Class: Proforma::Modeling::Grouping
- Inherits:
-
Object
- Object
- Proforma::Modeling::Grouping
- Includes:
- Compiling::Compilable
- Defined in:
- lib/proforma/modeling/grouping.rb
Overview
A grouping is an inverted collection, meaning, it iterates each child once per record instead of only one time. It also provides a mechanic to traverse data to tap nested child data (through the property attribute.)
Instance Attribute Summary collapse
- #children ⇒ Object
-
#property ⇒ Object
Returns the value of attribute property.
Instance Method Summary collapse
- #compile(data, evaluator) ⇒ Object
-
#initialize(children: [], property: nil) ⇒ Grouping
constructor
A new instance of Grouping.
Constructor Details
#initialize(children: [], property: nil) ⇒ Grouping
Returns a new instance of Grouping.
23 24 25 26 |
# File 'lib/proforma/modeling/grouping.rb', line 23 def initialize(children: [], property: nil) @children = ModelFactory.array(children) @property = property end |
Instance Attribute Details
#children ⇒ Object
28 29 30 |
# File 'lib/proforma/modeling/grouping.rb', line 28 def children Array(@children) end |
#property ⇒ Object
Returns the value of attribute property.
19 20 21 |
# File 'lib/proforma/modeling/grouping.rb', line 19 def property @property end |
Instance Method Details
#compile(data, evaluator) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/proforma/modeling/grouping.rb', line 32 def compile(data, evaluator) records = array(evaluator.value(data, property)) records.map { |record| Collection.new(children: children).compile(record, evaluator) } .flatten end |