Class: Axiom::Aggregate::Mean
- Inherits:
-
Axiom::Aggregate
- Object
- 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, Numeric)
Return the count and mean for a sequence of numbers.
-
.finalize(accumulator) ⇒ Float?
Extract the mean from the accumulator.
Instance Method Summary collapse
-
#type ⇒ Class<Attribute::Float>
Return the type returned from #call.
Methods inherited from Axiom::Aggregate
#call, #default, default, #finalize
Methods included from Visitable
Methods included from Operation::Unary
Class Method Details
.call(accumulator, value) ⇒ Array(Integer, Numeric)
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.nil? ? value.to_f : mean + ((value - mean) / count) ] end |
.finalize(accumulator) ⇒ Float?
Extract the mean from the accumulator
43 44 45 |
# File 'lib/axiom/aggregate/mean.rb', line 43 def self.finalize(accumulator) accumulator.last end |
Instance Method Details
#type ⇒ Class<Attribute::Float>
Return the type returned from #call
55 56 57 |
# File 'lib/axiom/aggregate/mean.rb', line 55 def type Attribute::Float end |