Class: TalkTalkTV::FilmPage
- Inherits:
-
Object
- Object
- TalkTalkTV::FilmPage
- Defined in:
- lib/talktalk_tv/film_page.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #buy_price ⇒ Object
- #certificate ⇒ Object
- #film ⇒ Object
- #image_url ⇒ Object
-
#initialize(body:, url: nil) ⇒ FilmPage
constructor
A new instance of FilmPage.
- #release_year ⇒ Object
- #rental_price ⇒ Object
- #running_time_in_minutes ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(body:, url: nil) ⇒ FilmPage
Returns a new instance of FilmPage.
7 8 9 10 |
# File 'lib/talktalk_tv/film_page.rb', line 7 def initialize(body:, url: nil) @body = body @url = url end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/talktalk_tv/film_page.rb', line 12 def body @body end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/talktalk_tv/film_page.rb', line 12 def url @url end |
Class Method Details
Instance Method Details
#buy_price ⇒ Object
59 60 61 |
# File 'lib/talktalk_tv/film_page.rb', line 59 def buy_price select_price(body, '.c-retailButton--purchase .c-retailButton__price > text()') end |
#certificate ⇒ Object
45 46 47 48 |
# File 'lib/talktalk_tv/film_page.rb', line 45 def certificate match = body.css('.g-assetInfo li').map { |n| %r{CERT (.*)}.match(n.content) }.compact.first match && match[1] end |
#film ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/talktalk_tv/film_page.rb', line 19 def film Film.new( title: title, url: url, image_url: image_url, release_year: release_year, certificate: certificate, running_time_in_minutes: running_time_in_minutes, rental_price: rental_price, buy_price: buy_price ) end |
#image_url ⇒ Object
36 37 38 |
# File 'lib/talktalk_tv/film_page.rb', line 36 def image_url body.css('.c-packShot noscript img').first.attributes['src'].value end |
#release_year ⇒ Object
40 41 42 43 |
# File 'lib/talktalk_tv/film_page.rb', line 40 def release_year match = body.css('.g-assetInfo li').map { |n| %r{(\d{4})}.match(n.content) }.compact.first match && match[1].to_i end |
#rental_price ⇒ Object
55 56 57 |
# File 'lib/talktalk_tv/film_page.rb', line 55 def rental_price select_price(body, '.c-retailButton--rental .c-retailButton__price > text()') end |
#running_time_in_minutes ⇒ Object
50 51 52 53 |
# File 'lib/talktalk_tv/film_page.rb', line 50 def running_time_in_minutes match = body.css('.g-assetInfo li').map { |n| %r{(\d+) HRS (\d+) MINS}.match(n.content) }.compact.first match && (match[1].to_i * 60 + match[2].to_i) end |
#title ⇒ Object
32 33 34 |
# File 'lib/talktalk_tv/film_page.rb', line 32 def title body.css('.g-assetTitle').first.content.strip end |