module FiveStar::Rateable
A module to be included to enhance an object with the interface below.
Public Class Methods
Extends base class or a module with Rateable
methods
@param base [Object]
the object to mix in this *Rateable* module
@return [undefined]
@api private
# File lib/five-star/rateable.rb, line 12 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
Reference to Configuration
used for this rateable
instance. Delegates to class.
@return [FiveStar::Configuration] Configuration
instance in use
@api private
# File lib/five-star/rateable.rb, line 114 def configuration self.class.configuration end
The name of the object that is rateable. This may be used by raters when generating descriptions. This can be overridden to provide a better response, otherwise is the class name.
@return [String] name of the class
@api public
# File lib/five-star/rateable.rb, line 105 def rateable_name self.class.name end
Return the rating given to the rateable
object by calculating based on set raters and their configuration.
@example
film = Film.new film.rating # => 6.0
@return [Float] rating calculated by set raters for the object
@raise [FiveStar::RatingError] raises error if any raters return either
+rating+ or +weighting+ that is outside of configuration bounds.
@api public
# File lib/five-star/rateable.rb, line 78 def rating rating_calculator.rate(self.class.configuration, raters) end
Return the rating description for each rater given to the rateable
object. These are returned in the order in which the rating classes were defined in rate_with
.
@example
film = Film.new film.rating_descriptions # => ["The film Alien was rated 8 for gore", ...]
@return [Array] list of descriptions from each rater
@api public
# File lib/five-star/rateable.rb, line 94 def rating_descriptions raters.map { |rater| rater.description } end
Protected Instance Methods
The instance that included this module
@return [Object] self
@api protected
# File lib/five-star/rateable.rb, line 125 def rateable self end
Private Instance Methods
# File lib/five-star/rateable.rb, line 131 def raters @raters ||= rating_klasses.map { |rater| rater.build(rateable) } end
# File lib/five-star/rateable.rb, line 139 def rating_calculator RatingCalculator end
# File lib/five-star/rateable.rb, line 135 def rating_klasses rateable.class.rating_klasses end