Class: Popularity::RedditPost
- Inherits:
-
Crawler
- Object
- Crawler
- Popularity::RedditPost
show all
- Defined in:
- lib/popularity/networks/reddit_post.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
19
20
21
22
23
24
|
# File 'lib/popularity/networks/reddit_post.rb', line 19
def as_json(options = {})
{
"comments" => ,
"score" => score
}
end
|
11
12
13
14
15
16
17
|
# File 'lib/popularity/networks/reddit_post.rb', line 11
def
begin
response_json[0]["data"]["children"][0]["data"]["num_comments"]
rescue
0
end
end
|
#name ⇒ Object
37
38
39
|
# File 'lib/popularity/networks/reddit_post.rb', line 37
def name
"reddit"
end
|
#score ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/popularity/networks/reddit_post.rb', line 3
def score
begin
response_json[0]["data"]["children"][0]["data"]["score"]
rescue
0
end
end
|
#total ⇒ Object
26
27
28
|
# File 'lib/popularity/networks/reddit_post.rb', line 26
def total
+ score
end
|
#valid? ⇒ Boolean
30
31
32
33
34
35
|
# File 'lib/popularity/networks/reddit_post.rb', line 30
def valid?
return false unless host == 'reddit.com'
path = URI.parse(@url).path
path.split('/').delete_if { |a| a.empty? }.size < 6
end
|