From: "Nik Z." Date: 2009-12-03T12:00:32+09:00 Subject: Re: Help with complex array transformation --0015174c0f024cba9c0479ca31eb Content-Type: text/plain; charset=ISO-8859-1 Hi, Bruno, I'm not too sure if I fully understood you, but this shouldn't be too difficult in constructing the data structure, but quite of bit mind-blogging for sure... Just make an array of hashes of arrays...a room array, such as arrRoom = [ "0", {"person"=>[day1, day2,...], # this is for room1, arrRoom[1] { #ditto for room2, arrRoom[2] } ] Then based on the return value of your "view" method, you can do this: # 1 view_method(day1).each do |person, room| arrRoom[room]["person"]< wrote: > Hi > > I have a following method > > view(all_people, begin_date, end_date) > > That's give me an array like this: > > # for a first day (day 1) > view("*", '2009-12-01 00:00:00', '2009-12-01 24:59:59') > > [[name_person1, room1], [name_person2, room2], [name_person3, room2]] > > # for a second day (day 2) > view("*", '2009-12-02 00:00:00', '2009-12-02 24:59:59') > > [[name_person1, room1], [name_person3, room1], [name_person2, room2]] > > > And I need to organize theses arrays in a following structure: > > [{room1 => [{day1 => [name_person1]}, > {day2 => [name_person1, name_person3]}] > }, > {room2 => [{day1 => [name_person2, name_person3]}, > {day2 => [name_person2]}] > }] > > > And finally put this array in a cvs strings > > room1; day1; name_person1 > room1; day2; name_person1 > room1; day2; name_person3 > > room2; day1; name_person2 > room2; day1; name_person3 > room2; day2; name_person2 > > I tried some scripts for hours but I didn't do this job! > Too complicated for my. > > Someone can help me if this? > > Thanks so much! > -- > Posted via http://www.ruby-forum.com/. > > --0015174c0f024cba9c0479ca31eb--