class BFIPlayerSearch::ResultParser
Attributes
fragment[R]
Public Class Methods
new(fragment)
click to toggle source
# File lib/bfi_player_search/result_parser.rb, line 3 def initialize(fragment) @fragment = fragment end
Public Instance Methods
certificate()
click to toggle source
# 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
director()
click to toggle source
# 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?()
click to toggle source
# File lib/bfi_player_search/result_parser.rb, line 23 def free? fragment.css('.price').first.content.include?('free') end
image_url()
click to toggle source
# 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_minutes()
click to toggle source
# 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
title()
click to toggle source
# File lib/bfi_player_search/result_parser.rb, line 7 def title fragment.css('span.title').first.content.strip end
url()
click to toggle source
# 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
year()
click to toggle source
# 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
Private Instance Methods
convert_to_url(path_or_url)
click to toggle source
# File lib/bfi_player_search/result_parser.rb, line 50 def convert_to_url(path_or_url) u = URI.parse(URI.escape(path_or_url)) u.host ||= 'player.bfi.org.uk' u.scheme ||= 'http' u.to_s end