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.
40 41 42 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 40 def ( = {}) Rating.create(score: [:score], rater: [:rater], ratee: self) end |
#any_ratings? ⇒ Boolean
Has this object been rated before?
29 30 31 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 29 def .any? end |
#average_rating ⇒ Object
Find the Average rating for the ratee. Return 0.0 if they have not been rated yet.
23 24 25 26 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 23 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?
34 35 36 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 34 def && .length > IsRateable. end |