From: Nuby Ruby Date: 2007-08-30T16:56:28+09:00 Subject: Re: Help parsing simple structured data. ------=_Part_4927_13952923.1188460586500 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Oh man this is awesome. I love ruby, I spent the last hour playing with ruport, and am in love with it's simplicity.. The reason I'm learning Ruby is to make it easier for me to get off my butt and write reports. On 8/29/07, Pe=F1a, Botp wrote: > > From: Nuby Ruby [mailto:nubyruby@gmail.com] > # of processing is the bit of code I use most in my daily life, and the > # hardest for me to wrap my head around when I play with new langauges. > > you sound like an admin or you do admin tasks daily. > > just want to tell you that there's a gem called ruport used for reporting > task. ..just in case it may help you. > > this is just a simple example. i snipped the initial echos fr irb. the > last outputs will give you an idea... > > so, > > >require 'rubygems' > >require 'ruport' > > >data =3D`df -h`.split "\n" > >header=3Ddata.shift.split " ",6 > >data =3D data.map{|line| line.split} > >report =3D Ruport::Data::Table.new :data =3D> data, :column_names =3D> h= eader > > >puts report > > +------------------------------------------------------------------------= -------+ > | Filesystem | Size | Used | Avail | Use% | Mounted > on | > > +------------------------------------------------------------------------= -------+ > | /dev/hda1 | 3.8G | 3.1G | 566M | 85% | > / | > | varrun | 125M | 68K | 125M | 1% | > /var/run | > | varlock | 125M | 4.0K | 125M | 1% | > /var/lock | > | udev | 125M | 76K | 125M | 1% | > /dev | > | devshm | 125M | 0 | 125M | 0% | > /dev/shm | > | lrm | 125M | 18M | 107M | 15% | > /lib/modules/2.6.15-28-686/volatile | > | /dev/hdb1 | 19G | 6.9G | 13G | 36% | > /disk2 | > | /dev/hdd1 | 2.0G | 731M | 1.3G | 37% | > /disk3-1 | > | /dev/hdd2 | 2.1G | 65M | 1.9G | 4% | > /disk3-2 | > > +------------------------------------------------------------------------= -------+ > =3D> nil > > > puts report.column("Filesystem") > /dev/hda1 > varrun > varlock > udev > devshm > lrm > /dev/hdb1 > /dev/hdd1 > /dev/hdd2 > =3D> nil > > > puts report.column("Size") > 3.8G > 125M > 125M > 125M > 125M > 125M > 19G > 2.0G > 2.1G > =3D> nil > > there are a lot of fxns in ruport that allow you to sum on columns, swap > them, remove/add columns, drill down on records, etc... > > many thanks to GBrown and MMilner, et al for ruport. > kind regards -botp > > ------=_Part_4927_13952923.1188460586500--