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 =
"0.0.2"
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.
33 34 35 |
# File 'lib/app/models/rails_rateable.rb', line 33 def && . || 0.0 end |
#average_rating_percent ⇒ Object
Returns the average rating in percent.
43 44 45 46 |
# File 'lib/app/models/rails_rateable.rb', line 43 def f = 100 / .to_f * f end |
#average_rating_round ⇒ Object
Rounds the average rating value.
38 39 40 |
# File 'lib/app/models/rails_rateable.rb', line 38 def .round end |
#rate_it(score, user) ⇒ Object
Rates the object by a given score. A user object should be passed to the method.
27 28 29 30 |
# File 'lib/app/models/rails_rateable.rb', line 27 def rate_it(score, user) unless .rate(score, user) end |
#rated_by?(user) ⇒ Boolean
Checks whether a user rated the object or not.
54 55 56 |
# File 'lib/app/models/rails_rateable.rb', line 54 def rated_by?(user) && ..exists?(:user_id => user) end |
#rating_by(user) ⇒ Object
Returns the rating a specific user has given the object.
59 60 61 62 |
# File 'lib/app/models/rails_rateable.rb', line 59 def (user) = && ..find_by_user_id(user.id) ? .score : nil end |
#ratings_count ⇒ Object
Returns the number of ratings.
49 50 51 |
# File 'lib/app/models/rails_rateable.rb', line 49 def && . || 0 end |