Class: Karaoke::Search
- Inherits:
-
Object
- Object
- Karaoke::Search
- Defined in:
- lib/karaoke/search.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(query) ⇒ Search
constructor
A new instance of Search.
- #results ⇒ Object
- #search_query ⇒ Object
Constructor Details
#initialize(query) ⇒ Search
Returns a new instance of Search.
9 10 11 |
# File 'lib/karaoke/search.rb', line 9 def initialize(query) @query = query end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
7 8 9 |
# File 'lib/karaoke/search.rb', line 7 def query @query end |
Instance Method Details
#results ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/karaoke/search.rb', line 17 def results @results ||= begin song_results = [] search_results = Google::Search::Web.new(query: search_query) search_results.each do |result| klass = Song.song_type_for(result.uri) next unless klass song_results << klass.new(result.uri) end song_results end end |
#search_query ⇒ Object
13 14 15 |
# File 'lib/karaoke/search.rb', line 13 def search_query "#{self.query} lyrics" end |