Returns the average rating. Calculation based on the already given scores.
# File lib/acts_as_rateable.rb, line 45 def average_rating rating && rating.average_rating || 0.0 end
Returns the average rating in percent.
# File lib/acts_as_rateable.rb, line 55 def average_rating_percent f = 100 / max_rating.to_f average_rating * f end
Rounds the average rating value.
# File lib/acts_as_rateable.rb, line 50 def average_rating_round average_rating.round end
Rates the object by a given score. A user object should be passed to the method.
# File lib/acts_as_rateable.rb, line 39 def rate_it(score, user) create_rating unless rating rating.rate(score, user) end
Checks whether a user rated the object or not.
# File lib/acts_as_rateable.rb, line 66 def rated_by?(user) rating && rating.user_ratings.exists?(:user_id => user) end
Returns the rating a specific user has given the object.
# File lib/acts_as_rateable.rb, line 71 def rating_by(user) user_rating = rating && rating.user_ratings.find_by_user_id(user.id) user_rating ? user_rating.score : nil end
Returns the number of ratings.
# File lib/acts_as_rateable.rb, line 61 def ratings_count rating && rating.ratings_count || 0 end