Class: RateableElement
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RateableElement
- Defined in:
- lib/rating_for/rateable_element.rb
Instance Method Summary collapse
- #<<(rating) ⇒ Object
- #add(value, rater = nil) ⇒ Object
- #add_rating(rating) ⇒ Object
- #average_rating ⇒ Object
- #average_rating=(value) ⇒ Object
- #clear ⇒ Object
- #rated_by?(rater) ⇒ Boolean
- #recalculate_rating ⇒ Object
- #recalculate_rating_without(ratings) ⇒ Object
- #remove_all ⇒ Object
- #remove_by_rater(rater) ⇒ Object
- #remove_rating(rating) ⇒ Object
Instance Method Details
#<<(rating) ⇒ Object
18 19 20 |
# File 'lib/rating_for/rateable_element.rb', line 18 def <<() self.() end |
#add(value, rater = nil) ⇒ Object
30 31 32 |
# File 'lib/rating_for/rateable_element.rb', line 30 def add(value, rater = nil) self.(Rating.new(:rater => rater, :value => value)) end |
#add_rating(rating) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rating_for/rateable_element.rb', line 22 def () return self. unless .is_a?(Rating) self. << self. += .value self. += 1 self.save end |
#average_rating ⇒ Object
10 11 12 |
# File 'lib/rating_for/rateable_element.rb', line 10 def self. end |
#average_rating=(value) ⇒ Object
14 15 16 |
# File 'lib/rating_for/rateable_element.rb', line 14 def (value) self. = value end |
#clear ⇒ Object
48 49 50 51 |
# File 'lib/rating_for/rateable_element.rb', line 48 def clear self. = [] self. end |
#rated_by?(rater) ⇒ Boolean
57 58 59 |
# File 'lib/rating_for/rateable_element.rb', line 57 def rated_by?(rater) not self..find_all_by_rater_id(rater.id, :conditions => {:rater_type => rater.class.name}).empty? end |
#recalculate_rating ⇒ Object
61 62 63 |
# File 'lib/rating_for/rateable_element.rb', line 61 def self.([]) end |
#recalculate_rating_without(ratings) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rating_for/rateable_element.rb', line 65 def () return unless (.is_a? Rating or .is_a? Array) self. = 0 self. = 0 self. = 0 = self. - [].compact.flatten .each do |r| self. += r.value self. += 1 end self.save end |
#remove_all ⇒ Object
53 54 55 |
# File 'lib/rating_for/rateable_element.rb', line 53 def remove_all self.clear end |
#remove_by_rater(rater) ⇒ Object
42 43 44 45 46 |
# File 'lib/rating_for/rateable_element.rb', line 42 def remove_by_rater(rater) self..find_all_by_rater_id(rater.id, :conditions => {:rater_type => rater.class.name}).each do || self.() end end |
#remove_rating(rating) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rating_for/rateable_element.rb', line 34 def () return self. unless .is_a?(Rating) self. -= .value self. -= 1 .destroy self.save end |