Class: VSCinemas::MovieItem

Inherits:
Object
  • Object
show all
Defined in:
lib/vscinemas/movie_item.rb

Overview

The Movie

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ MovieItem

Returns a new instance of MovieItem.

Parameters:

  • element (Nokogiri::XML::Element)

Since:

  • 0.1.0



14
15
16
17
18
# File 'lib/vscinemas/movie_item.rb', line 14

def initialize(element)
  @element = element
  @info_element = element.css('.infoArea')
  @tag_elements = element.css('.iconArea .theaterMark')
end

Instance Attribute Details

#elementObject (readonly)

Since:

  • 0.1.0



9
10
11
# File 'lib/vscinemas/movie_item.rb', line 9

def element
  @element
end

Instance Method Details

#dateDate

Date

Returns:

  • (Date)

Since:

  • 0.1.0



43
44
45
46
47
# File 'lib/vscinemas/movie_item.rb', line 43

def date
  @date ||= Date.parse(@info_element.css('time').to_s)
rescue ArgumentError
  nil
end

#detail_urlURI

Detail URL

Returns:

  • (URI)

Since:

  • 0.1.0



54
55
56
# File 'lib/vscinemas/movie_item.rb', line 54

def detail_url
  @detail_url ||= URI.join(ENDPOINT, PATH, @element.css('h2 a').attr('href').text)
end

#figureURI

Figure URI

Returns:

  • (URI)

Since:

  • 0.1.0



63
64
65
# File 'lib/vscinemas/movie_item.rb', line 63

def figure
  @figure ||= URI.join(ENDPOINT, PATH, @element.css('figure img').attr('src').text)
end

#inspectString

Inspect

Returns:

  • (String)

Since:

  • 0.1.0



85
86
87
# File 'lib/vscinemas/movie_item.rb', line 85

def inspect
  "#<#{self.class.name} title=#{title} date=#{date}>"
end

#titleString

Title

Returns:

  • (String)

Since:

  • 0.1.0



25
26
27
# File 'lib/vscinemas/movie_item.rb', line 25

def title
  @title ||= @info_element.css('h2').text&.strip
end

#title_enString

English Title

Returns:

  • (String)

Since:

  • 0.1.0



34
35
36
# File 'lib/vscinemas/movie_item.rb', line 34

def title_en
  @title_en ||= @info_element.css('h3').text&.strip
end

#to_hHash

Returns:

  • (Hash)

Since:

  • 0.1.0



70
71
72
73
74
75
76
77
78
# File 'lib/vscinemas/movie_item.rb', line 70

def to_h
  {
    title: title,
    title_en: title_en,
    date: date,
    detail_url: detail_url,
    figure: figure
  }
end