Module: RailsRateable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rails_rateable/version.rb,
lib/app/models/rails_rateable.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"1.0.0"
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.
31 32 33 |
# File 'lib/app/models/rails_rateable.rb', line 31 def && . || 0.0 end |
#average_rating_percent ⇒ Object
Returns the average rating in percent.
41 42 43 44 |
# File 'lib/app/models/rails_rateable.rb', line 41 def f = 100 / .to_f * f end |
#average_rating_round ⇒ Object
Rounds the average rating value.
36 37 38 |
# File 'lib/app/models/rails_rateable.rb', line 36 def .round end |
#rate_it(score, user) ⇒ Object
Rates the object by a given score. A user object should be passed to the method.
25 26 27 28 |
# File 'lib/app/models/rails_rateable.rb', line 25 def rate_it(score, user) unless .rate(score, user) end |
#rated_by?(user) ⇒ Boolean
Checks whether a user rated the object or not.
52 53 54 |
# File 'lib/app/models/rails_rateable.rb', line 52 def rated_by?(user) && ..exists?(:user_id => user) end |
#rating_by(user) ⇒ Object
Returns the rating a specific user has given the object.
57 58 59 60 |
# File 'lib/app/models/rails_rateable.rb', line 57 def (user) = && ..find_by_user_id(user.id) ? .score : nil end |
#ratings_count ⇒ Object
Returns the number of ratings.
47 48 49 |
# File 'lib/app/models/rails_rateable.rb', line 47 def && . || 0 end |