Sunday, September 30, 2007

Ruby: First hack

Thursday night, last week, I released some static web pages. That’s nothing special, but the code that built them is, for me.

It’s me first ruby hack. It’s a flikr like doodad.

What it do?

It takes a cd of images (mainly bodybuilding), straight from the developers (I still use an analogue camera, just, but that’s another story). It crops, brands them and then builds a cluster of static web pages around them.

Using Image Magick, via rmagick, I manipulate the images. The images get rotate (if needed), cropped and branded. The data to do this is stored in a mysql data base. Each derived image is also tagged with data, so they can be captioned and grouped later. It is stored in three tables.

Next there is web page formatting. I used staticmatic for this. It based on HAML and SASS.

The formatting data is laid out as a node/leaf arrangement, also in the mysql database. Currently there is only one type of node. That is the root node type of page. All the leaf nodes types currently sit directly connected to the page node. The valid leaf types are navigation, photo grid and album. Currently there is no recursion up a node structure. That’s a future possibility.

That’s two tables, one for node and its one type, page. Not YAGNI (Your Aren’t Going to Need It), but then there is Agile Modelling. There are for leaf tables, Leaf and its three types. Six tables all up.

I’m sure you can guess what navigation and photo grid do.

Album is the complex stuff and the reason I wasted an automated process.

The album is a page cluster. On the page that has the album leaf, you get the results of the specific sports event. The event has divisions. Divisions have competitors, who appear in placing order. If a division or competitor has any photos with their tag, then it becomes a link to a generated page that contains a photo grid with all their tagged photos. The four tables that contain this data are event, division, competitor and place.

Now there is currently only one type of album. If I want an additional album structure for a different event thingy, I’ll refactor. The cluster generating methods would be moved into a command pattern that could be changed by Dependence Injection (DI). But YAGNI says that’s in some tomorrow.

What would I do differently, use rspec from the start.

Well that my first use of ruby in anger.


Gnoll110

Technorati tags:

No comments: