Class: FiveStar::BaseRater
- Inherits:
-
Object
- Object
- FiveStar::BaseRater
- Defined in:
- lib/five-star/base_rater.rb
Overview
Base implementation of a class to give a rating, weighting and description to a rateable instance.
You are expected to subclass this class and override the default implementation with your own implementation.
Class Method Summary collapse
-
.build(rateable) ⇒ Object
Called to build a new instance of the rater with the given object being rated.
-
.rating_weight(weighting) ⇒ undefined
Set the weighting for this rating classifcation class.
-
.weighting ⇒ Float
Return the weighting value for this rating classifcation class.
Instance Method Summary collapse
-
#description ⇒ String
Return the rating description for the rater given to the
rateableobject. -
#initialize(rateable) ⇒ BaseRater
constructor
private
Create a new instance of rater.
-
#rating ⇒ Float
Return the rating for the rater given to the
rateableobject. -
#weighting ⇒ Float
Return the weighting value for this rating classifcation class.
Constructor Details
#initialize(rateable) ⇒ BaseRater
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.
Create a new instance of rater
55 56 57 |
# File 'lib/five-star/base_rater.rb', line 55 def initialize(rateable) @rateable = rateable end |
Class Method Details
.build(rateable) ⇒ Object
Called to build a new instance of the rater with the given object being rated.
16 17 18 |
# File 'lib/five-star/base_rater.rb', line 16 def self.build(rateable) new(rateable) end |
.rating_weight(weighting) ⇒ undefined
Set the weighting for this rating classifcation class. This should a valid floating point within the scale configured.
35 36 37 |
# File 'lib/five-star/base_rater.rb', line 35 def self.(weighting) @weighting = weighting end |
.weighting ⇒ Float
Return the weighting value for this rating classifcation class.
45 46 47 |
# File 'lib/five-star/base_rater.rb', line 45 def self.weighting @weighting ||= Configuration::DEFAULT_WEIGHTING end |
Instance Method Details
#description ⇒ String
Return the rating description for the rater given to the rateable object. Override this method to customise the message.
77 78 79 |
# File 'lib/five-star/base_rater.rb', line 77 def description "#{self.class} rated #{rateable_name} at #{rating} with weighting of #{weighting}" end |
#rating ⇒ Float
Return the rating for the rater given to the rateable object. You are expected to override this method to perform your own calculation for the rating based on your own criteria. If this is an expensive operation then the result should be cached as this method can be called more than once, for example by the description method.
112 113 114 |
# File 'lib/five-star/base_rater.rb', line 112 def configuration. end |
#weighting ⇒ Float
Return the weighting value for this rating classifcation class.
122 123 124 |
# File 'lib/five-star/base_rater.rb', line 122 def weighting self.class.weighting end |