Class: Popularity::RedditComment

Inherits:
Crawler
  • Object
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

#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

#nameObject



16
17
18
# File 'lib/popularity/networks/reddit_comment.rb', line 16

def name
  "reddit"
end

#scoreObject



5
6
7
# File 'lib/popularity/networks/reddit_comment.rb', line 5

def score
  response_json[1]["data"]["children"][0]["data"]["score"]
end

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/popularity/networks/reddit_comment.rb', line 9

def valid?
  return false unless host == 'reddit.com'

  path = URI.parse(@url).path
  path.split('/').delete_if { |a| a.empty? }.size == 6
end