Class: Popularity::RedditPost

Inherits:
Crawler
  • Object
show all
Defined in:
lib/popularity/networks/reddit_post.rb

Direct Known Subclasses

RedditResult

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

Constructor Details

This class inherits a constructor from Popularity::Crawler

Instance Method Details

#commentsObject



13
14
15
16
17
18
19
# File 'lib/popularity/networks/reddit_post.rb', line 13

def comments
  begin
    response_json[0]["data"]["children"][0]["data"]["num_comments"]
  rescue
    0
  end
end

#nameObject



28
29
30
# File 'lib/popularity/networks/reddit_post.rb', line 28

def name
  "reddit"
end

#scoreObject



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

Returns:

  • (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