I'm creating a scheduling application for my university, the Technion.
The course data we receive in a file called a REP file, which my
application parses. Its essential, simplified structure is this:
Faculties (which have names) contain courses
Courses (which have numbers and names) contain groups
Groups (which have numbers and lecturer names) contain events
Events have days, start/end times, and locations
This data I convert once (it takes a while), and then Marshal it. I
don't use YAML, though I'd rather do that, because of a unicode bug in
the stable version. The choice between them is less relevant.
So in my program, the data is stored as an array of Faculty objects,
which have a courses property which is an array of Course objects, and
so on - all the way down to events.
Now, I display the rendered schedule using Gecko. I have prepared an
HTML template for this, for which all I have to add is event lines in
addEvent(course_id, day, start, end, desc);
This code is then inserted into the HTML, which goes about the
rendering. course_id should be a unique identifier for color-coding.
desc, which is the actual rendered text, should contain the event's
course name & number, group number, lecturer, and location.
Now here's the kicker - an event doesn't know all that. It knows its
day, start/end time, and location. And that it's an event. It doesn't
know what group it's a part of, what course, nothing.
Currently, the scheduler returns an array of arrays of groups (an array
of groups per course). So my options are
groups belong to which courses, iterate down to the choices, and
(I don't like this because if I use YAML later on, I'd like it to be
redistributable instead of the REP file, and that's, well, icky)
- Store back-references to the group and course within the event - ruby
seems to handle this gracefully, with appropriate links in the YAML
etc. (no infinite recursion). To get a feel for what I mean, try
LinkBack = Struct.new(:link)
l = LinkBack.new
=> #<struct LinkBack link=nil>
l.link = l
=> #<struct LinkBack link=#<struct LinkBack:...>>
--- &id001 !ruby/struct:LinkBack
from within the Event.
- ...or something else I haven't thought of. What do you guys think?
Posted via http://www.ruby-forum.com/.