Class: BFIPlayerSearch::ResultParser
- Inherits:
-
Object
- Object
- BFIPlayerSearch::ResultParser
- Defined in:
- lib/bfi_player_search/result_parser.rb
Instance Method Summary collapse
- #certificate ⇒ Object
- #director ⇒ Object
- #free? ⇒ Boolean
- #image_url ⇒ Object
-
#initialize(fragment) ⇒ ResultParser
constructor
A new instance of ResultParser.
- #running_time_in_minutes ⇒ Object
- #title ⇒ Object
- #url ⇒ Object
- #year ⇒ Object
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
#certificate ⇒ Object
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 |
#director ⇒ Object
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
23 24 25 |
# File 'lib/bfi_player_search/result_parser.rb', line 23 def free? fragment.css('.price').first.content.include?('free') end |
#image_url ⇒ Object
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_minutes ⇒ Object
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 |
#title ⇒ Object
7 8 9 |
# File 'lib/bfi_player_search/result_parser.rb', line 7 def title fragment.css('span.title').first.content.strip end |
#url ⇒ Object
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 |
#year ⇒ Object
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 |