Class: VSCinemas::MovieList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/vscinemas/movie_list.rb

Overview

The Move List

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: 'film', page: 1, continue: false) ⇒ MovieList

Returns a new instance of MovieList.

Parameters:

  • type (String) (defaults to: 'film')

    the list type film or coming

  • page (Number) (defaults to: 1)
  • continue (Boolean) (defaults to: false)

Since:

  • 0.1.0



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

#continueObject (readonly)

Since:

  • 0.1.0



11
12
13
# File 'lib/vscinemas/movie_list.rb', line 11

def continue
  @continue
end

#pageObject (readonly)

Since:

  • 0.1.0



11
12
13
# File 'lib/vscinemas/movie_list.rb', line 11

def page
  @page
end

#typeObject (readonly)

Since:

  • 0.1.0



11
12
13
# File 'lib/vscinemas/movie_list.rb', line 11

def type
  @type
end

Instance Method Details

#bodyString

Downloaded Web Page

Returns:

  • (String)

Since:

  • 0.1.0



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

Returns:

  • (Boolean)

Since:

  • 0.1.0



91
92
93
# File 'lib/vscinemas/movie_list.rb', line 91

def continue?
  continue == true
end

#docNokogiri::HTML::Document

Parsed Document

Returns:

  • (Nokogiri::HTML::Document)

Since:

  • 0.1.0



37
38
39
# File 'lib/vscinemas/movie_list.rb', line 37

def doc
  @doc ||= Nokogiri::HTML(body)
end

#each(&block) ⇒ Object

Since:

  • 0.1.0



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

#nextVSCinemas::MovieList

Next List

Returns:

Since:

  • 0.1.0



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

Returns:

  • (Boolean)

Since:

  • 0.1.0



73
74
75
# File 'lib/vscinemas/movie_list.rb', line 73

def next?
  next_page && next_page != 0
end

#next_pageNumber

Next Page

Returns:

  • (Number)

Since:

  • 0.1.0



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

#uriURI

Target URI

Returns:

  • (URI)

Since:

  • 0.1.0



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