Module: SocialEngine::Rateable::InstanceMethods
- Defined in:
- app/models/social_engine/rateable.rb
Instance Method Summary collapse
- #avg_rating ⇒ Object
- #avg_rating_formatted(decimal_places = 1) ⇒ Object
- #avg_rating_round_half ⇒ Object
- #rateable? ⇒ Boolean
- #rating_count ⇒ Object
Instance Method Details
#avg_rating ⇒ Object
13 14 15 16 17 |
# File 'app/models/social_engine/rateable.rb', line 13 def avg = self..sum(:value).to_f/self..to_f rescue 0 avg = 0 if avg.nan? avg end |
#avg_rating_formatted(decimal_places = 1) ⇒ Object
19 20 21 22 |
# File 'app/models/social_engine/rateable.rb', line 19 def (decimal_places=1) return self..to_i.to_s if decimal_places==0 sprintf("%.#{decimal_places}f", self.) end |
#avg_rating_round_half ⇒ Object
28 29 30 |
# File 'app/models/social_engine/rateable.rb', line 28 def (*2).round / 2.0 end |
#rateable? ⇒ Boolean
9 10 11 |
# File 'app/models/social_engine/rateable.rb', line 9 def rateable? true end |
#rating_count ⇒ Object
24 25 26 |
# File 'app/models/social_engine/rateable.rb', line 24 def self..size end |