Class: PicturehouseUk::Film
- Inherits:
-
Object
- Object
- PicturehouseUk::Film
- Includes:
- Comparable
- Defined in:
- lib/picturehouse_uk/film.rb
Overview
A film on the Picturehouse UK website
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the film.
-
#slug ⇒ String
readonly
The normalized slug derived from the film name.
Class Method Summary collapse
-
.at(cinema_id) ⇒ Array<PicturehouseUk::Film>
Films at a single cinema.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Allows sort on objects.
-
#eql?(other) ⇒ Boolean
Check an object is the same as another object.
-
#hash ⇒ Integer
Generates hash of slug in order to allow two records of the same type and id to work with something like:.
- #initialize(name) ⇒ PicturehouseUk::Film constructor
Constructor Details
#initialize(name) ⇒ PicturehouseUk::Film
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
#name ⇒ String (readonly)
Returns the name of the film.
7 8 9 |
# File 'lib/picturehouse_uk/film.rb', line 7 def name @name end |
#slug ⇒ String (readonly)
Returns 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
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
30 31 32 |
# File 'lib/picturehouse_uk/film.rb', line 30 def <=>(other) slug <=> other.slug end |
#eql?(other) ⇒ Boolean
Note:
Check an object is the same as another object.
39 40 41 |
# File 'lib/picturehouse_uk/film.rb', line 39 def eql?(other) self.class == other.class && self == other end |
#hash ⇒ Integer
Note:
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') ]
51 52 53 |
# File 'lib/picturehouse_uk/film.rb', line 51 def hash slug.hash end |