Class: Letteropend::List
- Inherits:
-
Object
- Object
- Letteropend::List
- Defined in:
- lib/letteropend/list.rb
Instance Attribute Summary collapse
-
#films ⇒ Object
readonly
Returns the value of attribute films.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #get_total_time ⇒ Object
-
#initialize(username, list = "films", callbacks = {}) ⇒ List
constructor
A new instance of List.
Constructor Details
#initialize(username, list = "films", callbacks = {}) ⇒ List
Returns a new instance of List.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/letteropend/list.rb', line 9 def initialize(username, list="films", callbacks={}) @username = username @list = list @films = [] @pages = ["/#{username}/#{list}/page/1/"] begin # get page using Nokogiri if callbacks[:new_page] callbacks[:new_page].call(self) end page = Nokogiri::HTML(open("http://www.letterboxd.com#{@pages.last}")) # append visible films to @films page.css(".poster").each do |film| title = film.css(".frame-title").text url = film.css("a")[0].attr("href") @films.push( Film.new(title, url, callbacks) ) if callbacks[:new_film] callbacks[:new_film].call(self) end end # see if there is a next page next_page = page.css('a.paginate-next')[0] if ( next_page ) @pages.push( next_page.attr("href") ) end end while ( next_page ) end |
Instance Attribute Details
#films ⇒ Object (readonly)
Returns the value of attribute films.
7 8 9 |
# File 'lib/letteropend/list.rb', line 7 def films @films end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
7 8 9 |
# File 'lib/letteropend/list.rb', line 7 def list @list end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
7 8 9 |
# File 'lib/letteropend/list.rb', line 7 def pages @pages end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
7 8 9 |
# File 'lib/letteropend/list.rb', line 7 def username @username end |
Instance Method Details
#get_total_time ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/letteropend/list.rb', line 40 def get_total_time total_runtime = 0 @films.each do |film| total_runtime += film.runtime end return total_runtime end |