Class: BFIPlayerSearch::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/bfi_player_search/search.rb

Instance Method Summary collapse

Instance Method Details

#search(query) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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