Home > ActsAsMetrical

ActsAsMetrical

ActsAsMetrical is a project mainly written in Ruby, based on the MIT license.

Lets you define attributes that represent metric values.

ActsAsMetrical

Lets you define attributes that represent metric values. Those attributes will get a range of getters and setters which do the metric conversion for you. This enables you to store the values always in your preferred unit but easily lets you read and write in any unit (mm, cm, m, km).

Example

Let’s say your class Travel has an attribute distance which stores the distance in your database. Your preferred unit might be m.

Specify the attribute in your model:

acts_as_metrical =>

acts_as_metrical :distance => :m

This will generate the following methods:

distance_in_mm, distance_in_mm= distance_in_cm, distance_in_cm= distance_in_m, distance_in_m= distance_in_km, distance_in_km=

If your Travel object stores 1000 in distance in your database and you need to get the value in km, just call distance_in_km and you get 1.

Copyright (c) 2010 [niklas-], released under the MIT license

Previous:ouf_nev