Hi, 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. Http://www.rubyplus.org Free Ruby & Rails screencasts On Mar 15, 2008, at 10:22 PM, Wladimir Mutel <mwg-N70cOR3MGi/3fQ9qLvQP4Q@public.gmane.org> wrote:> > Hi, > > 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. > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 16 Бер, 07:54, Bcp <bcpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---