Class: Popularity::RedditComment
- Inherits:
-
Crawler
- Object
- Crawler
- Popularity::RedditComment
show all
- Defined in:
- lib/popularity/networks/reddit_comment.rb
Instance Attribute Summary
Attributes inherited from Crawler
#url
Instance Method Summary
collapse
Methods inherited from Crawler
#async_done?, #fetch, #fetch_async, #has_response?, #host, #initialize, #response, #response_json, #to_json
Instance Method Details
#as_json(options = {}) ⇒ Object
7
8
9
|
# File 'lib/popularity/networks/reddit_comment.rb', line 7
def as_json(options = {})
{"score" => score}
end
|
#name ⇒ Object
22
23
24
|
# File 'lib/popularity/networks/reddit_comment.rb', line 22
def name
"reddit"
end
|
#score ⇒ Object
3
4
5
|
# File 'lib/popularity/networks/reddit_comment.rb', line 3
def score
response_json[1]["data"]["children"][0]["data"]["score"]
end
|
#total ⇒ Object
11
12
13
|
# File 'lib/popularity/networks/reddit_comment.rb', line 11
def total
score
end
|
#valid? ⇒ Boolean
15
16
17
18
19
20
|
# File 'lib/popularity/networks/reddit_comment.rb', line 15
def valid?
return false unless host == 'reddit.com'
path = URI.parse(@url).path
path.split('/').delete_if { |a| a.empty? }.size == 6
end
|