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
#as_json, #async_done?, #fetch, #fetch_async, #has_response?, #host, #initialize, property_names, #response, #response_json, stats, #total
Instance Method Details
13
14
15
16
17
18
19
|
# File 'lib/popularity/networks/reddit_post.rb', line 13
def
begin
response_json[0]["data"]["children"][0]["data"]["num_comments"]
rescue
0
end
end
|
#name ⇒ Object
28
29
30
|
# File 'lib/popularity/networks/reddit_post.rb', line 28
def name
"reddit"
end
|
#score ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/popularity/networks/reddit_post.rb', line 5
def score
begin
response_json[0]["data"]["children"][0]["data"]["score"]
rescue
0
end
end
|
#valid? ⇒ Boolean
21
22
23
24
25
26
|
# File 'lib/popularity/networks/reddit_post.rb', line 21
def valid?
return false unless host == 'reddit.com'
path = URI.parse(@url).path
path.split('/').delete_if { |a| a.empty? }.size < 6
end
|