class Burner::Library::Collection::Transform

Iterate over all objects and return a new set of transformed objects. The object is transformed per the “transformers” attribute for its attributes. An attribute defines the ultimate key to place the value in and then the transformer pipeline to use to derive the value. Under the hood this uses the Realize library:

https://github.com/bluemarblepayroll/realize

For more information on the specific contract for attributes, see the Burner::Modeling::Attribute class.

Expected Payload input: array of objects. Payload output: An array of objects.

Attributes

attribute_renderers[R]
exclusive[R]
resolver[R]

Public Class Methods

new( attributes: [], exclusive: false, name: '', register: DEFAULT_REGISTER, separator: BLANK ) click to toggle source
Calls superclass method Burner::JobWithRegister::new
# File lib/burner/library/collection/transform.rb, line 28
def initialize(
  attributes: [],
  exclusive: false,
  name: '',
  register: DEFAULT_REGISTER,
  separator: BLANK
)
  super(name: name, register: register)

  @resolver  = Objectable.resolver(separator: separator)
  @exclusive = exclusive || false

  @attribute_renderers =
    Modeling::Attribute.array(attributes)
                       .map { |a| Modeling::AttributeRenderer.new(a, resolver) }

  freeze
end

Public Instance Methods

perform(output, payload) click to toggle source
# File lib/burner/library/collection/transform.rb, line 47
def perform(output, payload)
  payload[register] = array(payload[register]).map { |row| transform(row, payload.time) }

  attr_count = attribute_renderers.length
  row_count  = payload[register].length

  output.detail("Transformed #{attr_count} attributes(s) for #{row_count} row(s)")
end

Private Instance Methods

transform(row, time) click to toggle source
# File lib/burner/library/collection/transform.rb, line 58
def transform(row, time)
  outgoing_row = exclusive ? {} : row

  attribute_renderers.each_with_object(outgoing_row) do |attribute_renderer, memo|
    value = attribute_renderer.transform(row, time)

    resolver.set(memo, attribute_renderer.key, value)
  end
end