Class: Imdb::Search

Inherits:
MovieList
  • Object
show all
Defined in:
lib/extensions/imdb.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.query(query) ⇒ Object


6
7
8
# File 'lib/extensions/imdb.rb', line 6

def self.query(query)
  open("http://anonymouse.org/cgi-bin/anon-www.cgi/http://akas.imdb.com/find?q=#{CGI::escape(query)}&s=tt")
end

Instance Method Details

#parse_movieObject


10
11
12
13
14
# File 'lib/extensions/imdb.rb', line 10

def parse_movie
  id                 = document.at("head/link[@rel='canonical']")['href'][/\d+/]
  title              = document.at("h1").innerHTML.imdb_strip_tags.gsub("\n", " ").strip.imdb_unescape_html
  [Imdb::Movie.new(id, title)]
end

#parse_moviesObject


16
17
18
19
20
21
# File 'lib/extensions/imdb.rb', line 16

def parse_movies
  document.search("a[@href^='http://anonymouse.org/cgi-bin/anon-www.cgi/http://akas.imdb.com/title/tt']").each do |pm|
    pm["href"] = pm["href"].gsub("http://anonymouse.org/cgi-bin/anon-www.cgi/http://akas.imdb.com", "")
  end
  super
end