class Burner::Library::Collection::Unpivot

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.

Attributes

unpivot[R]

Public Class Methods

new( name: '', pivot_set: HashMath::Unpivot::PivotSet.new, register: DEFAULT_REGISTER ) click to toggle source
Calls superclass method Burner::JobWithRegister::new
# 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

Public Instance Methods

perform(output, payload) click to toggle source
# File lib/burner/library/collection/unpivot.rb, line 34
def perform(output, payload)
  payload[register] = array(payload[register])
  object_count      = payload[register].length || 0

  message = "#{pivot_count} Pivots, Key(s): #{key_count} key(s), #{object_count} objects(s)"

  output.detail(message)

  payload[register] = payload[register].flat_map { |object| unpivot.expand(object) }
end

Private Instance Methods

key_count() click to toggle source
# File lib/burner/library/collection/unpivot.rb, line 51
def key_count
  unpivot.pivot_set.pivots.map { |p| p.keys.length }.sum
end
pivot_count() click to toggle source
# File lib/burner/library/collection/unpivot.rb, line 47
def pivot_count
  unpivot.pivot_set.pivots.length
end