Class: Ikioi::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/ikioi/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword, board_name) ⇒ Checker

Returns a new instance of Checker.



9
10
11
12
# File 'lib/ikioi/checker.rb', line 9

def initialize(keyword, board_name)
  @keyword = keyword
  @board_name = board_name
end

Instance Attribute Details

#board_nameObject (readonly)

Returns the value of attribute board_name.



7
8
9
# File 'lib/ikioi/checker.rb', line 7

def board_name
  @board_name
end

#keywordObject (readonly)

Returns the value of attribute keyword.



7
8
9
# File 'lib/ikioi/checker.rb', line 7

def keyword
  @keyword
end

Instance Method Details

#fetchObject



14
15
16
17
18
19
20
# File 'lib/ikioi/checker.rb', line 14

def fetch
  @last_ikioi = parse(fetch_jsonp).find {|item| item['title'].include?(keyword) }['ikioi']
rescue OpenURI::HTTPError => e
  @last_ikioi || 0
rescue
  0
end

#fetch_jsonpObject



26
27
28
# File 'lib/ikioi/checker.rb', line 26

def fetch_jsonp
  open("http://2ch-ranking.net/ranking.json?board=#{board_name}").read
end

#parse(jsonp) ⇒ Object



22
23
24
# File 'lib/ikioi/checker.rb', line 22

def parse(jsonp)
  JSON.parse(jsonp.sub('callback(', '').sub(/\);$/, ''))
end