Class: YoutubeTools::Searcher
- Inherits:
-
Object
- Object
- YoutubeTools::Searcher
- Defined in:
- lib/youtube_tools/searcher.rb
Constant Summary collapse
- YOUTUBE_LINK =
"http://gdata.youtube.com/feeds/api/videos"
Instance Attribute Summary collapse
-
#href ⇒ Object
Returns the value of attribute href.
-
#links ⇒ Object
Returns the value of attribute links.
-
#search_term ⇒ Object
Returns the value of attribute search_term.
-
#term ⇒ Object
Returns the value of attribute term.
Instance Method Summary collapse
-
#initialize(term) ⇒ Searcher
constructor
A new instance of Searcher.
- #process ⇒ Object
Constructor Details
#initialize(term) ⇒ Searcher
Returns a new instance of Searcher.
6 7 8 9 10 11 12 13 |
# File 'lib/youtube_tools/searcher.rb', line 6 def initialize(term) @term = term @search_term = url_term term @href = "#{YOUTUBE_LINK}?vq=#{@search_term}" @content = open(@href) @links = [] process end |
Instance Attribute Details
#href ⇒ Object
Returns the value of attribute href.
3 4 5 |
# File 'lib/youtube_tools/searcher.rb', line 3 def href @href end |
#links ⇒ Object
Returns the value of attribute links.
3 4 5 |
# File 'lib/youtube_tools/searcher.rb', line 3 def links @links end |
#search_term ⇒ Object
Returns the value of attribute search_term.
3 4 5 |
# File 'lib/youtube_tools/searcher.rb', line 3 def search_term @search_term end |
#term ⇒ Object
Returns the value of attribute term.
3 4 5 |
# File 'lib/youtube_tools/searcher.rb', line 3 def term @term end |
Instance Method Details
#process ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/youtube_tools/searcher.rb', line 15 def process doc = Hpricot(@content) @links = doc.search("//entry").collect do |entry| { :title => entry.get_elements_by_tag_name("title").text, :link => entry.get_elements_by_tag_name("link").first.get_attribute("href") } end end |