have array of hashes it looks like
arr = [
{"partner_name"=>"Bell", "publisher_name"=>"News - Calgary", "mn"=>"", "mid"=>415},
{"partner_name"=>"Bell", "publisher_name"=>"News - Vancouver Island", "mn"=>"Module 2.0 ", "mid"=>4528},
{"partner_name"=>"Bell", "publisher_name"=>"News - Atlantic", "mn"=>"Module 2.0 ", "mid"=>4531},
{"partner_name"=>"Bell", "publisher_name"=>"News - Kitchener", "mn"=>"Module 2.0 ", "mid"=>4535},
{"partner_name"=>"Bell", "publisher_name"=>"News - London", "mn"=>"Module 2.0 ", "mid"=>4536},
]
i have tried to do arr.group_by{|el|el['partner_name']}
i want to achieve this result
{
partner:'Bell',
publishers: [
{name:'News - Vancouver Island'},
modules:[
{mn: val, mid: id_val},
# ...
{name:'News - Vancouver Island'
modules:[
{mn: val, mid: id_val},
# ...
],},
# ... and others
],
}
How can i do it?
Aucun commentaire:
Enregistrer un commentaire