Backwards references in arrays of arrays of...

Discussion in 'Ruby' started by Ohad Lutzky, Oct 14, 2006.

  1. Ohad Lutzky

    Ohad Lutzky Guest

    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
    Javascript, which go something like this:

    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.

    So the question is - how do I generate the javascript?

    Currently, the scheduler returns an array of arrays of groups (an array
    of groups per course). So my options are

    - Have the scheduler generate the javascript - let it figure out which
    groups belong to which courses, iterate down to the choices, and
    generate everything
    - Store javascript strings within the events during parsing of the REP
    (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 =
    => LinkBack
    l =
    => #<struct LinkBack link=nil> = l
    => #<struct LinkBack link=#<struct LinkBack:...>>
    y l
    --- &id001 !ruby/struct:LinkBack
    link: *id001
    => nil

    Once these are in, it's pretty simple to generate the javascript code
    from within the Event.
    - ...or something else I haven't thought of. What do you guys think?

    Posted via
    Ohad Lutzky, Oct 14, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger Leigh
    Karl Heinz Buchegger
    Nov 17, 2003
  2. Replies:
    Victor Bazarov
    Nov 10, 2004
  3. DanielEKFA
    May 16, 2005
  4. Replies:
    Bruno Desthuilliers
    Dec 12, 2006
  5. Lars Willich
    Ian Shef
    Oct 23, 2007

Share This Page