Module: IsRateable::ActsAsRater::LocalInstanceMethods

Defined in:
lib/is_rateable/acts_as_rater.rb

Instance Method Summary collapse

Instance Method Details

#rated_any?Boolean

Has this object rated anything yet?

Returns:

  • (Boolean)


19
20
21
# File 'lib/is_rateable/acts_as_rater.rb', line 19

def rated_any?
  rated_ratings.any?
end

#rating_for(ratee) ⇒ Object

Return the objects rating for another object



24
25
26
27
# File 'lib/is_rateable/acts_as_rater.rb', line 24

def rating_for(ratee)
  return nil unless rated_ratings.where(ratee: ratee).first
  ((rated_ratings.where(ratee: ratee).average(:score) * 10).round / 10.0)
end