A sweet Ruby measurement & converstion Library.
by Daniel Morrison, Collective Idea
Measurement is a library I wrote ages ago, in large part to play with metaprogramming.
But its cool. All of the measurements and conversions are in yaml files, stored in lib/measurements. This lets me have fun with SI prefixes and such. Ideally these files would be a separate project, to be used by other languages, but that’s for another day.
What can it do?
> include Measurement::Length
=> #<Measurement::Length::Centimeter:0x173c2b4 @units=30.48>
> include Measurement::Volume
=> #<Measurement::Volume::Teaspoon:0x1720e88 @units=45.0>
Check the yaml files to see what’s available, but note that SI prefixes (mega-, kilo-, yotta-, etc.) are applied magically, as are base2 prefixes for data.
Dunno, have ideas? Send me a message via github. I’m reviving the project after over a year, so its time to have some fun.
Some of my plans:
- More units (please add!)
- uh, tests.
- Namespaced units (Volume::Beer::Barrel vs. Volume::Oil::Barrel)
- Allow parents to be SI-derived (you can base a new unit on Meter, but not Kilometer)