lib/picturehouse_uk/film.rb in picturehouse_uk-1.0.0 vs lib/picturehouse_uk/film.rb in picturehouse_uk-1.0.1

- old
+ new

@@ -1,52 +1,47 @@ module PicturehouseUk - # Public: The object representing a film on the Odeon UK website + # A film on the Picturehouse UK website class Film include Comparable - # Public: Returns the String name of the film + # @return [String] the name of the film attr_reader :name - # Public: Returns the String slug of the film + # @return [String] the normalized slug derived from the film name attr_reader :slug - # Public: Allows sort on objects + # @param [String] name the film name + # @return [PicturehouseUk::Film] + def initialize(name) + @name = name + @slug = name.downcase.gsub(/[^0-9a-z ]/,'').gsub(/\s+/, '-') + end + + # Allows sort on objects + # @param [PicturehouseUk::Film] other another film object + # @return [Integer] -1, 0 or 1 def <=> other self.slug <=> other.slug end - # Public: Check an object is the same as another object. - # - # True if both objects are the same exact object, or if they are of the same - # type and share an equal slug - # - # Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/ - # - # object - object to be compared - # - # Returns Boolean + # Check an object is the same as another object. + # @param [PicturehouseUk::Film] other another film + # @return [Boolean] True if both objects are the same exact object, or if + # they are of the same type and share an equal slug + # @note Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/ def eql? other self.class == other.class && self == other end - # Public: generates hash of slug in order to allow two records of the same - # type and id to work with something like: + # Generates hash of slug in order to allow two records of the same type and + # id to work with something like: # # [ Film.new('ABC'), Film.new('DEF') ] & [ Film.new('DEF'), Film.new('GHI') ] # #=> [ Film.new('DEF') ] # - # Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/ - # - # Returns an Integer hash of the slug + # @return [Integer] hash of slug + # @note Guided by http://woss.name/2011/01/20/equality-comparison-and-ordering-in-ruby/ def hash self.slug.hash - end - - # Public: Initialize a screening - # - # name - String of the film name - def initialize(name) - @name = name - @slug = name.downcase.gsub(/[^0-9a-z ]/,'').gsub(/\s+/, '-') end end end