module RailsRateable
Constants
- VERSION
Public Instance Methods
average_rating()
click to toggle source
Returns the average rating. Calculation based on the already given scores.
# File lib/app/models/rails_rateable.rb, line 31 def average_rating rating && rating.average_rating || 0.0 end
average_rating_percent()
click to toggle source
Returns the average rating in percent.
# File lib/app/models/rails_rateable.rb, line 41 def average_rating_percent f = 100 / max_rating.to_f average_rating * f end
average_rating_round()
click to toggle source
Rounds the average rating value.
# File lib/app/models/rails_rateable.rb, line 36 def average_rating_round average_rating.round end
rate_it(score, user)
click to toggle source
Rates the object by a given score. A user object should be passed to the method.
# File lib/app/models/rails_rateable.rb, line 25 def rate_it(score, user) create_rating unless rating rating.rate(score, user) end
rated_by?(user)
click to toggle source
Checks whether a user rated the object or not.
# File lib/app/models/rails_rateable.rb, line 52 def rated_by?(user) rating && rating.user_ratings.exists?(:user_id => user) end
rating_by(user)
click to toggle source
Returns the rating a specific user has given the object.
# File lib/app/models/rails_rateable.rb, line 57 def rating_by(user) user_rating = rating && rating.user_ratings.find_by_user_id(user.id) user_rating ? user_rating.score : nil end
ratings_count()
click to toggle source
Returns the number of ratings.
# File lib/app/models/rails_rateable.rb, line 47 def ratings_count rating && rating.ratings_count || 0 end