Class: Axiom::Aggregate::Mean
- Inherits:
-
Axiom::Aggregate
- Object
- Function
- Axiom::Aggregate
- Axiom::Aggregate::Mean
- Defined in:
- lib/axiom/aggregate/mean.rb
Overview
The mean of a sequence of numbers
Defined Under Namespace
Modules: Methods
Constant Summary collapse
- DEFAULT =
[0, nil].freeze
Instance Attribute Summary
Attributes included from Operation::Unary
Class Method Summary collapse
-
.call(accumulator, value) ⇒ Array(Integer, Rational)
Return the count and mean for a sequence of numbers.
-
.finalize(accumulator) ⇒ Float?
Extract the mean from the accumulator.
-
.type ⇒ Class<Types::Float>
Return the type returned from #call.
Methods inherited from Axiom::Aggregate
#call, #default, default, #finalize
Methods included from Operation::Unary
Methods inherited from Function
extract_value, rename_attributes, #type
Methods included from Visitable
Class Method Details
.call(accumulator, value) ⇒ Array(Integer, Rational)
Return the count and mean for a sequence of numbers
23 24 25 26 27 28 |
# File 'lib/axiom/aggregate/mean.rb', line 23 def self.call(accumulator, value) return accumulator if value.nil? count, mean = accumulator count = Count.call(count, value) [count, mean ? Rational(value - mean, count) + mean : value.to_r] end |
.finalize(accumulator) ⇒ Float?
Extract the mean from the accumulator
43 44 45 46 |
# File 'lib/axiom/aggregate/mean.rb', line 43 def self.finalize(accumulator) mean = accumulator.last mean.to_f if mean end |
.type ⇒ Class<Types::Float>
Return the type returned from #call
56 57 58 |
# File 'lib/axiom/aggregate/mean.rb', line 56 def self.type Types::Float end |