Giter Site home page Giter Site logo

janjiss / alchemist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from halogenandtoast/alchemist

0.0 1.0 0.0 164 KB

Ruby conversions like you've never seen them before

Home Page: https://github.com/halogenandtoast/alchemist

License: MIT License

Ruby 100.00%

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

miles = 8 * 1609.344

You could add comments

miles = 8 * 1609.344 # converting meters to miles

But why not have this!

8.meters.to.miles

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

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

Alchemist::use_si = true

You may also register your own units

Alchemist.register(:distance, [:beard_second, :beard_seconds], 5.angstroms)

Thanks to simonmenke you can now do comparisons without having to convert to floats like so:

5.grams == 0.005.kilograms

Installation

gem install alchemist

Usage

require 'rubygems'
require 'alchemist'

Or if you’re using rails

gem 'alchemist'

Alchemist has conversions for:

Distance

  • metres or meters
  • fermis
  • microns
  • chains
  • inches
  • microinches
  • mils
  • rods
  • leagues
  • feet
  • yards
  • miles
  • astronomical_units
  • light_years
  • parsecs
  • nautical_miles
  • admirality_miles
  • fathoms
  • cable_lengths
  • angstroms
  • picas
  • printer_picas
  • points
  • printer_points

Mass

  • grams or grammes
  • carats
  • ounces
  • pennyweights
  • pounds
  • troy_pounds or apothecary_pounds
  • slugs
  • assay_tons
  • metric_tons
  • tons or short_tons

Volume

  • litres or liters
  • barrels
  • bushels
  • cubic_meters
  • cups
  • imperial_fluid_ounces
  • fluid_ounces
  • imperial_gallons
  • gallons
  • imperial_gills
  • gills
  • pints
  • liquid_pints
  • quarts
  • liquid_quarts
  • tablespoons
  • teaspoons

And many more checkout lib/alchemist.rb for the rest

alchemist's People

Contributors

halogenandtoast avatar shenry avatar janjiss avatar nebelhut avatar fd avatar

Watchers

James Cloos avatar

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.