Adventures with Ruby
| emacs, rubyThis 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
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)
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!