I had to send daily course update notification to the user. Update notification contain four types of [:due,:missed,:over_due,:new]
. To make it easy I omitted unnecessary field from data like due and missed coz it the same as overdue and new format. Below-provided data belonged a user. A user can be part of many courses that is why 2 different course_id there in the hash (course_id 20 and 30). The id represents here assignment_id in a particular course.
The actual format of data are.
{
1 => { #the 1st user
:new => {
1 => {
:id => 1,
:course_id =>20,
:course_name => "B"
},
2 => {
:id => 2,
:course_id =>30,
:course_name => "A"
},
3 => {
:id => 3,
:course_id =>20,
:course_name => "B"
}
}
:over_due => {}, #This is also having the same format as new
:missed => {}, #This is also having the same format as new
:due => {} #This is also having the same format as new
},
2 => { #this is 2nd user
:new => {},
:over_due => {},
:missed => {},
:due => {}
}
}
Suppose, This is just a dummy data I had created for a user for more clarity and explanation.
assignments = {
:new => {
1 => {
:id => 1,
:course_id => 20,
:name => "A"
},
2 => {
:id => 2,
:course_id => 20,
:name=>"A"
},
3 => {
:id => 3,
:course_id => 30,
:name=>"B"
}
},
:over_due => {
4 => {
:id => 4,
:course_id => 20,
:name => "A"
},
5 => {
:id => 5,
:course_id => 30,
:name => "B"
}
}
}
My requirement to parse data into this format:
{
20 => {
:new => {
1 => {
:id => 1,
:course_id => 20,
:name=>"A"
},
2 => {
:id => 2,
:course_id => 20,
:name => "B"
}
},
:over_due => {
4 => {
:id => 4,
:course_id => 20,
:name => "E"
}
}
},
30 => {
:new => {
3 => {
:id => 3,
:course_id => 30,
:name => "C"
}
},
:over_due => {
5 => {
:id => 5,
:course_id => 30,
:name=>"F"
}
}
}
}