Class: Burner::Library::Collection::Unpivot
- Inherits:
-
JobWithRegister
- Object
- Job
- JobWithRegister
- Burner::Library::Collection::Unpivot
- Defined in:
- lib/burner/library/collection/unpivot.rb
Overview
Take an array of objects and un-pivot groups of keys into rows. Under the hood it uses HashMath’s Unpivot class: github.com/bluemarblepayroll/hash_math
Expected Payload input: array of objects. Payload output: An array of objects.
Constant Summary
Constants inherited from JobWithRegister
Instance Attribute Summary collapse
-
#unpivot ⇒ Object
readonly
Returns the value of attribute unpivot.
Attributes inherited from JobWithRegister
Attributes inherited from Job
Instance Method Summary collapse
-
#initialize(name: '', pivot_set: HashMath::Unpivot::PivotSet.new, register: DEFAULT_REGISTER) ⇒ Unpivot
constructor
A new instance of Unpivot.
- #perform(output, payload) ⇒ Object
Methods included from Util::Arrayable
Constructor Details
#initialize(name: '', pivot_set: HashMath::Unpivot::PivotSet.new, register: DEFAULT_REGISTER) ⇒ Unpivot
Returns a new instance of Unpivot.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/burner/library/collection/unpivot.rb', line 22 def initialize( name: '', pivot_set: HashMath::Unpivot::PivotSet.new, register: DEFAULT_REGISTER ) super(name: name, register: register) @unpivot = HashMath::Unpivot.new(pivot_set) freeze end |
Instance Attribute Details
#unpivot ⇒ Object (readonly)
Returns the value of attribute unpivot.
20 21 22 |
# File 'lib/burner/library/collection/unpivot.rb', line 20 def unpivot @unpivot end |
Instance Method Details
#perform(output, payload) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/burner/library/collection/unpivot.rb', line 34 def perform(output, payload) payload[register] = array(payload[register]) object_count = payload[register].length || 0 = "#{pivot_count} Pivots, Key(s): #{key_count} key(s), #{object_count} objects(s)" output.detail() payload[register] = payload[register].flat_map { |object| unpivot.(object) } end |