Giter VIP home page Giter VIP logo

alchemist's Introduction

Alchemist

Build Status Code Climate

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

meters = 8 * 1609.344

You could add comments

meters = 8 * 1609.344 # converting miles to meters

But why not have this!

8.miles.to.meters

You can even perform mathematical operations

10.kilometers + 1.mile # 11.609344 kilometers

Handling bytes now works according to the JEDEC memory standard

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

require 'alchemist/geospatial'
1.mile.geospatial.to.degree == 0.014457066992474555

To switch to the IEC memory standard, force SI units with

Alchemist.config.use_si = true

To see all the units alchemist has built in conversion for, check out the units file

You may also register your own units

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:

Alchemist.setup # This will load every category of measurement

if you only want to use one category for conversions you can load it individually:

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:

Alchemist.measure(10, :bytes)

License

Alchemist is licensed under the MIT license as specified in the gemspec

alchemist's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.