Class: TildeScraper::Comment
Constant Summary
collapse
- @@all =
[]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
create, create_from_array
#add_attributes
Constructor Details
#initialize(attributes) ⇒ Comment
Returns a new instance of Comment.
9
10
11
|
# File 'lib/tilde_scraper/comment.rb', line 9
def initialize(attributes)
add_attributes(attributes.reject { |key, val| key == :children })
end
|
Instance Attribute Details
#age ⇒ Object
Returns the value of attribute age.
5
6
7
|
# File 'lib/tilde_scraper/comment.rb', line 5
def age
@age
end
|
#author ⇒ Object
Returns the value of attribute author.
5
6
7
|
# File 'lib/tilde_scraper/comment.rb', line 5
def author
@author
end
|
#children ⇒ Object
Returns the value of attribute children.
5
6
7
|
# File 'lib/tilde_scraper/comment.rb', line 5
def children
@children
end
|
#level ⇒ Object
Returns the value of attribute level.
5
6
7
|
# File 'lib/tilde_scraper/comment.rb', line 5
def level
@level
end
|
#text ⇒ Object
Returns the value of attribute text.
5
6
7
|
# File 'lib/tilde_scraper/comment.rb', line 5
def text
@text
end
|
#url ⇒ Object
Returns the value of attribute url.
5
6
7
|
# File 'lib/tilde_scraper/comment.rb', line 5
def url
@url
end
|
#votes ⇒ Object
Returns the value of attribute votes.
5
6
7
|
# File 'lib/tilde_scraper/comment.rb', line 5
def votes
@votes
end
|
Class Method Details
.all ⇒ Object
60
61
62
|
# File 'lib/tilde_scraper/comment.rb', line 60
def self.all
@@all
end
|
.all_top ⇒ Object
56
57
58
|
# File 'lib/tilde_scraper/comment.rb', line 56
def self.all_top
@@all.select { || .level == 0 }
end
|
.create_from_array(array) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/tilde_scraper/comment.rb', line 13
def self.create_from_array(array)
array.map do ||
= create(.reject { |key, val| key == :children })
.children = self.create_from_array([:children])
end
end
|
.display(array, indent = 0) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/tilde_scraper/comment.rb', line 49
def self.display(array, indent = 0)
array.each do ||
.display(indent)
display(.children, indent + 1)
end
end
|
.display_page(url) ⇒ Object
45
46
47
|
# File 'lib/tilde_scraper/comment.rb', line 45
def self.display_page(url)
display(find_top_by_url(url))
end
|
.find_by_url(url) ⇒ Object
21
22
23
|
# File 'lib/tilde_scraper/comment.rb', line 21
def self.find_by_url(url)
all.select { || .url == url }
end
|
.find_top_by_url(url) ⇒ Object
25
26
27
|
# File 'lib/tilde_scraper/comment.rb', line 25
def self.find_top_by_url(url)
all.select { || .url == url && .level == 0}
end
|
Instance Method Details
#display(indent = 0) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/tilde_scraper/comment.rb', line 29
def display(indent = 0)
indent(indent)
puts self.author
display_text(indent)
indent(indent)
puts "Votes: " + self.votes if self.votes
puts "-" * 10
end
|
#display_text(indent = 0) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/tilde_scraper/comment.rb', line 38
def display_text(indent = 0)
self.text.split("\n").each do |line|
indent(indent)
puts line
end
end
|