Class: Proforma::Compiling::Aggregation
- Inherits:
-
Object
- Object
- Proforma::Compiling::Aggregation
- Defined in:
- lib/proforma/compiling/aggregation.rb
Overview
This class is a group of aggregators that knows how to process records.
Instance Attribute Summary collapse
-
#aggregators ⇒ Object
readonly
Returns the value of attribute aggregators.
-
#evaluator ⇒ Object
readonly
Returns the value of attribute evaluator.
Instance Method Summary collapse
- #add(records) ⇒ Object
-
#initialize(aggregators, evaluator) ⇒ Aggregation
constructor
A new instance of Aggregation.
- #to_h ⇒ Object
Constructor Details
#initialize(aggregators, evaluator) ⇒ Aggregation
Returns a new instance of Aggregation.
16 17 18 19 20 21 22 23 24 |
# File 'lib/proforma/compiling/aggregation.rb', line 16 def initialize(aggregators, evaluator) raise ArgumentError, 'evaluator is required' unless evaluator @aggregators = Array(aggregators) @counters = {} @evaluator = evaluator freeze end |
Instance Attribute Details
#aggregators ⇒ Object (readonly)
Returns the value of attribute aggregators.
14 15 16 |
# File 'lib/proforma/compiling/aggregation.rb', line 14 def aggregators @aggregators end |
#evaluator ⇒ Object (readonly)
Returns the value of attribute evaluator.
14 15 16 |
# File 'lib/proforma/compiling/aggregation.rb', line 14 def evaluator @evaluator end |
Instance Method Details
#add(records) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/proforma/compiling/aggregation.rb', line 26 def add(records) records.each do |record| aggregators.each do |aggregator| property = aggregator.property value = property.to_s.empty? ? nil : evaluator.value(record, property) name = aggregator.name entry(name).add(value) end end self end |
#to_h ⇒ Object
40 41 42 |
# File 'lib/proforma/compiling/aggregation.rb', line 40 def to_h aggregators.map { |aggregator| execute(aggregator) }.to_h end |