Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Backwards references in arrays of arrays of...

Reply
Thread Tools

Backwards references in arrays of arrays of...

 
 
Ohad Lutzky
Guest
Posts: n/a
 
      10-14-2006
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
file
(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
file
etc. (no infinite recursion). To get a feel for what I mean, try

LinkBack = Struct.new(:link)
=> LinkBack
l = LinkBack.new
=> #<struct LinkBack link=nil>
l.link = 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 http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Snake references just as ok as Monty Python jokes/references in python community? :) seberino@spawar.navy.mil Python 8 12-12-2006 11:21 PM
Typedef A references struct B which references struct A which... DanielEKFA C++ 8 05-16-2005 10:26 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
how to understand references to variables and references to constants are distinguished? baumann.Pan@gmail.com C++ 3 11-10-2004 04:16 AM
Pointers and References (and References to Pointers) Roger Leigh C++ 8 11-17-2003 10:14 AM



Advertisments