Class: CineworldUk::Screening

Inherits:
Object
  • Object
show all
Defined in:
lib/cineworld_uk/screening.rb

Overview

The object representing a single screening on the Cineworld UK website

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Screening

Returns a new instance of Screening.

Parameters:

  • options (Hash)

    options hash

Options Hash (options):

  • :booking_url (String) — default: nil

    booking url for the screening

  • :cinema_name (String)

    name of the cinema

  • :cinema_id (String)

    website id of the cinema

  • :dimension (String) — default: '2d'

    dimension of the screening

  • :film_name (String)

    name of the film

  • :time (Time)

    utc time of the screening

  • :variant (Array<String>) — default: []

    type of screening



21
22
23
24
25
26
27
28
29
# File 'lib/cineworld_uk/screening.rb', line 21

def initialize(options)
  @booking_url = options.fetch(:booking_url, nil)
  @cinema_name = options.fetch(:cinema_name)
  @cinema_id   = options.fetch(:cinema_id)
  @dimension   = options.fetch(:dimension, '2d')
  @film_name   = options.fetch(:film_name)
  @time        = options.fetch(:time)
  @variant     = options.fetch(:variant, [])
end

Instance Attribute Details

#booking_urlString (readonly)

Returns the booking URL on the cinema website.

Returns:

  • (String)

    the booking URL on the cinema website



5
6
7
# File 'lib/cineworld_uk/screening.rb', line 5

def booking_url
  @booking_url
end

#cinema_nameString (readonly)

Returns the cinema name.

Returns:

  • (String)

    the cinema name



9
10
11
# File 'lib/cineworld_uk/screening.rb', line 9

def cinema_name
  @cinema_name
end

#dimensionString (readonly)

Returns 2d or 3d.

Returns:

  • (String)

    2d or 3d



7
8
9
# File 'lib/cineworld_uk/screening.rb', line 7

def dimension
  @dimension
end

#film_nameString (readonly)

Returns the film name.

Returns:

  • (String)

    the film name



11
12
13
# File 'lib/cineworld_uk/screening.rb', line 11

def film_name
  @film_name
end

Class Method Details

.at(cinema_id) ⇒ Array<CineworldUk::Screening>

All currently listed films showing at a cinema

Parameters:

  • cinema_id (Integer)

    id of the cinema on the website

Returns:



34
35
36
37
38
# File 'lib/cineworld_uk/screening.rb', line 34

def self.at(cinema_id)
  whatson_parser(cinema_id).films_with_screenings.map do |html|
    create_for_single_film(html, cinema_id)
  end.flatten
end

Instance Method Details

#showing_atTime

The UTC time of the screening

Returns:

  • (Time)


48
49
50
51
52
53
54
55
56
# File 'lib/cineworld_uk/screening.rb', line 48

def showing_at
  @when ||= begin
    if @time.utc?
      @time
    else
      TZInfo::Timezone.get('Europe/London').local_to_utc(@time)
    end
  end
end

#showing_onDate

The date of the screening

Returns:

  • (Date)


42
43
44
# File 'lib/cineworld_uk/screening.rb', line 42

def showing_on
  showing_at.to_date
end

#variantArray[String]

The kinds of screening

Returns:

  • (Array[String])


60
61
62
# File 'lib/cineworld_uk/screening.rb', line 60

def variant
  @variant.map(&:downcase).sort
end