Class: Burner::Library::Collection::Coalesce
- Inherits:
-
JobWithRegister
- Object
- Job
- JobWithRegister
- Burner::Library::Collection::Coalesce
- Includes:
- Util::Keyable
- Defined in:
- lib/burner/library/collection/coalesce.rb
Overview
This is generally used right after the Group job has been executed on a separate dataset in a separate register. This job can match up specified values in its dataset with lookup values in another. If it finds a match then it will (shallow) copy over the values into the respective dataset.
Expected Payload input: array of objects. Payload output: array of objects.
Constant Summary
Constants inherited from JobWithRegister
Instance Attribute Summary collapse
-
#grouped_register ⇒ Object
readonly
Returns the value of attribute grouped_register.
-
#insensitive ⇒ Object
readonly
Returns the value of attribute insensitive.
-
#key_mappings ⇒ Object
readonly
Returns the value of attribute key_mappings.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
Attributes inherited from JobWithRegister
Attributes inherited from Job
Instance Method Summary collapse
-
#initialize(grouped_register:, insensitive: false, key_mappings: [], keys: [], name: '', register: DEFAULT_REGISTER, separator: '') ⇒ Coalesce
constructor
A new instance of Coalesce.
- #perform(output, payload) ⇒ Object
Methods included from Util::Keyable
Methods included from Util::Arrayable
Constructor Details
#initialize(grouped_register:, insensitive: false, key_mappings: [], keys: [], name: '', register: DEFAULT_REGISTER, separator: '') ⇒ Coalesce
Returns a new instance of Coalesce.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/burner/library/collection/coalesce.rb', line 29 def initialize( grouped_register:, insensitive: false, key_mappings: [], keys: [], name: '', register: DEFAULT_REGISTER, separator: '' ) super(name: name, register: register) @grouped_register = grouped_register.to_s @insensitive = insensitive || false @key_mappings = Modeling::KeyMapping.array(key_mappings) @keys = Array(keys) @resolver = Objectable.resolver(separator: separator.to_s) raise ArgumentError, 'at least one key is required' if @keys.empty? freeze end |
Instance Attribute Details
#grouped_register ⇒ Object (readonly)
Returns the value of attribute grouped_register.
23 24 25 |
# File 'lib/burner/library/collection/coalesce.rb', line 23 def grouped_register @grouped_register end |
#insensitive ⇒ Object (readonly)
Returns the value of attribute insensitive.
23 24 25 |
# File 'lib/burner/library/collection/coalesce.rb', line 23 def insensitive @insensitive end |
#key_mappings ⇒ Object (readonly)
Returns the value of attribute key_mappings.
23 24 25 |
# File 'lib/burner/library/collection/coalesce.rb', line 23 def key_mappings @key_mappings end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
23 24 25 |
# File 'lib/burner/library/collection/coalesce.rb', line 23 def keys @keys end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
23 24 25 |
# File 'lib/burner/library/collection/coalesce.rb', line 23 def resolver @resolver end |
Instance Method Details
#perform(output, payload) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/burner/library/collection/coalesce.rb', line 51 def perform(output, payload) ensure_array(payload) count = payload[register].length output.detail("Coalescing based on key(s): #{keys} for #{count} records(s)") payload[register].each do |record| key = make_key(record, keys, resolver, insensitive) lookup = find_lookup(payload, key) key_mappings.each do |key_mapping| value = resolver.get(lookup, key_mapping.from) resolver.set(record, key_mapping.to, value) end end end |