class ImdbSearch attr_accessor :query def initialize(query) self.query = query end def movies @movies ||= parse_movies_from_document end private def document @document ||= Hpricot(open("http://www.imdb.com/find?q=#{CGI::escape(query)};s=tt").read) end def parse_movies_from_document exact_match? ? parse_exact_match_search_results : parse_multi_movie_search_results end def parse_exact_match_search_results id = document.at("a[@name='poster']")['href'][/\d+$/] title = document.at("h1").innerHTML.split('