Class: HashMath::Unpivot::PivotSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hash_math/unpivot/pivot_set.rb

Overview

A set of pivots for an Unpivot class to perform.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pivots: []) ⇒ PivotSet

Returns a new instance of PivotSet.



23
24
25
# File 'lib/hash_math/unpivot/pivot_set.rb', line 23

def initialize(pivots: [])
  @pivots = Pivot.array(pivots)
end

Instance Attribute Details

#pivotsObject (readonly)

Returns the value of attribute pivots.



19
20
21
# File 'lib/hash_math/unpivot/pivot_set.rb', line 19

def pivots
  @pivots
end

Instance Method Details

#add(pivot) ⇒ Object

Adds another Pivot configuration object to this objects list of pivots. Returns self.



29
30
31
# File 'lib/hash_math/unpivot/pivot_set.rb', line 29

def add(pivot)
  tap { pivots << Pivot.make(pivot) }
end

#expand(hash) ⇒ Object

An aggregation of Pivot#expand. This method will iterate over all pivots and expand them all out.



35
36
37
38
39
# File 'lib/hash_math/unpivot/pivot_set.rb', line 35

def expand(hash) # :nodoc:
  base_hash = make_base_hash(hash)

  pivots.map { |pivot| pivot.expand(base_hash, hash) }
end