I'm using RubyMotion, ProMotion, and MotionModel for an iOS app. We'll be storing multiple date/time sensitive entries per day and listing them in a large TableView. Right now the entries appear in one large list:
What I'd like to do is have entries segmented by date for better readability:
I assume I can get this working by looping through my model entries once, extracting an array of all unique dates, then run through the date array and extract entries that match. This would work, but I can't help but think there might be a better way to tackle this with some Ruby magic that I'm not familiar with. Any suggestions are much appreciated!
In case someone reading this knows Ruby or RubyMotion but not familiar with ProMotion, the data format I need to return is in this format:
[{
title: "June 12, 2013",
cells: [{
title: "10:00am"
},{
title: "3:15pm"
},{
title: "7:00pm"
},{
title: "10:15pm"
}]
},{
title: "June 06, 2013",
cells: [{
title: "10:00am"
},{
title: "3:15pm"
},{
title: "7:00pm"
},{
title: "10:15pm"
}]
}]
EDIT:
The current code that generates table cells in reverse chronological order:
[{
cells: Entries.order{|one, two| two.entry_date <=> one.entry_date}.all.map{ |f|
{
title: Time.at(f.entry_date).strftime("%I:%M %p"), #"%m/%d/%Y"
action: :show_entry,
arguments:
{
entry: f
}
}
}
}]