module SelfRateable::Core::InstanceMethods::Points
Public Instance Methods
vote(rater, val)
click to toggle source
# File lib/self_rateable/core/instance_methods.rb, line 61 def vote(rater, val) value = parse_val(val) if voted_by_rater?(rater) # set new star rating if already rated return false else #create new record if not yet rated ratings << SelfRateable::Rating.new(rating: value.to_i, rater_id: rater.try(:id)) end self.save! end
voted_by_rater?(rater)
click to toggle source
# File lib/self_rateable/core/instance_methods.rb, line 57 def voted_by_rater?(rater) ratings.where(:rater_id => rater.id).count > 0 end
votes()
click to toggle source
# File lib/self_rateable/core/instance_methods.rb, line 53 def votes ratings.sum(:rating).to_f end
Private Instance Methods
parse_val(val)
click to toggle source
# File lib/self_rateable/core/instance_methods.rb, line 75 def parse_val(val) val ? 1 : -1 end