Class: Letteropend::Film
- Inherits:
-
Object
- Object
- Letteropend::Film
- Defined in:
- lib/letteropend/film.rb
Instance Attribute Summary collapse
-
#overview ⇒ Object
readonly
Returns the value of attribute overview.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
-
#tagline ⇒ Object
readonly
Returns the value of attribute tagline.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #==(film) ⇒ Object
-
#initialize(title, url, callbacks = {}) ⇒ Film
constructor
A new instance of Film.
- #pull_data ⇒ Object
Constructor Details
#initialize(title, url, callbacks = {}) ⇒ Film
Returns a new instance of Film.
7 8 9 10 11 12 |
# File 'lib/letteropend/film.rb', line 7 def initialize(title, url, callbacks={}) @title = title @url = url @pulled = false @callbacks = callbacks end |
Instance Attribute Details
#overview ⇒ Object (readonly)
Returns the value of attribute overview.
6 7 8 |
# File 'lib/letteropend/film.rb', line 6 def overview @overview end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
6 7 8 |
# File 'lib/letteropend/film.rb', line 6 def runtime @runtime end |
#tagline ⇒ Object (readonly)
Returns the value of attribute tagline.
6 7 8 |
# File 'lib/letteropend/film.rb', line 6 def tagline @tagline end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/letteropend/film.rb', line 6 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/letteropend/film.rb', line 6 def url @url end |
Instance Method Details
#==(film) ⇒ Object
63 64 65 |
# File 'lib/letteropend/film.rb', line 63 def ==(film) @title == film.title and @url == film.url end |
#pull_data ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/letteropend/film.rb', line 35 def pull_data if @callbacks[:pulling_film] @callbacks[:pulling_film].call(self) end # pull the page from the url page = Nokogiri::HTML(open("http://www.letterboxd.com#{@url}")) @pulled = true # get the runtime for the film runtime_cap = page.css(".text-link").text.match(/(\d+) mins/) if runtime_cap @runtime = runtime_cap.captures[0].to_i else @runtime = 0 end # get the tagline for the film @tagline = page.css(".tagline").text # get the overview for the film @overview = page.css("div.truncate").text.strip if @callbacks[:pulled_film] @callbacks[:pulled_film].call(self) end end |