Class: YoutubeTools::Searcher

Inherits:
Object
  • Object
show all
Defined in:
lib/youtube_tools/searcher.rb

Constant Summary collapse

"http://gdata.youtube.com/feeds/api/videos"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hrefObject

Returns the value of attribute href.



3
4
5
# File 'lib/youtube_tools/searcher.rb', line 3

def href
  @href
end

Returns the value of attribute links.



3
4
5
# File 'lib/youtube_tools/searcher.rb', line 3

def links
  @links
end

#search_termObject

Returns the value of attribute search_term.



3
4
5
# File 'lib/youtube_tools/searcher.rb', line 3

def search_term
  @search_term
end

#termObject

Returns the value of attribute term.



3
4
5
# File 'lib/youtube_tools/searcher.rb', line 3

def term
  @term
end

Instance Method Details

#processObject



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