Module: ActiveRecord::Acts::Rateable::InstanceMethods
- Defined in:
- lib/acts_as_rateable.rb
Instance Method Summary collapse
-
#average_rating ⇒ Object
Returns the average rating.
-
#average_rating_percent ⇒ Object
Returns the average rating in percent.
-
#average_rating_round ⇒ Object
Rounds the average rating value.
-
#rate_it(score, user) ⇒ Object
Rates the object by a given score.
-
#rated_by?(user) ⇒ Boolean
Checks whether a user rated the object or not.
-
#rating_by(user) ⇒ Object
Returns the rating a specific user has given the object.
-
#ratings_count ⇒ Object
Returns the number of ratings.
Instance Method Details
#average_rating ⇒ Object
Returns the average rating. Calculation based on the already given scores.
45 46 47 |
# File 'lib/acts_as_rateable.rb', line 45 def && . || 0.0 end |
#average_rating_percent ⇒ Object
Returns the average rating in percent.
55 56 57 58 |
# File 'lib/acts_as_rateable.rb', line 55 def f = 100 / .to_f * f end |
#average_rating_round ⇒ Object
Rounds the average rating value.
50 51 52 |
# File 'lib/acts_as_rateable.rb', line 50 def .round end |
#rate_it(score, user) ⇒ Object
Rates the object by a given score. A user object should be passed to the method.
39 40 41 42 |
# File 'lib/acts_as_rateable.rb', line 39 def rate_it(score, user) unless .rate(score, user) end |
#rated_by?(user) ⇒ Boolean
Checks whether a user rated the object or not.
66 67 68 |
# File 'lib/acts_as_rateable.rb', line 66 def rated_by?(user) && ..exists?(:user_id => user) end |
#rating_by(user) ⇒ Object
Returns the rating a specific user has given the object.
71 72 73 74 |
# File 'lib/acts_as_rateable.rb', line 71 def (user) = && ..find_by_user_id(user.id) ? .score : nil end |
#ratings_count ⇒ Object
Returns the number of ratings.
61 62 63 |
# File 'lib/acts_as_rateable.rb', line 61 def && . || 0 end |