Class: CineworldUk::Cinema

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

Overview

The object representing a cinema on the Cineworld UK website

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name) ⇒ CineworldUk::Cinema

Parameters:

  • id (Integer, String)

    cinema id

  • name (String)

    cinema name



18
19
20
21
22
23
24
# File 'lib/cineworld_uk/cinema.rb', line 18

def initialize(id, name)
  @brand = 'Cineworld'
  @id    = id.to_i
  @name  = name.gsub('London - ', '').gsub(' - ', ': ')
  @slug  = @name.downcase.gsub(/[^0-9a-z ]/, '').gsub(/\s+/, '-')
  @url   = "http://www.cineworld.co.uk/cinemas/#{@id}/information"
end

Instance Attribute Details

#brandString (readonly)

Returns the brand of the cinema.

Returns:

  • (String)

    the brand of the cinema



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

def brand
  @brand
end

#idInteger (readonly)

Returns the numeric id of the cinema on the Cineworld website.

Returns:

  • (Integer)

    the numeric id of the cinema on the Cineworld website



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

def id
  @id
end

#nameString (readonly)

Returns the name of the cinema.

Returns:

  • (String)

    the name of the cinema



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

def name
  @name
end

#slugString (readonly)

Returns the slug of the cinema.

Returns:

  • (String)

    the slug of the cinema



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

def slug
  @slug
end

#urlString (readonly)

Returns the url of the cinema on the Cineworld website.

Returns:

  • (String)

    the url of the cinema on the Cineworld website



13
14
15
# File 'lib/cineworld_uk/cinema.rb', line 13

def url
  @url
end

Class Method Details

.allArray<CineworldUk::Cinema>

Return basic cinema information for all cinemas

Examples:

CineworldUk::Cinema.all
#=> [<CineworldUk::Cinema>, <CineworldUk::Cinema>, ...]

Returns:



31
32
33
34
35
# File 'lib/cineworld_uk/cinema.rb', line 31

def self.all
  cinemas_doc.css('#cinemaId option[value]').map do |option|
    new option['value'], option.text
  end[1..-1]
end

.find(id) ⇒ CineworldUk::Cinema?

Find a single cinema

Examples:

CineworldUk::Cinema.find('3')
#=> <CineworldUk::Cinema brand="Cineworld"
                         name="Brighton"
                         slug="brighton"
                         id=3
                         url="...">

Parameters:

  • id (Integer, String)

    the cinema id as used on the website

Returns:



47
48
49
# File 'lib/cineworld_uk/cinema.rb', line 47

def self.find(id)
  all.select { |cinema| cinema.id == id.to_i }[0]
end

Instance Method Details

#adrHash Also known as: address

Note:

Uses the standard method naming as at microformats.org/wiki/adr

Address of the cinema

Examples:

cinema = CineworldUk::Cinema.find(3)
cinema.adr
#=> {
      street_address: '44-47 Gardner Street',
      extended_address: 'North Laine',
      locality: 'Brighton',
      postal_code: 'BN1 1UN',
      country_name: 'United Kingdom'
    }

Returns:

  • (Hash)

    of different address parts



64
65
66
67
68
69
70
71
72
73
# File 'lib/cineworld_uk/cinema.rb', line 64

def adr
  {
    street_address: street_address,
    extended_address: extended_address,
    locality: locality,
    region: region,
    postal_code: postal_code,
    country: 'United Kingdom'
  }
end

#extended_addressString?

Note:

Uses the standard method naming as at microformats.org/wiki/adr

The second address line of the cinema

Examples:

cinema = CineworldUk::Cinema.find(10)
cinema.extended_address
#=> 'Chelsea'

cinema = CineworldUk::Cinema.find(3)
cinema.extended_address
#=> nil

Returns:

  • (String, nil)


87
88
89
# File 'lib/cineworld_uk/cinema.rb', line 87

def extended_address
  remaining_address * ', ' unless remaining_address.empty?
end

#filmsArray<CineworldUk::Film>

Films with showings scheduled at this cinema

Examples:

cinema = CineworldUk::Cinema.find('71')
cinema.films
#=> [<CineworldUk::Film>, <CineworldUk::Film>, ...]

Returns:



97
98
99
# File 'lib/cineworld_uk/cinema.rb', line 97

def films
  Film.at(id)
end

#full_nameString

The name of the cinema including the brand

Examples:

cinema = CineworldUk::Cinema.find(88)
cinema.full_name
#=> 'Cineworld Glasgow: IMAX at GSC'

Returns:

  • (String)


107
108
109
# File 'lib/cineworld_uk/cinema.rb', line 107

def full_name
  "#{brand} #{name}"
end

#localityString

Note:

Uses the standard method naming as at microformats.org/wiki/adr

The locality (town) of the cinema

Examples:

cinema = CineworldUk::Cinema.find(3)
cinema.locality
#=> 'Brighton'

Returns:

  • (String)


118
119
120
121
122
123
124
# File 'lib/cineworld_uk/cinema.rb', line 118

def locality
  if adr_has_region? && !adr_in_london?
    adr_array[-2]
  else
    adr_array[-1]
  end
end

#postal_codeString

Note:

Uses the standard method naming as at microformats.org/wiki/adr

Post code of the cinema

Examples:

cinema = CineworldUk::Cinema.find(3)
cinema.postal_code
#=> 'BN2 5UF'

Returns:

  • (String)


133
134
135
# File 'lib/cineworld_uk/cinema.rb', line 133

def postal_code
  last_adr_line_array[-2..-1] * ' '
end

#regionString?

Note:

Uses the standard method naming as at microformats.org/wiki/adr

The region (county) of the cinema if provided

Examples:

cinema = CineworldUk::Cinema.find(3)
cinema.region
#=> 'East Sussex'

Returns:

  • (String, nil)


144
145
146
# File 'lib/cineworld_uk/cinema.rb', line 144

def region
  last_adr_line_non_postal_code if adr_has_region? && !adr_in_london?
end

#screeningsArray<CineworldUk::Screening>

All planned screenings

Examples:

cinema = CineworldUk::Cinema.find(3)
cinema.screenings
# => [<CineworldUk::Screening>, <CineworldUk::Screening>, ...]

Returns:



154
155
156
# File 'lib/cineworld_uk/cinema.rb', line 154

def screenings
  Screening.at(id)
end

#street_addressObject

Note:

Uses the standard method naming as at microformats.org/wiki/adr

The street adress of the cinema

Examples:

cinema = CineworldUk::Cinema.find(3)
cinema.street_address
#=> 'Brighton Marina'

Returns:

  • a String



165
166
167
# File 'lib/cineworld_uk/cinema.rb', line 165

def street_address
  adr_parts[0]
end