GithubHelp home page GithubHelp logo

isabella232 / monetize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rubymoney/monetize

0.0 0.0 0.0 192 KB

A library for converting various objects into `Money` objects.

License: MIT License

Ruby 100.00%

monetize's Introduction

Monetize

Gem Version Build Status Code Climate Dependency Status License

A library for converting various objects into Money objects.

Installation

Add this line to your application's Gemfile:

gem 'monetize'

And then execute:

$ bundle

Or install it yourself as:

$ gem install monetize

Usage

Monetize.parse("USD 100") == Money.new(100_00, "USD")
Monetize.parse("EUR 100") == Money.new(100_00, "EUR")
Monetize.parse("GBP 100") == Money.new(100_00, "GBP")

"100".to_money == Money.new(100_00, "USD")

parse will return nil if it is unable to parse the input. Use parse! instead if you want a Monetize::Error (or one of the subclasses) to be raised instead:

>> Monetize.parse('OMG 100')
=> nil

>> Monetize.parse!('OMG 100')
Monetize::ParseError: Unknown currency 'omg'

Optionally, enable the ability to assume the currency from a passed symbol. Otherwise, currency symbols will be ignored, and USD used as the default currency:

Monetize.parse("£100") == Money.new(100_00, "USD")

Monetize.assume_from_symbol = true

Monetize.parse("£100") == Money.new(100_00, "GBP")
"€100".to_money == Money.new(100_00, "EUR")

Monetize can also parse a list of values, returning an array-like object (Monetize::Collection):

Monetize.parse_collection("€80/$100") == [Money.new(80_00, "EUR"), Money.new(100_00, "USD")]
Monetize.parse_collection("€80, $100") == [Money.new(80_00, "EUR"), Money.new(100_00, "USD")]

# The #range? method detects the presence of a hyphen
Monetize.parse_collection("€80-$100").range? == true

Contributing

See CONTRIBUTING.md for details.

monetize's People

Contributors

semmons99 avatar antstorm avatar aredondo avatar bensheldon avatar allolex avatar ct-clearhaus avatar tatey avatar lautis avatar nitsas avatar julienitard avatar langtianlang avatar mehdiahmadov avatar boone avatar chtitux avatar awagener avatar alup avatar afdev82 avatar arthurtalkgoal avatar umate avatar bkeepers avatar dblock avatar daniel-levin avatar greggroth avatar guillehorno avatar snowblink avatar spk avatar leonyip avatar michaelpreston avatar maokomioko avatar crftr 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.