Class: HashPivot::Table
- Inherits:
-
Object
- Object
- HashPivot::Table
- Defined in:
- lib/hash_pivot/table.rb
Instance Method Summary collapse
-
#initialize(data, repository: HashPivot::Repository::HashRepository) ⇒ Table
constructor
A new instance of Table.
- #pivot(group, pivot_in, pivot_kinds, &block) ⇒ Array<Hash>
Constructor Details
#initialize(data, repository: HashPivot::Repository::HashRepository) ⇒ Table
Returns a new instance of Table.
13 14 15 16 |
# File 'lib/hash_pivot/table.rb', line 13 def initialize(data, repository: HashPivot::Repository::HashRepository) @data = data @repository = repository end |
Instance Method Details
#pivot(group, pivot_in, pivot_kinds, &block) ⇒ Array<Hash>
25 26 27 28 29 30 31 32 |
# File 'lib/hash_pivot/table.rb', line 25 def pivot(group, pivot_in, pivot_kinds, &block) group = [group] unless group.is_a?(Array) @repository.hash_by_group(@data, group, pivot_in).each_with_object([]) do |(key, array), memo| hash = transpose_with(pivot_kinds, array, pivot_in, &block) memo << key.merge(hash) end end |