Skip to content

Latest commit

 

History

History
54 lines (33 loc) · 2.03 KB

README.md

File metadata and controls

54 lines (33 loc) · 2.03 KB

SimpleMagicCurrency @ 0.2.1

This is a simple gem (really simple), to handle money formats (USD, BRL and BTC. You can set your own format.).

Installation

Add this line to your application's Gemfile:

gem 'simple_magic_currency', git: "https://github.com/fabioaraujo121/simple_magic_currency", branch: "master"

And then execute:

$ bundle

Usage

  1. Make sure your money attribute type is Integer or Float or Decimal or BigDecimal or String
  2. Just use the method to_currency
  3. Or use to_currency(SimpleMagicCurrency::BRL) when you haven't setted default or want something different from default

Example

	product = Product.new(price: 19.99)
	product.price.to_currency # => R$ 19,99
	product.price.to_currency(SimpleMagicCurrency::USD) # => US$ 19,99
	product.price.to_currency(SimpleMagicCurrency::BTC, {unit: "ETH"}) # => 19.990000 ETH

Set Default Currency Required

  1. Create a file /config/initializers/simple_magice_currency.rb file
  2. Add SimpleMagicCurrency::DEFAULT = SimpleMagicCurrency::USD, to use Dollar format, for example

Supported Currencies

  • BRL
  • USD
  • BTC
  • Any other using the option params to_currency(nil, {delimiter: ',', separator: '.', unit: 'US$', precision: '2', position: 'before'})

Contributing

Feel free to contribute!!! \o/

Bug reports and pull requests are welcome on GitHub at https://github.com/fabioaraujo121/simple_magic_currency. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the SimpleMagicCurrency project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.