Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Conversion methods for Numeric. Dimension units like weight, distance, mass, and time conveniently for all measures like pounds, grams, and meters, or convert one unit to another. Also includes a natural language parser.

License

farski/systeme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Systeme - Dimensional declaration and conversion

Now with more drachm!

Systeme provides an extensive but intuitive library of convenience methods for handling and passing around numeric data that represents dimensioned units (such as length, mass, and volume). Besides trimming down your code and making it more readable, it simplifies the task of storing data such that all values are stored in their standard SI base unit (meter, kilogram, etc).

Usage

Declarations

Declaration methods are the basis for utilizing systeme. Whenever a Numeric is declared with a systeme method, it will return an equivalent value in the SI standard base unit. These methods can be taken advantage of in several ways:

height_of_eiffel_tower = 325.meters => 325 # 325 already represents the SI standard unit meter, so this just helps you read your code more easily

10.kilometers => 10000 # as in, 10 kilometers equals 10000 meters # This allows you to quickly convert a number to it’s equivalent base unit for storage 120.miles + 14.furlongs + 191.megameters => 191195937.632 # this value is in meters # Declarations also make otherwise annoying calculations a snap Systeme supports the five SI base units (meter, kilogram, ampere, second, kelvin) and all prefixed derivatives (pico-, nano-, kilo-, terra-, giga-, etc). Declarations can be made using any of a number of methods provided by these units.

10.meter == 10.meters == 10.m 10.kilogram == 10.kilograms == 10.kg A growing number of U.S, Imperial, deprecated, and other non international standard units are also supported.

10.pounds == 10.pound = 10.lb == 10.lbs == 10.lbm 10.inches == 10.inch == 10.in 10.foot == 10.feet == 10.foots == 10.ft

Conversions

Conversions allow you to display or pass data in a unit other than the SI base. The set of methods for conversions is identical to declarations, but with each one prefixed by ‘in_’. By declaring the numeric before converting it, any unit can be converted to any other unit. Non-declared numerics will be presumed to already be in their SI base unit

1000.meters.in_kilometer => 1 16.oz.in_lb => 1 5280.in_miles => 3.28083989501312 # 5280 was presumed to be in meters, if you were looking for a result of 1 you should do 5280.feet.in_miles

Advanced Usage

One useful application of systeme is to take human readable input to produce usable and storable data

# How far did you walk today? input = “6.25mi” distance = input.to_f unit = ((unit_data = input.match(/(+)/)) ? unit_data : “m” ) si_distance = distance.send(unit) => 10058.4

Parsing

The parse method provides very lax natural language parsing of dimensioned numbers in strings. It works much as one would expect, but two things to note: it will simply ignore any numbers associated with labels it doesn’t understand, and it doesn’t care if all the numbers in the string are of the same dimensionality. A string like “1 meter 1 centimeter” 1.01 and the string “1 meter 1 kilogram” will return 2.0. The same unit label can appear many times in a single string (“1m 1m 1m” => 3.0). If the parser finds a number with no label, it is technically being dimensioned as ‘meter’, which has no effect on the value.

Installation

As a gem

The official distributions of this gem are available on RubyForge under the project name systeme

this will be available soon

$ gem install systeme Development can be followed on GitHub at www.github.com/farski/systeme

$ gem install farski-systeme

Credits

Systeme is maintained by Chris Kalafarski

License

Systeme is Copyright © 2008 Christopher P Kalafarski. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Conversion methods for Numeric. Dimension units like weight, distance, mass, and time conveniently for all measures like pounds, grams, and meters, or convert one unit to another. Also includes a natural language parser.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages