aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/calculations.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-05-12 08:47:55 +0200
committerXavier Noria <fxn@hashref.com>2010-05-12 08:47:55 +0200
commit7321a3a7d314585093d08c098eca38afd3b57b00 (patch)
tree4580ed57e7ed4fc5da7bbb72a925654fc16866ae /activerecord/lib/active_record/relation/calculations.rb
parent5f3bd55726703e08ba595555e1cf428c57832603 (diff)
downloadrails-7321a3a7d314585093d08c098eca38afd3b57b00.tar.gz
rails-7321a3a7d314585093d08c098eca38afd3b57b00.tar.bz2
rails-7321a3a7d314585093d08c098eca38afd3b57b00.zip
revises the rdoc of #average according to 5f3bd55, and realigns when clauses
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 0e11f89c8b..44baeb6c84 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -45,9 +45,8 @@ module ActiveRecord
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 @@ module ActiveRecord
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