Class: Burner::Library::Collection::Transform

Inherits:
JobWithRegister show all
Defined in:
lib/burner/library/collection/transform.rb

Overview

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.

Constant Summary collapse

BLANK =
''

Instance Attribute Summary collapse

Attributes inherited from JobWithRegister

#register

Attributes inherited from Job

#name

Instance Method Summary collapse

Methods included from Util::Arrayable

#array

Constructor Details

#initialize(attributes: [], exclusive: false, name: '', register: DEFAULT_REGISTER, separator: BLANK) ⇒ Transform

Returns a new instance of Transform.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/burner/library/collection/transform.rb', line 30

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

Instance Attribute Details

#attribute_renderersObject (readonly)

Returns the value of attribute attribute_renderers.



26
27
28
# File 'lib/burner/library/collection/transform.rb', line 26

def attribute_renderers
  @attribute_renderers
end

#exclusiveObject (readonly)

Returns the value of attribute exclusive.



26
27
28
# File 'lib/burner/library/collection/transform.rb', line 26

def exclusive
  @exclusive
end

#resolverObject (readonly)

Returns the value of attribute resolver.



26
27
28
# File 'lib/burner/library/collection/transform.rb', line 26

def resolver
  @resolver
end

Instance Method Details

#perform(output, payload) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/burner/library/collection/transform.rb', line 49

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