Class: Burner::Library::Collection::Values

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

Overview

Take an array of objects and call #values on each object. If include_keys is true (it is false by default), then call #keys on the first object and inject that as a “header” object.

Expected Payload input: array of objects. Payload output: An array of 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(include_keys: false, name: '', register: DEFAULT_REGISTER) ⇒ Values

Returns a new instance of Values.



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

def initialize(include_keys: false, name: '', register: DEFAULT_REGISTER)
  super(name: name, register: register)

  @include_keys = include_keys || false

  freeze
end

Instance Attribute Details

#include_keysObject (readonly)

Returns the value of attribute include_keys.



20
21
22
# File 'lib/burner/library/collection/values.rb', line 20

def include_keys
  @include_keys
end

Instance Method Details

#perform(_output, payload) ⇒ Object



30
31
32
33
34
35
# File 'lib/burner/library/collection/values.rb', line 30

def perform(_output, payload)
  payload[register] = array(payload[register])
  keys = include_keys ? [keys(payload[register].first)] : []
  values = payload[register].map { |object| values(object) }
  payload[register] = keys + values
end