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

#async_done?, #fetch, #fetch_async, #has_response?, #host, #initialize, #response, #response_json, #to_json

Constructor Details

This class inherits a constructor from Popularity::Crawler

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

#nameObject



22
23
24
# File 'lib/popularity/networks/reddit_comment.rb', line 22

def name
  "reddit"
end

#scoreObject



3
4
5
# File 'lib/popularity/networks/reddit_comment.rb', line 3

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

#totalObject



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

def total
  score
end

#valid?Boolean

Returns:

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