Class: Honeysearch::Search
- Inherits:
-
Object
- Object
- Honeysearch::Search
- Defined in:
- lib/honeysearch.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(term, page = 0) ⇒ Search
constructor
A new instance of Search.
- #more? ⇒ Boolean
- #res ⇒ Object
- #result ⇒ Object
- #total_number ⇒ Object
Constructor Details
#initialize(term, page = 0) ⇒ Search
Returns a new instance of Search.
15 16 17 18 |
# File 'lib/honeysearch.rb', line 15 def initialize(term, page=0) @term = term @page = page end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
13 14 15 |
# File 'lib/honeysearch.rb', line 13 def page @page end |
Instance Method Details
#body ⇒ Object
39 40 41 |
# File 'lib/honeysearch.rb', line 39 def body @body ||= res.body.force_encoding('UTF-8') end |
#more? ⇒ Boolean
47 48 49 |
# File 'lib/honeysearch.rb', line 47 def more? body.include?('次の30曲') end |
#res ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/honeysearch.rb', line 20 def res @res ||= begin uri = URI("#{SEARCH_URL}?p=#{@page}") Net::HTTP.post_form( uri, sel_rows1: 30, topsearch_box: @term, sel_rows2: 30, s_title: '', s_singer: '', s_intro: '', s_tieup: '', search_genre: 0, sel_search_genre: 0, method: 0 ) end end |
#result ⇒ Object
43 44 45 |
# File 'lib/honeysearch.rb', line 43 def result body end |
#total_number ⇒ Object
51 52 53 |
# File 'lib/honeysearch.rb', line 51 def total_number body.match(/検索結果\uff1a(?<number>[0-9]+)曲/)[:number].to_i end |