joshwlewis / unitwise

Physical quantity and units of measure conversion and math for Ruby
unitwise.org
MIT License
281 stars 32 forks source link

Can't normalise to SI units or handle common units #16

Open ahacking opened 10 years ago

ahacking commented 10 years ago

There does not seem to be an obvious way to normalise units to their SI counterpart.

I was expecting if I did Unitwise(3, 'foot') I would be able to do a to_si without having to know the dimension type a-priori. I was wanting to use this library for units handling and normalise all units regardless if they be length, mass, area, volume, etc before storing in DB but it seems not possible the way things are currently structured.

Also I noticed Unitwise(3, 'ft') on closer inspection seems to return mass, not length, making use of this library for common use cases rather impractical.

joshwlewis commented 10 years ago

As to the first, yes, you have to be explicit. Unitwise(3, 'foot').to_meter would probably be what you want. Unitwise doesn't have preferred unit mappings, though this is probably a reasonable feature.

Unitwise(3, 'ft') does indeed return a 'femtotonne'. However, this is a valid SI unit and 'ft' is it's official abbreviation. Unitwise implements the UCUM standard, so that is appropriate -- to create a foot unit, you can either use 'foot' or '[ft_i]' to describe a foot unit.

ahacking commented 10 years ago

Thanks, after my brief reading of UCUM I came to the conclusion it was a well intentioned but ultimately useless "standard" for common use cases since your average joe isn't going to use those conventions to describe a common length measurement like feet and inches.

I guess it works really well for the tiniest minority in the world who deal with femto scale mass units.

joshwlewis commented 10 years ago

I agree, UCUM (and by extension Unitwise) is built to encompass a huge scope of units. That is obviously useful for say fluid dynamics and heat transfer. There are probably some things I can do to make it more useful for simpler use cases (like perhaps only loading more common units by default).

In any case, thank you for your feedback. I've got some things to ponder.