README.md in hash_pivot-0.2.0 vs README.md in hash_pivot-0.3.0

- old
+ new

@@ -20,10 +20,17 @@ #### Prepare data Prepare Array of Hash. +id | role | team | age +-- | -- | -- | -- +1 | guest | rabbit | 1 +2 | guest | mouse | 2 +3 | guest | rabbit | 3 +4 | admin | mouse | 4 + ```ruby data = [ { id: 1, role: 'guest', team: 'rabbit', age: 1 }, { id: 2, role: 'guest', team: 'mouse', age: 2 }, { id: 3, role: 'guest', team: 'rabbit', age: 3 }, @@ -42,10 +49,15 @@ # "rabbit" => [{ :id => 1, :role => "guest", :team => "rabbit", :age => 1 }, { :id => 3, :role => "guest", :team => "rabbit", :age => 3 }], # "mouse" => [{ :id => 2, :role => "guest", :team => "mouse", :age => 2 }] }, # { :role => "admin", "rabbit" => [], "mouse" => [{ :id => 4, :role => "admin", :team => "mouse", :age => 4 }] }] ``` +role | rabbit | mouse +-- | -- | -- +guest | {1 guest rabbit 1} {3 guest rabbit 3} | {2 guest mouse 2} +admin |   | {4 admin mouse 4} + Grouping by `:role` and pivot in `:team`. Pivot column is nil. This means that pivot column is automatically configured. ```ruby @@ -67,9 +79,33 @@ HashPivot.pivot(data, :role, :team, %w[rabbit mouse]) { |array| array.sum { |h| h[:age] } } # [{ :role => "guest", "rabbit" => 4, "mouse" => 2 }, { :role => "admin", "rabbit" => 0, "mouse" => 4 }] ``` +role | rabbit | mouse +-- | -- | -- +guest | 4 | 2 +admin | 0 | 4 + +#### Pivot with summarize and replacing label. + +If you give Hash for pivot kinds like this, pivot data is summarized by block and replace with labels. + +```ruby +pivot_kinds = { 'rabbit' => 'RABBIT AGE', + 'mouse' => 'MOUSE AGE' } +``` + +```ruby +HashPivot.pivot(data, :role, :team, pivot_kinds) { |array| array.sum { |h| h[:age] } } + +# [{ :role => "guest", "RABBIT AGE" => 4, "MOUSE AGE" => 2 }, { :role => "admin", "RABBIT AGE" => 0, "MOUSE AGE" => 4 }] +``` + +role | RABBIT AGE | MOUSE AGE +-- | -- | -- +guest | 4 | 2 +admin | 0 | 4 ### Pivot Array of Struct #### Prepare data