Method: WeightedAverage::ActiveRecordRelationInstanceMethods#weighted_average
- Defined in:
- lib/weighted_average/active_record_relation_instance_methods.rb
#weighted_average(data_column_names, options = {}) ⇒ Float?
Get the weighted average of column(s).
In addition to the options available on WeightedAverage::ArelSelectManagerInstanceMethods#weighted_average, this ActiveRecord-specific method understands associations.
23 24 25 26 |
# File 'lib/weighted_average/active_record_relation_instance_methods.rb', line 23 def weighted_average(data_column_names, = {}) weighted_average = connection.select_value weighted_average_relation(data_column_names, ).to_sql weighted_average.nil? ? nil : weighted_average.to_f end |