Class: Burner::Library::Collection::Zip

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

Overview

This job can take two arrays and coalesces them by index. For example:

input:

base_register: [ 'hello', 'bugs' ]
with_register: [ 'world', 'bunny' ]

output:

register: [ ['hello', 'world'], ['bugs', 'bunny'] ]

Expected Payload input: array of objects. Expected Payload input: array of objects. Payload output: An array of two-dimensional arrays.

Constant Summary

Constants inherited from JobWithRegister

JobWithRegister::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(with_register:, base_register: DEFAULT_REGISTER, name: '', register: DEFAULT_REGISTER) ⇒ Zip

Returns a new instance of Zip.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/burner/library/collection/zip.rb', line 27

def initialize(
  with_register:,
  base_register: DEFAULT_REGISTER,
  name: '',
  register: DEFAULT_REGISTER
)
  super(name: name, register: register)

  @base_register = base_register.to_s
  @with_register = with_register.to_s

  freeze
end

Instance Attribute Details

#base_registerObject (readonly)

Returns the value of attribute base_register.



25
26
27
# File 'lib/burner/library/collection/zip.rb', line 25

def base_register
  @base_register
end

#with_registerObject (readonly)

Returns the value of attribute with_register.



25
26
27
# File 'lib/burner/library/collection/zip.rb', line 25

def with_register
  @with_register
end

Instance Method Details

#perform(output, payload) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/burner/library/collection/zip.rb', line 41

def perform(output, payload)
  base_data = array(payload[base_register])
  with_data = array(payload[with_register])

  output.detail("Combining register: #{base_register} (#{base_data.length} record(s))")
  output.detail("With register: #{with_register} (#{with_data.length} record(s))")

  payload[register] = base_data.zip(with_data)
end