Class: Burner::Library::Collection::Concatenate

Inherits:
Job
  • Object
show all
Defined in:
lib/burner/library/collection/concatenate.rb

Overview

Take the list of from_registers and concatenate each of their values together. Each from_value will be coerced into an array if it not an array.

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

Instance Attribute Summary collapse

Attributes inherited from Job

#name

Instance Method Summary collapse

Methods included from Util::Arrayable

#array

Constructor Details

#initialize(from_registers: [], name: '', to_register: DEFAULT_REGISTER) ⇒ Concatenate

Returns a new instance of Concatenate.



21
22
23
24
25
26
27
28
# File 'lib/burner/library/collection/concatenate.rb', line 21

def initialize(from_registers: [], name: '', to_register: DEFAULT_REGISTER)
  super(name: name)

  @from_registers = Array(from_registers)
  @to_register    = to_register.to_s

  freeze
end

Instance Attribute Details

#from_registersObject (readonly)

Returns the value of attribute from_registers.



19
20
21
# File 'lib/burner/library/collection/concatenate.rb', line 19

def from_registers
  @from_registers
end

#to_registerObject (readonly)

Returns the value of attribute to_register.



19
20
21
# File 'lib/burner/library/collection/concatenate.rb', line 19

def to_register
  @to_register
end

Instance Method Details

#perform(output, payload) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/burner/library/collection/concatenate.rb', line 30

def perform(output, payload)
  output.detail("Concatenating registers: '#{from_registers}' to: '#{to_register}'")

  payload[to_register] = from_registers.each_with_object([]) do |from_register, memo|
    from_register_value = array(payload[from_register])

    memo.concat(from_register_value)
  end
end