Adventures with Ruby

| emacs, ruby

This is my second day of Ruby, a programming language that is rather
popular in Japan. I’m in love. It’s now my second-favorite programming
language. (Emacs Lisp is, of course, the first.)

Yesterday’s script parsed schedule data and checked that monthly cost
and day constraints were observed. Today I wanted to visualize the verified schedule.

At first I tried working with planner (formerly known as
MrProject and not to be confused with PlannerMode). I wrote a Ruby program that converted my schedule.csv into XML, and planner loaded it successfully. However, I didn’t think planner would let me do funky color coding. I thought about using etask, but ended up deciding to write something using libgd-ruby.

It was surprisingly easy to write a Gantt-like visualizer for the schedule
and even easier to manipulate it once I had written it. For example, I could do silly things like

s.to_image((s.schedule.sort { |a,b| a.start <=> b.start }, 0, 2500, 1800, image)

Sorted by start date

to see the tasks sorted by start date. Being a Lisp girl, I had no problems writing silly things like

s.to_image((s.schedule.collect { |x| x if x.person_id == ’08-1′ } – [ nil ]).sort { |a,b| a.start <=> b.start }, 0, 2500, 1800, image)

but then I realized that this was much cleaner:

s.to_image((s.schedule.sort { |a,b| x = a.person_id <=> b.person_id; if x == 0 then a.start <=> b.start else x end }, 0, 2500, 1800, image)

Sorted by person and then start date

Ruby is so cute!

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.