Daniel Morrison

measurement: The Voodoo Library

So over a year ago I wanted a Ruby library that could do measurement conversions. Inches to centimeters, gallons to cups, anything. I got a bit carried away and abstracted all the units into yaml files, while going on a metaprogramming binge in the 179-line library.

I never released it, and don’t entirely remember why I wanted it in the first place, but Brandon asked me about it today, so I pulled it up, it worked, and I pushed it to GitHub.

It works pretty well, and I have a decent set of units:

> include Measurement::Length
> Inch.new(12).to_centimeters
=> #<Measurement::Length::Centimeter:0×173c2b4 @units=30.48>
>
> include Measurement::Volume
> Milliliter.new(100).to_teaspoons
=> #<Measurement::Volume::Teaspoon:0×1720e88 @units=45.0>

All the units (with conversions and abbreviations) are in yaml files:

Meter:
abbreviation: m
prefix: si
Foot:
abbreviation: ft
to_base: 0.3048
Inch:
abbreviation: in
parent: Foot
to_parent: 1.0/12.0

And I’m having way too much fun with prefixes (mega-, centi-, etc.) in their own files:

mega:
prefix: M
base: 10
exponent: 6
kilo:
prefix: k
base: 10
exponent: 3

centi:
prefix: c
base: 10
exponent: -2

I’m not really sure how this whole thing works anymore, but I’m having fun looking at it again. Tell me what to add, or fork it yourself and let’s measure. In the meantime, ponder why beer, wine and oil barrels are all different measurements (36, 31, 42 gallons, respectively).

4 Comments

  1. Charles Waldman — December 18, 2008

    Why not use the database file from the Unix “units” program?
    It has over 2000 units already defined, and its freely available – why reinvent this?

  2. Georges — February 17, 2009

    I must admit that it would be interesting to use the GNU units database and apply it to your plugins. I’ll have a look at that for training …

  3. satelliteko — February 22, 2009

    Very cool project. Ill clone it now from Github!

    Thanks

  4. Emerald queen casino — October 26, 2012

    axeouebojfm, Blackjack, UfDHNiN, [url=http://act1dancestudio.com/]Blackjack[/url], pnyChbo, http://act1dancestudio.com/ Blackjack knives, FnEUEJp, Casino, rcuIpJv, [url=http://themodularconnection.com/]Casino[/url], LwrKyUH, http://themodularconnection.com/ City casino, coloumc, Where to buy viagra online, aOicDJQ, [url=http://affordable-rx.com/]Viagra jokes[/url], WojfwEF, http://affordable-rx.com/ Viagra, unirnQJ, Slots, dBXBBNC, [url=http://casino-slots-guide.com/]Slots vote results anne arundel[/url], gsFInZF, http://casino-slots-guide.com/ Vegas loose slots, mUyokLr, Casino betting, MFVWChJ, [url=http://tomjohndance.com/]Casino[/url], rHwwkNq, http://tomjohndance.com/ Casino, wykHyvE, Wordpress casino en ligne, JeVuAwg, [url=http://intercasinoeuro.fr/]Casino en Ligne[/url], qvKmneT, http://intercasinoeuro.fr/ Casino en Ligne, SfqpPXi.

Make a Comment