Browse files

revises the rdoc of #average according to 5f3bd55, and realigns when …

…clauses
  • Loading branch information...
1 parent 5f3bd55 commit 7321a3a7d314585093d08c098eca38afd3b57b00 @fxn fxn committed May 12, 2010
Showing with 4 additions and 5 deletions.
  1. +4 −5 activerecord/lib/active_record/relation/calculations.rb
View
9 activerecord/lib/active_record/relation/calculations.rb
@@ -45,9 +45,8 @@ def count(column_name = nil, options = {})
calculate(:count, column_name, options)
end
- # Calculates the average value on a given column. The value is returned as
- # a float, or +nil+ if there's no row. See +calculate+ for examples with
- # options.
+ # Calculates the average value on a given column. Returns +nil+ if there's
+ # no row. See +calculate+ for examples with options.
#
# Person.average('age') # => 35.8
def average(column_name, options = {})
@@ -241,8 +240,8 @@ def column_for(field)
def type_cast_calculated_value(value, column, operation = nil)
if value.is_a?(String) || value.nil?
case operation
- when 'count' then value.to_i
- when 'sum' then type_cast_using_column(value || '0', column)
+ when 'count' then value.to_i
+ when 'sum' then type_cast_using_column(value || '0', column)
when 'average' then value.try(:to_d)
else type_cast_using_column(value, column)
end

0 comments on commit 7321a3a

Please sign in to comment.