Class: BFIPlayerSearch::ResultParser

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

Instance Method Summary collapse

Constructor Details

#initialize(fragment) ⇒ ResultParser

Returns a new instance of ResultParser.



3
4
5
# File 'lib/bfi_player_search/result_parser.rb', line 3

def initialize(fragment)
  @fragment = fragment
end

Instance Method Details

#certificateObject



17
18
19
20
21
# File 'lib/bfi_player_search/result_parser.rb', line 17

def certificate
  if cert_tag = fragment.css('img.certificate-image').first
    cert_tag.attributes['alt'].to_s.strip
  end
end

#directorObject



42
43
44
45
# File 'lib/bfi_player_search/result_parser.rb', line 42

def director
  match = fragment.css('.metrics span').map { |n| %r{Director\. (.*)\Z}.match(n.content) }.compact.first
  match && match[1].strip
end

#free?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/bfi_player_search/result_parser.rb', line 23

def free?
  fragment.css('.price').first.content.include?('free')
end

#image_urlObject



32
33
34
35
# File 'lib/bfi_player_search/result_parser.rb', line 32

def image_url
  path = fragment.css('figure img').first.attributes['src'].to_s.strip
  convert_to_url(path)
end

#running_time_in_minutesObject



37
38
39
40
# File 'lib/bfi_player_search/result_parser.rb', line 37

def running_time_in_minutes
  match = fragment.css('.metrics span').map { |n| %r{(\d+) mins}.match(n.content) }.compact.first
  match && match[1].to_i
end

#titleObject



7
8
9
# File 'lib/bfi_player_search/result_parser.rb', line 7

def title
  fragment.css('span.title').first.content.strip
end

#urlObject



27
28
29
30
# File 'lib/bfi_player_search/result_parser.rb', line 27

def url
  path = fragment.css('a').first.attributes['href'].to_s.strip
  convert_to_url(path)
end

#yearObject



11
12
13
14
15
# File 'lib/bfi_player_search/result_parser.rb', line 11

def year
  if year_tag = fragment.css('span.film-year').first
    year_tag.content.strip
  end
end