Serialize typed id arrays - howto ?


Here is a part of type system in my Rails app :

daytime : just an integer >= 0 and < 86400
dayinterval : a pair of daytimes, where first one is less than last
dayschedule : zero or more (non-intersecting) dayintervals
weekschedule : seven dayschedules.

DayInterval, DaySchedule and WeekSchedule are also models to be stored
in the database. To save on association(join) tables, DaySchedule has
text column "intervals" where a serialized array of DayInterval ids is
stored, and WeekSchedule has text column "days" to store a serialized
array of DaySchedule ids.

And so, my question is, how to leverage Rails facilities to express
these relations in short way ? I.e., I would like .intervals method to
return me not just Array of integers, but make it know that these
integers are references to DayInterval ids and so [], << and []= have
to convert these ids to DayIntervals and vs-vrs. Currently I have had
to write this logic by hand, and so far it looks quite repetitive.
Should I dive into heavy metaprogramming to factor out the common
parts, or Rails (v2) could offer something ready-made to help me with
my problem ?

Thank you in advance for your reply.

These classes seem to be specific to ur app. My question is why do u
need so many classes? Do they have any behaviour? I don't think rails
2 has anything to help u. Check the active support library source
code. If u only have data & conversion methods u can open up the time
classes and add ur methods to it.

Free Ruby & Rails screencasts

This all is to represent weekly schedule templates. First the user
enters dayintervals from the web form (hh:mm..hh:mm), then he/she
composes daily schedules out of dayintervals, then weekly schedules
out of daily ones. Then these created structures are used as schedule
templates to generate schedules for further days and weeks. In fact,
the whole structure is just a multilevel list of integer pairs, but
all its parts have to be stored in DB and edited by the user. That's
why I decided to do so.

Like this :

one type of business day is 9:00 to 17:00 (5:00pm)
another type is 9:00 to 13:00 and 14:00 to 18:00
weekend work is 10:00 to 16:00
dayoff is empty set - no interval at all.

one week schedule is Mon..Fri 9:00..17:00 and Sat 10:00..16:00
another week schedule Mon..Fri 9..13+14..18 and Sat 10..16
(both with dayoff on Sunday)

then each worker is given his own weekly schedule template which is
used to generate/fill his further schedules. Then given workload is
fit to these schedules, performed and reported.

Earlier my application had schedule generation hand-coded in its
logic, but the customer asked to have different schedules for
different workers.