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).

13 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.

  5. lizee — June 19, 2023

    Making the library available on GitHub allows others to access, use, and potentially contribute to its development. It’s not uncommon for personal wordle unlimited projects or experiments to evolve into something valuable for others in the developer community. By sharing it, you provide an opportunity for others to benefit from your work and contribute their own insights and improvements.

  6. lizee — June 19, 2023

    Making the library available on GitHub allows others to access, use, and potentially contribute to its development. It’s not uncommon for personal wordle unlimited projects or experiments to evolve into something valuable for others in the developer community. By sharing it, you provide an opportunity for others to benefit from your work and contribute their own insights and improvements.

  7. Jenny — July 05, 2023

    The library is designed to be flexible and extensible. It utilizes YAML files to abstract the units of measurement, allowing for easy shell shockers customization and addition of new units. The codebase makes use of metaprogramming techniques, resulting in a concise library consisting of 179 lines of code.

  8. x trench run — July 11, 2023

    This is an amazing and informative article that covers so much ground.

  9. rosy dam — July 17, 2023

    Pokemon Fusion is a captivating and innovative concept that takes the beloved creatures from the Pokemon universe and reimagines them in a whole new light. It is an artistic endeavor that fuses the traits and characteristics of different Pokemon to create imaginative and unique hybrids that transcend the boundaries of traditional evolution.

  10. Emma Brown — July 20, 2023

    good

  11. Emma — July 20, 2023

    I am really impressed with your article. The information you share will be an important document for me to learn more about this topic. mapquest directions

  12. Madeline — August 04, 2023

    This site has been bookmarked, and I will return to read new posts. Quordle, have you ever played this well-known game?

  13. hazel — August 31, 2023

    Discover the ultimate Unblocked Games Premium selection! Explore a variety of unblocked games for endless entertainment. Find your favorites and start playing now. Click to explore!
    https://sites.google.com/codees.cc/unblocked-games/home