Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/halogenandtoast/alchemist
A scientific conversion library.
https://github.com/halogenandtoast/alchemist
Last synced: 3 months ago
JSON representation
A scientific conversion library.
- Host: GitHub
- URL: https://github.com/halogenandtoast/alchemist
- Owner: halogenandtoast
- Created: 2010-02-10T19:54:27.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2021-03-23T15:23:59.000Z (almost 4 years ago)
- Last Synced: 2024-09-17T08:31:59.838Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 248 KB
- Stars: 155
- Watchers: 5
- Forks: 28
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Alchemist
=========[![Build Status](https://travis-ci.org/halogenandtoast/alchemist.png?branch=master)](https://travis-ci.org/halogenandtoast/alchemist)
[![Code Climate](https://codeclimate.com/github/halogenandtoast/alchemist.png)](https://codeclimate.com/github/halogenandtoast/alchemist)Doing conversions for you so you don’t have to google them and making
code more readable.Having code that looks like this is meaningless
```ruby
meters = 8 * 1609.344
```You could add comments
```ruby
meters = 8 * 1609.344 # converting miles to meters
```But why not have this!
```ruby
8.miles.to.meters
```You can even perform mathematical operations
```ruby
10.kilometers + 1.mile # 11.609344 kilometers
```Handling bytes now works according to the JEDEC memory standard
```ruby
1.kb.to.b.to_f == 1024.0
```Converting distance of arc length on Earth to an (approximate) corresponding spherical geometry angle can be done with
```ruby
require 'alchemist/geospatial'
1.mile.geospatial.to.degree == 0.014457066992474555
```To switch to the IEC memory standard, force SI units with
```ruby
Alchemist.config.use_si = true
```To see all the units alchemist has built in conversion for, check out the [units file](lib/alchemist/data/units.yml)
You may also register your own units
```ruby
Alchemist.register(:distance, [:beard_second, :beard_seconds], 5.angstroms)
```Installation
------------gem install alchemist
Setup
-----In order for methods like `1.meter` to work, you'll either need to setup Alchemist yourself:
```ruby
Alchemist.setup # This will load every category of measurement
```if you only want to use one category for conversions you can load it individually:
```ruby
Alchemist.setup('distance') # This will load only distance
```Rails
-----#### Setup
It is suggested that you add your `Alchemist.setup` call to `config/initializers/alchemist.rb` and then restart your rails server.
#### Rails Warning
Rails adds some methods like `bytes` to `Numeric` so it's highly recommended that instead of trying to call `bytes` on a numeric, you should use the `measure` method:
```ruby
Alchemist.measure(10, :bytes)
```License
-------Alchemist is licensed under the MIT license as specified in the [gemspec](alchemist.gemspec)