Class: Ikioi::Checker
- Inherits:
-
Object
- Object
- Ikioi::Checker
- Defined in:
- lib/ikioi/checker.rb
Instance Attribute Summary collapse
-
#board_name ⇒ Object
readonly
Returns the value of attribute board_name.
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
Instance Method Summary collapse
- #fetch ⇒ Object
- #fetch_jsonp ⇒ Object
-
#initialize(keyword, board_name) ⇒ Checker
constructor
A new instance of Checker.
- #parse(jsonp) ⇒ Object
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_name ⇒ Object (readonly)
Returns the value of attribute board_name.
7 8 9 |
# File 'lib/ikioi/checker.rb', line 7 def board_name @board_name end |
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
7 8 9 |
# File 'lib/ikioi/checker.rb', line 7 def keyword @keyword end |
Instance Method Details
#fetch ⇒ Object
14 15 16 17 18 |
# 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 end |
#fetch_jsonp ⇒ Object
24 25 26 |
# File 'lib/ikioi/checker.rb', line 24 def fetch_jsonp open("http://2ch-ranking.net/ranking.json?board=#{board_name}").read end |
#parse(jsonp) ⇒ Object
20 21 22 |
# File 'lib/ikioi/checker.rb', line 20 def parse(jsonp) ActiveSupport::JSON.decode(jsonp.sub('callback(', '').sub(/\);$/, '')) end |