x = [
{:head_count=>100, :group=>"NE", :estimated_ship_date=>"201103", :yard=>"wcc"},
{:head_count=>200, :group=>"NW", :estimated_ship_date=>"201104", :yard=>"wcc"},
{:head_count=>300, :group=>"NW", :estimated_ship_date=>"201105", :yard=>"wcc"},
{:head_count=>400, :group=>"NW", :estimated_ship_date=>"201105", :yard=>"wcc"},
{:head_count=>500, :group=>"NW", :estimated_ship_date=>"201104", :yard=>"nyssa"}]
p Hash[ x.group_by{ |i| i[:yard] }.map { |i,j|
[i, Hash[ j.group_by { |i| i[:group] }.map { |i,j|
[i, Hash[ j.group_by { |i| i[:estimated_ship_date] }.map{ |i,j|
[i, j.map{ |i| i[:head_count] }.inject(:+)]
} ] ]
} ] ]
} ]
{
"wcc"=>
{
"NE"=>
{
"201103"=>100
},
"NW"=>
{
"201104"=>200,
"201105"=>700
}
},
"nyssa"=>
{
"NW"=>
{
"201104"=>500
}
}
}