Converting units LIKE A BOSS (now based on the alchemist gem)
Having unit conversion code that looks like this is meaningless
miles = 8 * 1609.344
You could add comments
miles = 8 * 1609.344 # converting meters to miles
But why not have this?
You can even perform mathematic operations
10.kilometers + 1.mile # 11.609344 kilometers
You may also register your own units
Conversions.register(:distance, [:beard_second, :beard_seconds], 5.angstroms)
You can even compare different units
5.grams == 0.005.kilograms
gem install conversions
require 'conversions' puts 5.miles.to.kilometers
If you're using rails, add to your Gemfile:
Conversions has conversions for:
- metres or meters
- grams or grammes
- troy_pounds or apothecary_pounds
- tons or short_tons
- litres or liters
And many more!
Check out lib/conversions/default_table.rb for the rest
Please contribute patches!
- Fork the emitter repository on GitHub.
- Write a test proving the existing implementation's inadequacy. Ensure that the test fails.
- Improve the code until your new test passes and commit your changes.
- Push your changes to your GitHub fork.
- Submit a pull request to us.
- Receive a pull request.
- Pull changes from forked repository.
- Ensure tests pass.
- Review changes
- Merge changes to master repository and publish.