Class: Alf::Engine::Aggregate
- Inherits:
-
Object
- Object
- Alf::Engine::Aggregate
- Includes:
- Cog
- Defined in:
- lib/alf-engine/alf/engine/aggregate.rb
Overview
Aggregates the whole operand according to a Summarization. The result contains only one tuple.
Example:
res = [
{:name => "Jones", :price => 12.0, :id => 1},
{:name => "Smith", :price => 10.0, :id => 2}
]
agg = Summarization[:size => "count",
:total => "sum{ price }"]
Aggregate.new(res, agg).to_a
# => [
# {:size => 2, :total => 22.0}
# ]
Instance Attribute Summary collapse
-
#operand ⇒ Enumerable
readonly
The operand.
-
#summarization ⇒ Summarization
readonly
The summarization to use.
Instance Method Summary collapse
- #_each {|@summarization.finalize(agg)| ... } ⇒ Object
-
#initialize(operand, summarization) ⇒ Aggregate
constructor
Creates an Aggregate instance.
Methods included from Cog
Constructor Details
#initialize(operand, summarization) ⇒ Aggregate
Creates an Aggregate instance
30 31 32 33 |
# File 'lib/alf-engine/alf/engine/aggregate.rb', line 30 def initialize(operand, summarization) @operand = operand @summarization = summarization end |
Instance Attribute Details
#operand ⇒ Enumerable (readonly)
Returns The operand.
24 25 26 |
# File 'lib/alf-engine/alf/engine/aggregate.rb', line 24 def operand @operand end |
#summarization ⇒ Summarization (readonly)
Returns The summarization to use.
27 28 29 |
# File 'lib/alf-engine/alf/engine/aggregate.rb', line 27 def summarization @summarization end |
Instance Method Details
#_each {|@summarization.finalize(agg)| ... } ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/alf-engine/alf/engine/aggregate.rb', line 36 def _each scope = tuple_scope agg = operand.inject(@summarization.least) do |memo,tuple| @summarization.happens(memo, scope.__set_tuple(tuple)) end yield @summarization.finalize(agg) end |