Module: FiveStar::Rateable
- Defined in:
- lib/five-star/rateable.rb
Overview
A module to be included to enhance an object with the interface below.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ undefined
private
Extends base class or a module with Rateable methods.
Instance Method Summary collapse
-
#configuration ⇒ FiveStar::Configuration
private
Reference to Configuration used for this
rateableinstance. -
#rateable_name ⇒ String
The name of the object that is rateable.
-
#rating ⇒ Float
Return the rating given to the
rateableobject by calculating based on set raters and their configuration. -
#rating_descriptions ⇒ Array
Return the rating description for each rater given to the
rateableobject.
Class Method Details
.included(base) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Extends base class or a module with Rateable methods
12 13 14 |
# File 'lib/five-star/rateable.rb', line 12 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#configuration ⇒ FiveStar::Configuration
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reference to Configuration used for this rateable instance. Delegates to class.
114 115 116 |
# File 'lib/five-star/rateable.rb', line 114 def configuration self.class.configuration end |
#rateable_name ⇒ String
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.
105 106 107 |
# File 'lib/five-star/rateable.rb', line 105 def rateable_name self.class.name end |
#rating ⇒ Float
Return the rating given to the rateable object by calculating based on set raters and their configuration.
78 79 80 |
# File 'lib/five-star/rateable.rb', line 78 def .rate(self.class.configuration, raters) end |
#rating_descriptions ⇒ Array
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.
94 95 96 |
# File 'lib/five-star/rateable.rb', line 94 def raters.map { |rater| rater.description } end |