Class: SeemsRateable::Rating

Inherits:
Struct
  • Object
show all
Defined in:
lib/seems_rateable/rating.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ratesObject

Returns the value of attribute rates

Returns:

  • (Object)

    the current value of rates



2
3
4
# File 'lib/seems_rateable/rating.rb', line 2

def rates
  @rates
end

Instance Method Details

#averageObject



3
4
5
# File 'lib/seems_rateable/rating.rb', line 3

def average
  sum/(count.nonzero? || 1)
end

#countObject



11
12
13
# File 'lib/seems_rateable/rating.rb', line 11

def count
  stars.length
end

#starsObject



15
16
17
# File 'lib/seems_rateable/rating.rb', line 15

def stars
  @stars ||= rates.pluck(:stars)
end

#sumObject



7
8
9
# File 'lib/seems_rateable/rating.rb', line 7

def sum
  stars.inject(:+).to_f
end