Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A small framework to simplify math operations on quantities.
branch: master

This branch is even with aportnov:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
doc/api
lib
test
.gitignore
.project
LICENSE
README.rdoc
Rakefile
quantity.gemspec

README.rdoc

Quantity Framework

This is a simple framework allowing one to perform basic quantity math and conversions.

Basic usage:

calc = Quantity::calc
qty = calc.quantity(45, :cm)
mm = calc.exp(:mm) {qty}
cm = calc.exp(:cm){2.m - 20.cm}
m = calc.exp(:m) {25.cm + 15.8.mm + 10.m}

Something a bit more interesting:

calc.exp(1.L / 1.km) {33.mi / 1.gal}.value

More

Look at lib/config/default.rb for full list of conversions and units supported by default. You can also add new units and new conversions to “global” config via Quantity::configure :

Quantity::configure do |config|
 config.unit :unit => :new_unit
 .....
end

or do the same on a given calculator level:

calc.add_unit :unit => :new_unit
Something went wrong with that request. Please try again.