Module: SocialEngine::Rateable::InstanceMethods

Defined in:
app/models/social_engine/rateable.rb

Instance Method Summary collapse

Instance Method Details

#avg_ratingObject



13
14
15
16
17
# File 'app/models/social_engine/rateable.rb', line 13

def avg_rating
  avg = self.ratings.sum(:value).to_f/self.rating_count.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 avg_rating_formatted(decimal_places=1)
  return self.avg_rating.to_i.to_s if decimal_places==0
  sprintf("%.#{decimal_places}f", self.avg_rating)
end

#avg_rating_round_halfObject



28
29
30
# File 'app/models/social_engine/rateable.rb', line 28

def avg_rating_round_half
  (avg_rating*2).round / 2.0
end

#rateable?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/models/social_engine/rateable.rb', line 9

def rateable?
  true
end

#rating_countObject



24
25
26
# File 'app/models/social_engine/rateable.rb', line 24

def rating_count
  self.ratings.size
end