Project

m9t

0.01
No commit activity in last 3 years
No release in over 3 years
Classes for handling basic measurement units: distance, direction, speed, temperature and pressure
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0.3.5
>= 0
 Project Readme

Build Status Source Analysis Test Coverage

m9t

Measurements and coversions library for Ruby

This package handles the basic units of measure:

  • distance,
  • direction,
  • speed,
  • temperature,
  • weight.

The emphasis is on:

  • coherent interface,
  • ease of translation (using i18n).

Internals

Internally, values are stored in SI units, with the exception of temperature:

  • distance - meters,
  • direction - degrees,
  • speed - meters per second,
  • temperature - degrees celcius,
  • weight - kilograms.

Interface

new: accepts the S.I. unit as a parameter:

height = M9t::Distance.new(1.75)

to_f: returns the decimal value(s):

height.to_f -> 1.75

other units: there are class methods named after each known unit, which take values in that unit (actually, they are defined as needed):

marathon = M9t::Distance.miles(26.21875)
marathon.to_f -> 42194.988

to_s: returns a localized string with units:

I18n.locale = :it
puts M9t::Distance.new(3).to_s -> '3 metri'

Class methods for conversion

Methods are available for conversion between any pair of units:

M9t::Distance.miles_to_meters(26.21875) -> 42194.988

Alternatives

  • ruby-units
    • Doesn't handle i18n:
      • The library depends heavily on English string representations of units.
    • Monkey patches a lot of core classes:
      • Adds methods to e.g. Object.

Contributors

License

Dual license:

  • MIT License: see MIT-LICENSE.txt,
  • GPL version 3: see GPL-LICENSE.txt