Class: Burner::Library::Collection::Zip
- Inherits:
-
JobWithRegister
- Object
- Job
- JobWithRegister
- Burner::Library::Collection::Zip
- 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
Instance Attribute Summary collapse
-
#base_register ⇒ Object
readonly
Returns the value of attribute base_register.
-
#with_register ⇒ Object
readonly
Returns the value of attribute with_register.
Attributes inherited from JobWithRegister
Attributes inherited from Job
Instance Method Summary collapse
-
#initialize(with_register:, base_register: DEFAULT_REGISTER, name: '', register: DEFAULT_REGISTER) ⇒ Zip
constructor
A new instance of Zip.
- #perform(output, payload) ⇒ Object
Methods included from Util::Arrayable
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_register ⇒ Object (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_register ⇒ Object (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 |