From 7321a3a7d314585093d08c098eca38afd3b57b00 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 12 May 2010 08:47:55 +0200 Subject: revises the rdoc of #average according to 5f3bd55, and realigns when clauses --- activerecord/lib/active_record/relation/calculations.rb | 9 ++++----- 1 file 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 -- cgit v1.2.3