Shaku is a little gem that handle Measurement calculation and conversion. It is still in its early development phase so the current project is just a boiler plate.
Add this line to your application's Gemfile:
gem 'shaku'
And then execute:
$ bundle
Or install it yourself as:
$ gem install shaku
a = Shaku::Measure.new(10, 'cm') # => (10.0 cm)
b = Shaku::Measure.new(3, 'cm') # => (3.0 cm)
a + b # => (15.0 cm)
a - b # => (7.0 cm)
a * 2 # => (20.0 cm)
a / 2 # => (5.0 cm)
Currently Shaku does not provides any conversion feature. All examples below will raise an exception even some are meaningful.
a = Shaku::Measure.new(10, 'cm')
b = Shaku::Measure.new(10, 'km')
a + 3.0 # => TypeError: Cannot convert Float to Measure
a + b # ArgumentError: Inconsistent unit
Multiply and divide are not commutative. Hence the example below have no meaning.
a = Shaku::Measure.new(10, 'cm')
2 * a # => TypeError: Shaku::Measure can't be coerced into Fixnum
2 / a # => TypeError: Shaku::Measure can't be coerced into Fixnum
In interactive you can save some keystrocks by extending the main object with Shaku
module
extend Shaku
# => main
a = Measure(3, 'cm')
# => (3.0 cm)
After checking out the repo, run bin/setup
to install dependencies. Then, run rake rspec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
- More exhaustive measure arithmetics
- Unit conversion
- SI unit database
- Unit arithmetics
Bug reports and pull requests are welcome on GitHub at https://github.com/mhammiche/shaku. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.