class BFIPlayerSearch::Search
Public Instance Methods
search(query)
click to toggle source
# File lib/bfi_player_search/search.rb, line 7 def search(query) r = response(query) films = film_fragments(r.body).map do |f| rp = ResultParser.new(f) { :title => rp.title, :url => rp.url, :image_url => rp.image_url, :year => rp.year, :certificate => rp.certificate, :free => rp.free?, :running_time_in_minutes => rp.running_time_in_minutes, :director => rp.director } end if films.empty? & !no_results_page?(r.body) raise BFIPlayerSearch::SearchResultsPageNotRecognised else films end end
Private Instance Methods
film_fragments(page)
click to toggle source
# File lib/bfi_player_search/search.rb, line 39 def film_fragments(page) Nokogiri::HTML(page).css('#search-results article.film') end
no_results_page?(page)
click to toggle source
# File lib/bfi_player_search/search.rb, line 31 def no_results_page?(page) page.include?('returned no results') end
response(query)
click to toggle source
# File lib/bfi_player_search/search.rb, line 35 def response(query) HTTPClient.new.get('http://player.bfi.org.uk/search/', { 'q' => query }) end