Class: PicturehouseUk::Film

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/picturehouse_uk/film.rb

Overview

A film on the Picturehouse UK website

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ PicturehouseUk::Film

Parameters:

  • name (String)

    the film name



13
14
15
16
# File 'lib/picturehouse_uk/film.rb', line 13

def initialize(name)
  @name = name
  @slug = name.downcase.gsub(/[^0-9a-z ]/, '').gsub(/\s+/, '-')
end

Instance Attribute Details

#nameString (readonly)

Returns the name of the film.

Returns:

  • (String)

    the name of the film



7
8
9
# File 'lib/picturehouse_uk/film.rb', line 7

def name
  @name
end

#slugString (readonly)

Returns the normalized slug derived from the film name.

Returns:

  • (String)

    the normalized slug derived from the film name



9
10
11
# File 'lib/picturehouse_uk/film.rb', line 9

def slug
  @slug
end

Class Method Details

.at(cinema_id) ⇒ Array<PicturehouseUk::Film>

Films at a single cinema

Parameters:

  • cinema_id (String)

    the id of the cinema

Returns:



21
22
23
24
25
# File 'lib/picturehouse_uk/film.rb', line 21

def self.at(cinema_id)
  cinema_page(cinema_id).film_html.map do |html|
    new(Internal::FilmWithScreeningsParser.new(html).film_name)
  end.uniq
end

Instance Method Details

#<=>(other) ⇒ Integer

Allows sort on objects

Parameters:

Returns:

  • (Integer)

    -1, 0 or 1



30
31
32
# File 'lib/picturehouse_uk/film.rb', line 30

def <=>(other)
  slug <=> other.slug
end

#eql?(other) ⇒ Boolean

Check an object is the same as another object.

Parameters:

Returns:

  • (Boolean)

    True if both objects are the same exact object, or if they are of the same type and share an equal slug



39
40
41
# File 'lib/picturehouse_uk/film.rb', line 39

def eql?(other)
  self.class == other.class && self == other
end

#hashInteger

Generates hash of slug in order to allow two records of the same type and id to work with something like:

[ Film.new('AB'), Film.new('EF') ] & [ Film.new('EF'), Film.new('GH') ]
#=> [ Film.new('EF') ]

Returns:

  • (Integer)

    hash of slug



51
52
53
# File 'lib/picturehouse_uk/film.rb', line 51

def hash
  slug.hash
end