Class: Axiom::Aggregate::Sum
- Inherits:
-
Axiom::Aggregate
- Object
- Function
- Axiom::Aggregate
- Axiom::Aggregate::Sum
- Defined in:
- lib/axiom/aggregate/sum.rb
Overview
The sum of a sequence of numbers
Defined Under Namespace
Modules: Methods
Constant Summary collapse
- DEFAULT =
0
Instance Attribute Summary
Attributes included from Operation::Unary
Class Method Summary collapse
-
.call(sum, value) ⇒ Numeric
Return the sum for a sequence of numbers.
Instance Method Summary collapse
-
#default ⇒ Numeric
Return the default sum.
-
#type ⇒ Class<Types::Numeric>
Return the type returned from #call.
Methods inherited from Axiom::Aggregate
#call, default, finalize, #finalize
Methods included from Operation::Unary
Methods inherited from Function
extract_value, rename_attributes
Methods included from Visitable
Class Method Details
.call(sum, value) ⇒ Numeric
Return the sum for a sequence of numbers
23 24 25 26 |
# File 'lib/axiom/aggregate/sum.rb', line 23 def self.call(sum, value) return sum if value.nil? sum + value end |
Instance Method Details
#default ⇒ Numeric
TODO:
refactor once functions know their return types
Return the default sum
44 45 46 47 48 49 50 |
# File 'lib/axiom/aggregate/sum.rb', line 44 def default if type <= Types::Float then super.to_f elsif type <= Types::Decimal then super.to_d else super end end |
#type ⇒ Class<Types::Numeric>
Return the type returned from #call
60 61 62 |
# File 'lib/axiom/aggregate/sum.rb', line 60 def type Attribute.infer_type(operand) end |