Module: IsRateable::ActsAsRateable::LocalInstanceMethods
- Defined in:
- lib/is_rateable/acts_as_rateable.rb
Instance Method Summary collapse
-
#add_rating(options = {}) ⇒ Object
Easily add a new rating to the object by calling Object.add_rating(score: 5, rater: user) Pass in the entire rater object in, rather than the id.
-
#any_ratings? ⇒ Boolean
Has this object been rated before?.
-
#average_rating ⇒ Object
Find the Average rating for the ratee.
-
#enough_ratings_for_average? ⇒ Boolean
Has the object received enough ratings to show the average?.
Instance Method Details
#add_rating(options = {}) ⇒ Object
Easily add a new rating to the object by calling Object.add_rating(score: 5, rater: user) Pass in the entire rater object in, rather than the id.
37 38 39 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 37 def ( = {}) Rating.create(score: [:score], rater: [:rater], ratee: self) end |
#any_ratings? ⇒ Boolean
Has this object been rated before?
26 27 28 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 26 def .any? end |
#average_rating ⇒ Object
Find the Average rating for the ratee. Return 0.0 if they have not been rated yet.
20 21 22 23 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 20 def return IsRateable. unless ? ((.average(:score) * 10).round / 10.0) : 0.0 end |
#enough_ratings_for_average? ⇒ Boolean
Has the object received enough ratings to show the average?
31 32 33 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 31 def && .length > IsRateable. end |