It's dead simple Value object, which provides convenient way to work with weight in a different unit systems. It could be useful if you have to work with different unit system, for example you have to work with :kg as well as :lb for USA
- mri 2.0.0
- mri 1.9.3
- mri 1.9.2
- jruby-19mode
- rbx-19mode
- jruby-18mode
- mri 1.8.7
- ree
Add this line to your application's Gemfile:
gem 'weight'
And then execute:
$ bundle
Or install it yourself as:
$ gem install weight
You could configure default unit system (:kg or :lb)
just put this in your initializer: config/initializers/weight.rb
# new object in kg by default
Weight.new # => <Weight: @input_value=0, @input_unit=:kg>
Weight::Configuration.configure do |config|
config.default_unit = :lb # by default it uses :kg
end
# Now default object looks like
Weight.new # => <Weight: @input_value=0, @input_unit=:lb>
Weight.new(1, :kg) + Weight.new(1, :kg) == Weight.new(2, :kg)
Weight.new(1, :kg) - Weight.new(1, :kg) == Weight.new(0, :kg)
Weight.new(1, :kg) * 2 == Weight.new(2, :kg)
Weight.new(2, :kg) / 2 == Weight.new(1, :kg)
Weight.new(3, :lb).between?(Weight.new(1, :kg), Weight.new(2, :kg))
Weight.new(1, :kg) > Weight.new(2, :lb)
Weight.new(1, :lb) <= Weight.new(0.5, :kg)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request