Class: VSCinemas::MovieList
- Inherits:
-
Object
- Object
- VSCinemas::MovieList
- Includes:
- Enumerable
- Defined in:
- lib/vscinemas/movie_list.rb
Overview
The Move List
Instance Attribute Summary collapse
- #continue ⇒ Object readonly
- #page ⇒ Object readonly
- #type ⇒ Object readonly
Instance Method Summary collapse
-
#body ⇒ String
Downloaded Web Page.
-
#continue? ⇒ Boolean
Continue to Next Page.
-
#doc ⇒ Nokogiri::HTML::Document
Parsed Document.
- #each(&block) ⇒ Object
-
#initialize(type: 'film', page: 1, continue: false) ⇒ MovieList
constructor
A new instance of MovieList.
-
#next ⇒ VSCinemas::MovieList
Next List.
-
#next? ⇒ Boolean
Has Next Page.
-
#next_page ⇒ Number
Next Page.
-
#uri ⇒ URI
Target URI.
Constructor Details
#initialize(type: 'film', page: 1, continue: false) ⇒ MovieList
Returns a new instance of MovieList.
18 19 20 21 22 |
# File 'lib/vscinemas/movie_list.rb', line 18 def initialize(type: 'film', page: 1, continue: false) @type = type @page = page @continue = continue end |
Instance Attribute Details
#continue ⇒ Object (readonly)
11 12 13 |
# File 'lib/vscinemas/movie_list.rb', line 11 def continue @continue end |
#page ⇒ Object (readonly)
11 12 13 |
# File 'lib/vscinemas/movie_list.rb', line 11 def page @page end |
#type ⇒ Object (readonly)
11 12 13 |
# File 'lib/vscinemas/movie_list.rb', line 11 def type @type end |
Instance Method Details
#body ⇒ String
Downloaded Web Page
55 56 57 |
# File 'lib/vscinemas/movie_list.rb', line 55 def body @body ||= Net::HTTP.get(uri).force_encoding('UTF-8') end |
#continue? ⇒ Boolean
Continue to Next Page
91 92 93 |
# File 'lib/vscinemas/movie_list.rb', line 91 def continue? continue == true end |
#doc ⇒ Nokogiri::HTML::Document
Parsed Document
37 38 39 |
# File 'lib/vscinemas/movie_list.rb', line 37 def doc @doc ||= Nokogiri::HTML(body) end |
#each(&block) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/vscinemas/movie_list.rb', line 25 def each(&block) return enum_for(:each) unless defined?(yield) doc.css('.movieList li').map { |el| MovieItem.new(el) }.each(&block) self.next.each(&block) if next? && continue? end |
#next ⇒ VSCinemas::MovieList
Next List
82 83 84 |
# File 'lib/vscinemas/movie_list.rb', line 82 def next MovieList.new(page: next_page, continue: continue) if next? end |
#next? ⇒ Boolean
Has Next Page
73 74 75 |
# File 'lib/vscinemas/movie_list.rb', line 73 def next? next_page && next_page != 0 end |
#next_page ⇒ Number
Next Page
64 65 66 |
# File 'lib/vscinemas/movie_list.rb', line 64 def next_page @next_page ||= doc.css('.pagebar li.press+li').text&.to_i end |
#uri ⇒ URI
Target URI
46 47 48 |
# File 'lib/vscinemas/movie_list.rb', line 46 def uri @uri ||= URI("#{ENDPOINT}/vsweb/film/#{@type == 'coming' ? 'coming' : 'index'}.aspx?p=#{page}") end |