0.0
No commit activity in last 3 years
No release in over 3 years
Parse strings formatted as currencies
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0
>= 0
>= 0
 Project Readme

currency_parser

Installation

Add this line to your Rails 3.x application's Gemfile:

gem 'currency_parser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install currency_parser

API Summary

CurrencyParser works in any Ruby class, it does not require Active Record or other ORM. Its default settings has it configured for the German currency format, without allowing negative values.

parser = CurrencyParser::Parser.new
=> #<CurrencyParser::Parser:0x007feca487fe68
 @allow_negative=false,
 @delimiter=".",
 @format=:de,
 @separator=",">

parser.to_us("1,23")
=> "1.23"

parser.to_us("-1,23")
=> "1.23"

The same can be achieved without any change to the default configuration via

CurrencyParser::Parser.to_us("1,23")
=> "1.23"

As of v0.1.2 only the :de format is supported and you can allow negative values as follows

parser = CurrencyParser::Parser.new(:de, :allow_negative => true)
=> #<CurrencyParser::Parser:0x007feca9f999d8
 @allow_negative=true,
 @delimiter=".",
 @format=:de,
 @separator=",">

parser.to_us("-1,23")
=> "-1.23"

Invalid formats will raise an InvalidFormatError exception.

License

This project rocks and uses MIT-LICENSE.