Class: SeemsRateable::Rating
- Inherits:
-
Struct
- Object
- Struct
- SeemsRateable::Rating
- Defined in:
- lib/seems_rateable/rating.rb
Instance Attribute Summary collapse
-
#rates ⇒ Object
Returns the value of attribute rates.
Instance Method Summary collapse
Instance Attribute Details
#rates ⇒ Object
Returns the value of attribute rates
2 3 4 |
# File 'lib/seems_rateable/rating.rb', line 2 def rates @rates end |
Instance Method Details
#average ⇒ Object
3 4 5 |
# File 'lib/seems_rateable/rating.rb', line 3 def average sum/(count.nonzero? || 1) end |
#count ⇒ Object
11 12 13 |
# File 'lib/seems_rateable/rating.rb', line 11 def count stars.length end |
#stars ⇒ Object
15 16 17 |
# File 'lib/seems_rateable/rating.rb', line 15 def stars @stars ||= rates.pluck(:stars) end |
#sum ⇒ Object
7 8 9 |
# File 'lib/seems_rateable/rating.rb', line 7 def sum stars.inject(:+).to_f end |