Class: HackerCurse::ForumArticle

Inherits:
Object
  • Object
show all
Defined in:
lib/hacker/curse/abstractsiteparser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ ForumArticle

Returns a new instance of ForumArticle.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hacker/curse/abstractsiteparser.rb', line 51

def initialize h
  @comments = nil
  @hash = h
  [:title, :article_url, :points, :comment_count, :comments_url, :age_text, :age,
   :submitter, :submitter_url, :domain, :domain_url, :byline].each do |sym|
    instance_variable_set("@#{sym.to_s}", h[sym]) if h.key? sym
  end
  if h.key? :comments
    c = h[:comments]
    @comments = Array.new
    c.each do |h|
      fc = ForumComment.new h
      @comments << fc
    end
  end
end

Instance Attribute Details

#ageObject

Returns the value of attribute age.



41
42
43
# File 'lib/hacker/curse/abstractsiteparser.rb', line 41

def age
  @age
end

#age_textObject

Returns the value of attribute age_text.



40
41
42
# File 'lib/hacker/curse/abstractsiteparser.rb', line 40

def age_text
  @age_text
end

#article_urlObject

Returns the value of attribute article_url.



36
37
38
# File 'lib/hacker/curse/abstractsiteparser.rb', line 36

def article_url
  @article_url
end

#bylineObject

byline is dump of text on top containing all the info on points, # of comments, nn hours aga



47
48
49
# File 'lib/hacker/curse/abstractsiteparser.rb', line 47

def 
  @byline
end

#comment_countObject

Returns the value of attribute comment_count.



38
39
40
# File 'lib/hacker/curse/abstractsiteparser.rb', line 38

def comment_count
  @comment_count
end

#commentsObject



68
69
70
# File 'lib/hacker/curse/abstractsiteparser.rb', line 68

def comments
  @comments || retrieve_comments(@comments_url)
end

#comments_urlObject

Returns the value of attribute comments_url.



39
40
41
# File 'lib/hacker/curse/abstractsiteparser.rb', line 39

def comments_url
  @comments_url
end

#domainObject

Returns the value of attribute domain.



44
45
46
# File 'lib/hacker/curse/abstractsiteparser.rb', line 44

def domain
  @domain
end

#domain_urlObject

Returns the value of attribute domain_url.



45
46
47
# File 'lib/hacker/curse/abstractsiteparser.rb', line 45

def domain_url
  @domain_url
end

#hashObject (readonly)

Returns the value of attribute hash.



50
51
52
# File 'lib/hacker/curse/abstractsiteparser.rb', line 50

def hash
  @hash
end

#parentObject

Returns the value of attribute parent.



48
49
50
# File 'lib/hacker/curse/abstractsiteparser.rb', line 48

def parent
  @parent
end

#pointsObject

Returns the value of attribute points.



37
38
39
# File 'lib/hacker/curse/abstractsiteparser.rb', line 37

def points
  @points
end

#submitterObject

Returns the value of attribute submitter.



42
43
44
# File 'lib/hacker/curse/abstractsiteparser.rb', line 42

def submitter
  @submitter
end

#submitter_urlObject

Returns the value of attribute submitter_url.



43
44
45
# File 'lib/hacker/curse/abstractsiteparser.rb', line 43

def submitter_url
  @submitter_url
end

#titleObject

Returns the value of attribute title.



35
36
37
# File 'lib/hacker/curse/abstractsiteparser.rb', line 35

def title
  @title
end

Instance Method Details

#[](sym) ⇒ Object



79
80
81
# File 'lib/hacker/curse/abstractsiteparser.rb', line 79

def [](sym)
  @hash[sym]
end

#eachObject Also known as: each_comment



71
72
73
# File 'lib/hacker/curse/abstractsiteparser.rb', line 71

def each
  comments.each do |e| yield(e) ; end
end

#keysObject



82
83
84
# File 'lib/hacker/curse/abstractsiteparser.rb', line 82

def keys
  @hash.keys
end

#retrieve_comments(url) ⇒ Object



74
75
76
77
# File 'lib/hacker/curse/abstractsiteparser.rb', line 74

def retrieve_comments url
  raise "Parent must be set in order to retrieve comments " unless @parent
  @parent._retrieve_comments url
end

#valuesObject



85
86
87
# File 'lib/hacker/curse/abstractsiteparser.rb', line 85

def values
  @hash.values
end