Class: Letteropend::Film
- Inherits:
-
Object
- Object
- Letteropend::Film
- Defined in:
- lib/letteropend/film.rb
Instance Attribute Summary collapse
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
-
#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
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
6 7 8 |
# File 'lib/letteropend/film.rb', line 6 def runtime @runtime 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
43 44 45 |
# File 'lib/letteropend/film.rb', line 43 def ==(film) @title == film.title and @url == film.url end |
#pull_data ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/letteropend/film.rb', line 21 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 if @callbacks[:pulled_film] @callbacks[:pulled_film].call(self) end end |