Class: YoutubeAudio::Search
- Inherits:
-
Object
- Object
- YoutubeAudio::Search
- Defined in:
- lib/youtube_audio/search.rb
Instance Attribute Summary collapse
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
Instance Method Summary collapse
-
#initialize(keywords) ⇒ Search
constructor
A new instance of Search.
- #results ⇒ Object
Constructor Details
#initialize(keywords) ⇒ Search
Returns a new instance of Search.
7 8 9 |
# File 'lib/youtube_audio/search.rb', line 7 def initialize(keywords) @keywords = keywords end |
Instance Attribute Details
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
5 6 7 |
# File 'lib/youtube_audio/search.rb', line 5 def keywords @keywords end |
Instance Method Details
#results ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/youtube_audio/search.rb', line 11 def results selector = '.section-list li ol.item-section li .yt-lockup-tile' search_url = 'https://www.youtube.com/results?search_query=' @results ||= agent.get(search_url + CGI.escape(keywords)) .search(selector) .map { |element| to_search_item(element) } end |