class Proforma::Modeling::Grouping

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.)

Attributes

children[W]
property[RW]

Public Class Methods

new(children: [], property: nil) click to toggle source
# File lib/proforma/modeling/grouping.rb, line 23
def initialize(children: [], property: nil)
  @children = ModelFactory.array(children)
  @property = property
end

Public Instance Methods

children() click to toggle source
# File lib/proforma/modeling/grouping.rb, line 28
def children
  Array(@children)
end
compile(data, evaluator) click to toggle source
# 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