money 6.18.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +110 -49
- data/LICENSE +1 -1
- data/README.md +55 -54
- data/config/currency_backwards_compatible.json +17 -0
- data/config/currency_iso.json +47 -33
- data/config/currency_non_iso.json +1 -1
- data/lib/money/bank/base.rb +2 -0
- data/lib/money/bank/single_currency.rb +2 -0
- data/lib/money/bank/variable_exchange.rb +2 -0
- data/lib/money/currency/heuristics.rb +1 -1
- data/lib/money/currency/loader.rb +2 -0
- data/lib/money/currency.rb +35 -9
- data/lib/money/locale_backend/base.rb +2 -0
- data/lib/money/locale_backend/currency.rb +2 -0
- data/lib/money/locale_backend/errors.rb +2 -0
- data/lib/money/locale_backend/i18n.rb +4 -1
- data/lib/money/money/allocation.rb +51 -10
- data/lib/money/money/arithmetic.rb +31 -13
- data/lib/money/money/constructors.rb +2 -0
- data/lib/money/money/formatter.rb +13 -62
- data/lib/money/money/formatting_rules.rb +9 -59
- data/lib/money/money/locale_backend.rb +1 -3
- data/lib/money/money.rb +105 -119
- data/lib/money/rates_store/memory.rb +2 -0
- data/lib/money/version.rb +3 -1
- data/lib/money.rb +3 -0
- data/money.gemspec +8 -3
- metadata +22 -17
- data/lib/money/locale_backend/legacy.rb +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 435fd498ba0ce70e5d0ee2079e0e99d93abc2c17440f7a6cacda1176641b7d3a
|
|
4
|
+
data.tar.gz: 81fdc617e20b27d8628ba2f4859fa2fd41a9cbc04c3a44ddf689036b4414f40b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e2ef4767b6d9a50fa7d6eed46570249af8c2e2bade1c8b11aee93d737d1a8c484d74f1aaf837a880e28af8be44b1c5413a5bea854a015b936026032a3070dcd
|
|
7
|
+
data.tar.gz: 756de612cdebdb1e4cf3311f460a3f5118fd775a4f1760ad211c4fd6816804cc16f8b4c461bb8a0292031d7b03a22ae0f291844467791fbbc1a9f1bc46519060
|
data/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,76 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 7.0.0
|
|
6
|
+
|
|
7
|
+
- **Breaking change**: Require Ruby >= 3.1 and i18n ~> 1.9
|
|
8
|
+
- **Breaking change**: Remove deprecated formatting rules:
|
|
9
|
+
- `:html`
|
|
10
|
+
- `:html_wrap_symbol`
|
|
11
|
+
- `:symbol_position`
|
|
12
|
+
- `:symbol_before_without_space`
|
|
13
|
+
- `:symbol_after_without_space`
|
|
14
|
+
- **Breaking change**: Remove deprecated methods:
|
|
15
|
+
- `Money.infinite_precision`.
|
|
16
|
+
- `Money.infinite_precision=`.
|
|
17
|
+
- `Money#currency_as_string`.
|
|
18
|
+
- `Money#currency_as_string=`.
|
|
19
|
+
- `Money.use_i18n` and `Money.use_i18n=` (use `Money.locale_backend = :i18n` instead).
|
|
20
|
+
- **Breaking change**: Remove legacy locale backend. The default locale backend is now `:currency` which uses currency definitions for formatting.
|
|
21
|
+
- **Breaking change**: Default currency is now `nil` instead of `USD`. If you want to keep the previous behavior, set `Money.default_currency = Money::Currency.new("USD")` in your initializer. Initializing a Money object will raise a `Currency::NoCurrency` if no currency is set.
|
|
22
|
+
- **Breaking change**: The default rounding mode has changed from `BigDecimal::ROUND_HALF_EVEN` to `BigDecimal::ROUND_HALF_UP`. Set it explicitly using `Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN` to keep the previous behavior.
|
|
23
|
+
- **Potential breaking change**: Fix RSD (Serbian Dinar) formatting to be like `12.345,42 RSD`
|
|
24
|
+
- **Potential breaking change**: Fix USDC decimals places from 2 to 6
|
|
25
|
+
- **Potential breaking change**: Fix MGA (Malagasy Ariary) to be a zero-decimal currency (changing subunit_to_unit from 5 to 1)
|
|
26
|
+
- **Potential breaking change**: Remove special handling for Japanese language only
|
|
27
|
+
- **Potential breaking change**: Adjust formatting rules to use i18n translations for `:format`
|
|
28
|
+
- **Potential breaking change**: Not allow divide by zero
|
|
29
|
+
- Updated Armenian Dram sign and HTML entity
|
|
30
|
+
- Updated the Turkmen Manat symbol and HTML entity and added disambiguation symbol for TMM
|
|
31
|
+
- Expose Money::VERSION
|
|
32
|
+
- Fix typo in ILS currency
|
|
33
|
+
- Add Zimbabwe Gold (ZWG) currency
|
|
34
|
+
- Update thousands_separator for CHF
|
|
35
|
+
- Add Caribbean Guilder (XCG) as replacement for Netherlands Antillean Gulden (ANG)
|
|
36
|
+
- Add `Money.strict_eql_compare = true` so that comparing zero amounts with different currencies using `Money#eql?` returns `false`
|
|
37
|
+
```rb
|
|
38
|
+
Money.new(0, "USD").eql?(Money.new(0, "EUR")) #=> true
|
|
39
|
+
#> [DEPRECATION] Comparing 0 USD with 0 EUR using `#eql?` will return false…
|
|
40
|
+
|
|
41
|
+
Money.strict_eql_compare = true
|
|
42
|
+
Money.new(0, "USD").eql?(Money.new(0, "EUR")) #=> false
|
|
43
|
+
```
|
|
44
|
+
- Add `Money#to_nearest_cash_value` to return a rounded Money instance to the smallest denomination
|
|
45
|
+
- Deprecate `Money#round_to_nearest_cash_value` in favor of calling `to_nearest_cash_value.fractional`
|
|
46
|
+
- Deprecate `Money#dollars` in favor of `Money#amount`.
|
|
47
|
+
- Deprecate `Money.from_dollars` in favor of `Money.from_amount`.
|
|
48
|
+
- Add `Money::Currency#cents_based?` to check if currency is cents-based
|
|
49
|
+
- Add ability to nest `Money.with_rounding_mode` blocks
|
|
50
|
+
- Allow `nil` to be used as a default_currency
|
|
51
|
+
- Improve performance of `find_by_iso_numeric` method
|
|
52
|
+
- Add ability to nest `Money.with_bank` blocks
|
|
53
|
+
- Refactor `Money::Allocation.generate` to support configurable per-split precision by accepting an Integer as a second argument, fixing allocation failures with large arrays and infinite decimal expansions.
|
|
54
|
+
|
|
55
|
+
## 6.19.0
|
|
56
|
+
|
|
57
|
+
- Change Peruvian Sol (PEN) decimal mark and thousands separator.
|
|
58
|
+
- Fix deprecation warning for BigDecimal being moved out from stdlib.
|
|
59
|
+
- Improves Precision and Simplifies Allocation Logic
|
|
60
|
+
- explicit declaration of i18n locales
|
|
61
|
+
- Add space to CHF format
|
|
62
|
+
- Update deprecation message to suggest correct formatting.
|
|
63
|
+
|
|
64
|
+
## 6.18.0
|
|
4
65
|
|
|
5
66
|
- Add second dobra (STN) from São Tomé and Príncipe
|
|
67
|
+
- Add Sierra Leonean (new) leone (SLE) from Sierra Leone
|
|
68
|
+
- Correct South African Rand (ZAR) to use comma decimal mark, and space thousands separator
|
|
6
69
|
- Use euro symbol as html_entity for euro currency
|
|
7
70
|
- Update Georgian Lari symbol
|
|
8
|
-
- Add Ruby 3.1 to the CI matrix
|
|
9
|
-
|
|
10
|
-
## 6.18.0
|
|
11
|
-
|
|
71
|
+
- Add Ruby 3.1 and 3.2 to the CI matrix
|
|
12
72
|
- Add `Money.from_dollars` alias as a more explicit initializer, it's the same as `Money.from_amount`
|
|
73
|
+
- Mark Croatian Kuna (HRK) as obsolete by moving its definition to the backwards compatibility data source
|
|
13
74
|
|
|
14
75
|
## 6.17.0
|
|
15
76
|
|
|
@@ -200,7 +261,7 @@
|
|
|
200
261
|
return `nil` as `Comparable#==` will not rescue exceptions in the next release.
|
|
201
262
|
- Fix `Currency` specs for `#exponent` and `#decimal_places` not making assertions.
|
|
202
263
|
- Fix a couple of Ruby warnings found in specs.
|
|
203
|
-
- Fix `Money#-`,`Money#+`
|
|
264
|
+
- Fix `Money#-`,`Money#+` arithmetic for Ruby 2.3+ : check for zero value without using eql? with a Fixnum. (#577)
|
|
204
265
|
- Use `Money#decimal_mark` when formatting with `rounded_infinite_precision` rule
|
|
205
266
|
set to `true`.
|
|
206
267
|
- Replaced meta-defined `thousands_separator` and `decimal_mark` methods with regular methods. (#579)
|
|
@@ -247,7 +308,7 @@
|
|
|
247
308
|
- Fix formatting of NGN - show symbol before amount
|
|
248
309
|
- Switch default and alternate symbols for RUB currency
|
|
249
310
|
- Fix symbol for TRY currency
|
|
250
|
-
- Add `Money.default_formatting_rules` hash, meant to define default rules for
|
|
311
|
+
- Add `Money.default_formatting_rules` hash, meant to define default rules for every time `Money#format` is called. They can be overwritten if provided on method call
|
|
251
312
|
- Add support for the new official symbol for Russian Ruble (RUB) — «₽»
|
|
252
313
|
|
|
253
314
|
## 6.2.1
|
|
@@ -416,7 +477,7 @@ Features
|
|
|
416
477
|
|
|
417
478
|
Bugfixes
|
|
418
479
|
--------
|
|
419
|
-
- EEK currency is no longer used, kept for BC ([#issue/110](
|
|
480
|
+
- EEK currency is no longer used, kept for BC ([#issue/110](https://github.com/RubyMoney/money/issues/110))
|
|
420
481
|
- Lithuanian Litas symbol position fixed (laurynas)
|
|
421
482
|
- Fixed README typos (phlipper)
|
|
422
483
|
- Fixed README typos (pwim)
|
|
@@ -542,11 +603,11 @@ Bugfixes
|
|
|
542
603
|
--------
|
|
543
604
|
- Updated Money#to_s to respect :separator and :subunit_to_unit.
|
|
544
605
|
- Fixed Money#format for :subunit_to_unit != 100.
|
|
545
|
-
([#issue/37](
|
|
606
|
+
([#issue/37](https://github.com/RubyMoney/money/issues/37))
|
|
546
607
|
- Fixed String#to_money for :subunit_to_unit != 100.
|
|
547
|
-
([#issue/36](
|
|
608
|
+
([#issue/36](https://github.com/RubyMoney/money/issues/36))
|
|
548
609
|
- Removed duplicate currencies.
|
|
549
|
-
([#issue/38](
|
|
610
|
+
([#issue/38](https://github.com/RubyMoney/money/issues/38))
|
|
550
611
|
- Fixed issue related to JRuby returning 2 for Math.log10(1000).floor instead
|
|
551
612
|
of correctly returning 3.
|
|
552
613
|
|
|
@@ -557,22 +618,22 @@ Features
|
|
|
557
618
|
--------
|
|
558
619
|
- Added support for creating objects with the main monetary unit instead of
|
|
559
620
|
cents.
|
|
560
|
-
([#issue/25](
|
|
621
|
+
([#issue/25](https://github.com/RubyMoney/money/issues/25))
|
|
561
622
|
- Deprecated `Money#format` with separate params instead of Hash. Deprecation
|
|
562
623
|
target set to Money 3.5.0.
|
|
563
|
-
([#issue/31](
|
|
624
|
+
([#issue/31](https://github.com/RubyMoney/money/issues/31))
|
|
564
625
|
- Deprecated `Money#new(0, currency: "EUR")` in favor of
|
|
565
626
|
`Money#new(0, "EUR")`. Deprecation target set to Money 3.5.0.
|
|
566
|
-
([#issue/31](
|
|
627
|
+
([#issue/31](https://github.com/RubyMoney/money/issues/31))
|
|
567
628
|
- Throw ArgumentError when trying to multiply two Money objects together.
|
|
568
|
-
([#issue/29](
|
|
629
|
+
([#issue/29](https://github.com/RubyMoney/money/issues/29))
|
|
569
630
|
- Update Money#parse to use :subunit_to_unit
|
|
570
|
-
([#issue/30](
|
|
631
|
+
([#issue/30](https://github.com/RubyMoney/money/issues/30))
|
|
571
632
|
|
|
572
633
|
Bugfixes
|
|
573
634
|
--------
|
|
574
635
|
- Downgraded required_rubygems_version to >= 1.3.6.
|
|
575
|
-
([#issue/26](
|
|
636
|
+
([#issue/26](https://github.com/RubyMoney/money/issues/26))
|
|
576
637
|
- Use BigDecimal when floating point calculations are needed.
|
|
577
638
|
- Ruby 1.9.2 compatibility enhancements.
|
|
578
639
|
|
|
@@ -582,32 +643,32 @@ Money 3.1.0
|
|
|
582
643
|
Features
|
|
583
644
|
--------
|
|
584
645
|
- Implemented `Money::Bank::Base`.
|
|
585
|
-
([#issue/14](
|
|
646
|
+
([#issue/14](https://github.com/RubyMoney/money/issues/14))
|
|
586
647
|
- Added `Money::Bank::Base#exchange_with`.
|
|
587
648
|
- Deprecated `Money::Bank::Base#exchange`. Deprecation target set to Money
|
|
588
649
|
3.2.0.
|
|
589
|
-
-
|
|
650
|
+
- Implemented `Money::Bank::VariableExchange`
|
|
590
651
|
- Deprecated `Money::VariableExchangeBank`. Deprecation target set to Money
|
|
591
652
|
3.2.0.
|
|
592
653
|
- Deprecate `Money::SYMBOLS`, `Money::SEPARATORS` and `Money::DELIMITERS`.
|
|
593
654
|
Deprecation target set to Money 3.2.0.
|
|
594
|
-
([#issue/16](
|
|
655
|
+
([#issue/16](https://github.com/RubyMoney/money/issues/16))
|
|
595
656
|
- Implemented `#has` for `Money` and `Money::Currency`.
|
|
596
657
|
- Refactored test suite to conform to RSpec conventions.
|
|
597
|
-
- Moved project from [FooBarWidget](
|
|
598
|
-
[RubyMoney](
|
|
658
|
+
- Moved project from [FooBarWidget](https://github.com/FooBarWidget) to
|
|
659
|
+
[RubyMoney](https://github.com/RubyMoney)
|
|
599
660
|
- Added Simone Carletti to list of authors.
|
|
600
661
|
- Moved `@rounding_method` from `Money::Bank::VariableExchange` to
|
|
601
662
|
`Money::Bank::Base`.
|
|
602
|
-
([#issue/18](
|
|
663
|
+
([#issue/18](https://github.com/RubyMoney/money/issues/18))
|
|
603
664
|
- Added `#setup` to `Money::Bank::Base`. Called from `#initialize`.
|
|
604
|
-
([#issue/19](
|
|
605
|
-
- Added [google_currency](
|
|
665
|
+
([#issue/19](https://github.com/RubyMoney/money/issues/19))
|
|
666
|
+
- Added [google_currency](https://github.com/RubyMoney/google_currency) to list
|
|
606
667
|
of Currency Exchange Implementations.
|
|
607
668
|
- Added `#export_rates` to `Money::Bank::VariableExchange`.
|
|
608
|
-
([#issue/21](
|
|
669
|
+
([#issue/21](https://github.com/RubyMoney/money/issues/21))
|
|
609
670
|
- Added `#import_rates` to `Money::Bank::VariableExchange`.
|
|
610
|
-
([#issue/21](
|
|
671
|
+
([#issue/21](https://github.com/RubyMoney/money/issues/21))
|
|
611
672
|
- Removed dependency on Jeweler.
|
|
612
673
|
- Replaced usage of hanna with yardoc.
|
|
613
674
|
- Rewrote/reformatted all documentation.
|
|
@@ -615,30 +676,30 @@ Features
|
|
|
615
676
|
Bugfixes
|
|
616
677
|
--------
|
|
617
678
|
- Fixed incorrect URLs in documentation.
|
|
618
|
-
([#issue/17](
|
|
679
|
+
([#issue/17](https://github.com/RubyMoney/money/issues/17))
|
|
619
680
|
- Updated `:subunit_to_unit` for HKD from 10 to 100.
|
|
620
|
-
([#issue/20](
|
|
681
|
+
([#issue/20](https://github.com/RubyMoney/money/issues/20))
|
|
621
682
|
- Updated Ghanaian Cedi to use correct ISO Code, GHS.
|
|
622
|
-
([#issue/22](
|
|
683
|
+
([#issue/22](https://github.com/RubyMoney/money/issues/22))
|
|
623
684
|
- Make `default` rake task call `spec`.
|
|
624
|
-
([#issue/23](
|
|
685
|
+
([#issue/23](https://github.com/RubyMoney/money/issues/23))
|
|
625
686
|
|
|
626
687
|
Money 3.1.0.pre3
|
|
627
688
|
================
|
|
628
689
|
|
|
629
690
|
Features
|
|
630
691
|
--------
|
|
631
|
-
- Added [google_currency](
|
|
692
|
+
- Added [google_currency](https://github.com/RubyMoney/google_currency) to list
|
|
632
693
|
of Currency Exchange Implementations.
|
|
633
694
|
- Added `#export_rates` to `Money::Bank::VariableExchange`.
|
|
634
|
-
([#issue/21](
|
|
695
|
+
([#issue/21](https://github.com/RubyMoney/money/issues/21))
|
|
635
696
|
- Added `#import_rates` to `Money::Bank::VariableExchange`.
|
|
636
|
-
([#issue/21](
|
|
697
|
+
([#issue/21](https://github.com/RubyMoney/money/issues/21))
|
|
637
698
|
|
|
638
699
|
Bugfixes
|
|
639
700
|
--------
|
|
640
701
|
- Updated `:subunit_to_unit` for HKD from 10 to 100.
|
|
641
|
-
([#issue/20](
|
|
702
|
+
([#issue/20](https://github.com/RubyMoney/money/issues/20))
|
|
642
703
|
|
|
643
704
|
Money 3.1.0.pre2
|
|
644
705
|
================
|
|
@@ -647,14 +708,14 @@ Features
|
|
|
647
708
|
--------
|
|
648
709
|
- Moved `@rounding_method` from `Money::Bank::VariableExchange` to
|
|
649
710
|
`Money::Bank::Base`.
|
|
650
|
-
([#issue/18](
|
|
711
|
+
([#issue/18](https://github.com/RubyMoney/money/issues/18))
|
|
651
712
|
- Added `#setup` to `Money::Bank::Base`. Called from `#initialize`.
|
|
652
|
-
([#issue/19](
|
|
713
|
+
([#issue/19](https://github.com/RubyMoney/money/issues/19))
|
|
653
714
|
|
|
654
715
|
Bugfixes
|
|
655
716
|
--------
|
|
656
717
|
- Fixed incorrect URLs in documentation.
|
|
657
|
-
([#issue/17](
|
|
718
|
+
([#issue/17](https://github.com/RubyMoney/money/issues/17))
|
|
658
719
|
|
|
659
720
|
Money 3.1.0.pre1
|
|
660
721
|
================
|
|
@@ -662,26 +723,26 @@ Money 3.1.0.pre1
|
|
|
662
723
|
Features
|
|
663
724
|
--------
|
|
664
725
|
- Implemented `Money::Bank::Base`.
|
|
665
|
-
([#issue/14](
|
|
726
|
+
([#issue/14](https://github.com/RubyMoney/money/issues/14))
|
|
666
727
|
- Added `Money::Bank::Base#exchange_with`.
|
|
667
728
|
- Deprecated `Money::Bank::Base#exchange`. Deprecation target set to Money
|
|
668
729
|
3.2.0.
|
|
669
|
-
-
|
|
730
|
+
- Implemented `Money::Bank::VariableExchange`
|
|
670
731
|
- Deprecated `Money::VariableExchangeBank`. Deprecation target set to Money
|
|
671
732
|
3.2.0.
|
|
672
733
|
- Deprecate `Money::SYMBOLS`, `Money::SEPARATORS` and `Money::DELIMITERS`.
|
|
673
734
|
Deprecation target set to Money 3.2.0.
|
|
674
|
-
([#issue/16](
|
|
735
|
+
([#issue/16](https://github.com/RubyMoney/money/issues/16))
|
|
675
736
|
- Implemented `#has` for `Money` and `Money::Currency`.
|
|
676
737
|
- Refactored test suite to conform to RSpec conventions.
|
|
677
|
-
- Moved project from [FooBarWidget](
|
|
678
|
-
[RubyMoney](
|
|
738
|
+
- Moved project from [FooBarWidget](https://github.com/FooBarWidget) to
|
|
739
|
+
[RubyMoney](https://github.com/RubyMoney)
|
|
679
740
|
- Added Simone Carletti to list of authors.
|
|
680
741
|
|
|
681
742
|
Bugfixes
|
|
682
743
|
--------
|
|
683
744
|
- Fixed rounding error in `Numeric#to_money`.
|
|
684
|
-
([#issue/15](
|
|
745
|
+
([#issue/15](https://github.com/RubyMoney/money/issues/15))
|
|
685
746
|
|
|
686
747
|
Money 3.0.5
|
|
687
748
|
===========
|
|
@@ -692,11 +753,11 @@ Features
|
|
|
692
753
|
- Added ability to pass a block to `VariableExchangeBank#new` or `#exchange`,
|
|
693
754
|
specifying a custom truncation method
|
|
694
755
|
- Added optional `currency` argument to` Numeric#to_money`.
|
|
695
|
-
([#issue/11](
|
|
756
|
+
([#issue/11](https://github.com/RubyMoney/money/issues/11))
|
|
696
757
|
- Added optional `currency` argument to `String#to_money`.
|
|
697
|
-
([#issue/11](
|
|
758
|
+
([#issue/11](https://github.com/RubyMoney/money/issues/11))
|
|
698
759
|
- Use '¤' as the default currency symbol.
|
|
699
|
-
([#issue/10](
|
|
760
|
+
([#issue/10](https://github.com/RubyMoney/money/issues/10))
|
|
700
761
|
|
|
701
762
|
Bugfixes
|
|
702
763
|
--------
|
|
@@ -705,7 +766,7 @@ Bugfixes
|
|
|
705
766
|
- Fixed issue when exchanging currencies with different `:subunit_to_unit`
|
|
706
767
|
values.
|
|
707
768
|
- `Numeric#to_money` now respects `:subunit_to_unit`.
|
|
708
|
-
([#issue/12](
|
|
769
|
+
([#issue/12](https://github.com/RubyMoney/money/issues/12))
|
|
709
770
|
|
|
710
771
|
Money 3.0.4
|
|
711
772
|
===========
|
|
@@ -752,7 +813,7 @@ Features
|
|
|
752
813
|
--------
|
|
753
814
|
- Version Bump due to compatibility changes with ActiveRecord. See
|
|
754
815
|
conversation
|
|
755
|
-
[here](
|
|
816
|
+
[here](https://github.com/RubyMoney/money/issues/4#issuecomment-224880)
|
|
756
817
|
for more information.
|
|
757
818
|
|
|
758
819
|
Money 2.3.0
|
data/LICENSE
CHANGED
|
@@ -2,7 +2,7 @@ MIT License
|
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2005 Tobias Lutke
|
|
4
4
|
Copyright (c) 2008 Phusion
|
|
5
|
-
Copyright (c)
|
|
5
|
+
Copyright (c) 2025 Shane Emmons
|
|
6
6
|
|
|
7
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
8
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/money)
|
|
4
4
|
[](https://github.com/RubyMoney/money/actions/workflows/ruby.yml)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://rubymoney.github.io/money/)
|
|
6
|
+
[](https://opensource.org/license/MIT)
|
|
8
7
|
|
|
9
|
-
:warning: Please read the [
|
|
8
|
+
:warning: Please read the [upgrade guides](#upgrade-guides) before upgrading to a new major version.
|
|
10
9
|
|
|
11
10
|
If you miss String parsing, check out the new [monetize gem](https://github.com/RubyMoney/monetize).
|
|
12
11
|
|
|
13
12
|
## Contributing
|
|
14
13
|
|
|
15
|
-
See the [Contribution Guidelines](https://github.com/RubyMoney/money/blob/
|
|
14
|
+
See the [Contribution Guidelines](https://github.com/RubyMoney/money/blob/main/CONTRIBUTING.md)
|
|
16
15
|
|
|
17
16
|
## Introduction
|
|
18
17
|
|
|
@@ -33,15 +32,13 @@ A Ruby Library for dealing with money and currency conversion.
|
|
|
33
32
|
### Resources
|
|
34
33
|
|
|
35
34
|
- [Website](https://rubymoney.github.io/money/)
|
|
36
|
-
- [API Documentation](
|
|
35
|
+
- [API Documentation](https://www.rubydoc.info/gems/money/frames)
|
|
37
36
|
- [Git Repository](https://github.com/RubyMoney/money)
|
|
38
37
|
|
|
39
38
|
### Notes
|
|
40
39
|
|
|
41
40
|
- Your app must use UTF-8 to function with this library. There are a
|
|
42
41
|
number of non-ASCII currency attributes.
|
|
43
|
-
- This app requires JSON. If you're using JRuby < 1.7.0
|
|
44
|
-
you'll need to add `gem "json"` to your Gemfile or similar.
|
|
45
42
|
|
|
46
43
|
## Downloading
|
|
47
44
|
|
|
@@ -57,9 +54,13 @@ The development version (hosted on Github) can be installed with:
|
|
|
57
54
|
|
|
58
55
|
## Usage
|
|
59
56
|
|
|
60
|
-
```
|
|
57
|
+
```ruby
|
|
61
58
|
require 'money'
|
|
62
59
|
|
|
60
|
+
# explicitly define locales
|
|
61
|
+
I18n.config.available_locales = :en
|
|
62
|
+
Money.locale_backend = :i18n
|
|
63
|
+
|
|
63
64
|
# 10.00 USD
|
|
64
65
|
money = Money.from_cents(1000, "USD")
|
|
65
66
|
money.cents #=> 1000
|
|
@@ -101,7 +102,7 @@ Currencies are consistently represented as instances of `Money::Currency`.
|
|
|
101
102
|
The most part of `Money` APIs allows you to supply either a `String` or a
|
|
102
103
|
`Money::Currency`.
|
|
103
104
|
|
|
104
|
-
```
|
|
105
|
+
```ruby
|
|
105
106
|
Money.from_cents(1000, "USD") == Money.from_cents(1000, Money::Currency.new("USD"))
|
|
106
107
|
Money.from_cents(1000, "EUR").currency == Money::Currency.new("EUR")
|
|
107
108
|
```
|
|
@@ -109,16 +110,17 @@ Money.from_cents(1000, "EUR").currency == Money::Currency.new("EUR")
|
|
|
109
110
|
A `Money::Currency` instance holds all the information about the currency,
|
|
110
111
|
including the currency symbol, name and much more.
|
|
111
112
|
|
|
112
|
-
```
|
|
113
|
+
```ruby
|
|
113
114
|
currency = Money.from_cents(1000, "USD").currency
|
|
114
|
-
currency.iso_code
|
|
115
|
-
currency.name
|
|
115
|
+
currency.iso_code #=> "USD"
|
|
116
|
+
currency.name #=> "United States Dollar"
|
|
117
|
+
currency.cents_based? #=> true
|
|
116
118
|
```
|
|
117
119
|
|
|
118
120
|
To define a new `Money::Currency` use `Money::Currency.register` as shown
|
|
119
121
|
below.
|
|
120
122
|
|
|
121
|
-
```
|
|
123
|
+
```ruby
|
|
122
124
|
curr = {
|
|
123
125
|
priority: 1,
|
|
124
126
|
iso_code: "USD",
|
|
@@ -162,7 +164,7 @@ selector like the one available
|
|
|
162
164
|
custom methods to return the list of major currencies and all currencies as
|
|
163
165
|
follows:
|
|
164
166
|
|
|
165
|
-
```
|
|
167
|
+
```ruby
|
|
166
168
|
# Returns an array of currency id where
|
|
167
169
|
# priority < 10
|
|
168
170
|
def major_currencies(hash)
|
|
@@ -190,23 +192,22 @@ all_currencies(Money::Currency.table)
|
|
|
190
192
|
|
|
191
193
|
### Default Currency
|
|
192
194
|
|
|
193
|
-
|
|
194
|
-
using:
|
|
195
|
+
A default currency is not set by default. If a default currency is not set, it will raise an error when you try to initialize a `Money` object without explicitly passing a currency or parse a string that does not contain a currency. You can set a default currency for your application by using:
|
|
195
196
|
|
|
196
|
-
```
|
|
197
|
+
```ruby
|
|
197
198
|
Money.default_currency = Money::Currency.new("CAD")
|
|
198
199
|
```
|
|
199
200
|
|
|
200
|
-
If you use [Rails](https://github.com/RubyMoney/money/tree/
|
|
201
|
+
If you use [Rails](https://github.com/RubyMoney/money/tree/main#ruby-on-rails), then `config/initializers/money.rb` is a very good place to put this.
|
|
201
202
|
|
|
202
203
|
### Currency Exponent
|
|
203
204
|
|
|
204
205
|
The exponent of a money value is the number of digits after the decimal
|
|
205
206
|
separator (which separates the major unit from the minor unit). See e.g.
|
|
206
|
-
[ISO 4217](https://www.
|
|
207
|
+
[ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) for more
|
|
207
208
|
information. You can find the exponent (as an `Integer`) by
|
|
208
209
|
|
|
209
|
-
```
|
|
210
|
+
```ruby
|
|
210
211
|
Money::Currency.new("USD").exponent # => 2
|
|
211
212
|
Money::Currency.new("JPY").exponent # => 0
|
|
212
213
|
Money::Currency.new("MGA").exponent # => 1
|
|
@@ -216,7 +217,7 @@ Money::Currency.new("MGA").exponent # => 1
|
|
|
216
217
|
|
|
217
218
|
To find a given currency by ISO 4217 numeric code (three digits) you can do
|
|
218
219
|
|
|
219
|
-
```
|
|
220
|
+
```ruby
|
|
220
221
|
Money::Currency.find_by_iso_numeric(978) #=> Money::Currency.new(:eur)
|
|
221
222
|
```
|
|
222
223
|
|
|
@@ -226,7 +227,7 @@ Exchanging money is performed through an exchange bank object. The default
|
|
|
226
227
|
exchange bank object requires one to manually specify the exchange rate. Here's
|
|
227
228
|
an example of how it works:
|
|
228
229
|
|
|
229
|
-
```
|
|
230
|
+
```ruby
|
|
230
231
|
Money.add_rate("USD", "CAD", 1.24515)
|
|
231
232
|
Money.add_rate("CAD", "USD", 0.803115)
|
|
232
233
|
|
|
@@ -236,7 +237,7 @@ Money.ca_dollar(100).exchange_to("USD") # => Money.from_cents(80, "USD")
|
|
|
236
237
|
|
|
237
238
|
Comparison and arithmetic operations work as expected:
|
|
238
239
|
|
|
239
|
-
```
|
|
240
|
+
```ruby
|
|
240
241
|
Money.from_cents(1000, "USD") <=> Money.from_cents(900, "USD") # => 1; 9.00 USD is smaller
|
|
241
242
|
Money.from_cents(1000, "EUR") + Money.from_cents(10, "EUR") == Money.from_cents(1010, "EUR")
|
|
242
243
|
|
|
@@ -344,14 +345,13 @@ end
|
|
|
344
345
|
The following example implements a `Redis` store to save exchange rates to a redis database.
|
|
345
346
|
|
|
346
347
|
```ruby
|
|
347
|
-
|
|
348
348
|
class RedisRateStore
|
|
349
349
|
INDEX_KEY_SEPARATOR = '_TO_'.freeze
|
|
350
|
-
|
|
350
|
+
|
|
351
351
|
# Using second db of the redis instance
|
|
352
352
|
# because sidekiq uses the first db
|
|
353
353
|
REDIS_DATABASE = 1
|
|
354
|
-
|
|
354
|
+
|
|
355
355
|
# Using Hash to store rates data
|
|
356
356
|
REDIS_STORE_KEY = 'rates'
|
|
357
357
|
|
|
@@ -406,9 +406,9 @@ Money.from_cents(1000, 'USD').exchange_to('CAD') #=> #<Money fractional:900 curr
|
|
|
406
406
|
```
|
|
407
407
|
|
|
408
408
|
There is nothing stopping you from creating store objects which scrapes
|
|
409
|
-
[XE](
|
|
409
|
+
[XE](https://www.xe.com) for the current rates or just returns `rand(2)`:
|
|
410
410
|
|
|
411
|
-
```
|
|
411
|
+
```ruby
|
|
412
412
|
Money.default_bank = Money::Bank::VariableExchange.new(StoreWhichScrapesXeDotCom.new)
|
|
413
413
|
```
|
|
414
414
|
|
|
@@ -422,7 +422,7 @@ Money.default_bank = MyCustomBank.new(Money::RatesStore::Memory.new)
|
|
|
422
422
|
If you wish to disable automatic currency conversion to prevent arithmetic when
|
|
423
423
|
currencies don't match:
|
|
424
424
|
|
|
425
|
-
```
|
|
425
|
+
```ruby
|
|
426
426
|
Money.disallow_currency_conversion!
|
|
427
427
|
```
|
|
428
428
|
|
|
@@ -444,9 +444,9 @@ implementations.
|
|
|
444
444
|
|
|
445
445
|
## Formatting
|
|
446
446
|
|
|
447
|
-
There are several formatting rules for when `Money#format` is called. For more information, check out the [formatting module source](https://github.com/RubyMoney/money/blob/
|
|
447
|
+
There are several formatting rules for when `Money#format` is called. For more information, check out the [formatting module source](https://github.com/RubyMoney/money/blob/main/lib/money/money/formatter.rb), or read the latest release's [rdoc version](https://www.rubydoc.info/gems/money/Money/Formatter).
|
|
448
448
|
|
|
449
|
-
If you wish to format money according to the EU's [Rules for expressing monetary units](
|
|
449
|
+
If you wish to format money according to the EU's [Rules for expressing monetary units](https://style-guide.europa.eu/en/content/-/isg/topic?identifier=7.3.3-rules-for-expressing-monetary-units#id370303__id370303_PositionISO) in either English, Irish, Latvian or Maltese:
|
|
450
450
|
|
|
451
451
|
```ruby
|
|
452
452
|
m = Money.from_cents('123', :gbp) # => #<Money fractional:123 currency:GBP>
|
|
@@ -470,23 +470,31 @@ Money.from_amount(2.34567).format #=> "$2.34567"
|
|
|
470
470
|
|
|
471
471
|
To round to the nearest cent (or anything more precise), you can use the `round` method. However, note that the `round` method on a `Money` object does not work the same way as a normal Ruby `Float` object. Money's `round` method accepts different arguments. The first argument to the round method is the rounding mode, while the second argument is the level of precision relative to the cent.
|
|
472
472
|
|
|
473
|
-
```
|
|
473
|
+
```ruby
|
|
474
474
|
# Float
|
|
475
475
|
2.34567.round #=> 2
|
|
476
476
|
2.34567.round(2) #=> 2.35
|
|
477
477
|
|
|
478
478
|
# Money
|
|
479
479
|
Money.default_infinite_precision = true
|
|
480
|
-
Money.from_cents(2.34567).format
|
|
480
|
+
Money.from_cents(2.34567).format #=> "$0.0234567"
|
|
481
481
|
Money.from_cents(2.34567).round.format #=> "$0.02"
|
|
482
|
-
Money.from_cents(2.34567).round(BigDecimal::
|
|
482
|
+
Money.from_cents(2.34567).round(BigDecimal::ROUND_DOWN, 2).format #=> "$0.0234"
|
|
483
483
|
```
|
|
484
484
|
|
|
485
485
|
You can set the default rounding mode by passing one of the `BigDecimal` mode enumerables like so:
|
|
486
|
+
|
|
486
487
|
```ruby
|
|
487
488
|
Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
|
488
489
|
```
|
|
489
|
-
|
|
490
|
+
|
|
491
|
+
See [BigDecimal::ROUND_MODE](https://ruby-doc.org/3.4.1/gems/bigdecimal/BigDecimal.html#ROUND_MODE) for more information.
|
|
492
|
+
|
|
493
|
+
To round to the nearest cash value in currencies without small denominations:
|
|
494
|
+
|
|
495
|
+
```ruby
|
|
496
|
+
Money.from_cents(11_11, "CHF").to_nearest_cash_value.format # => "CHF 11.10"
|
|
497
|
+
```
|
|
490
498
|
|
|
491
499
|
## Ruby on Rails
|
|
492
500
|
|
|
@@ -502,7 +510,7 @@ In order to localize formatting you can use `I18n` gem:
|
|
|
502
510
|
Money.locale_backend = :i18n
|
|
503
511
|
```
|
|
504
512
|
|
|
505
|
-
With this enabled a thousands
|
|
513
|
+
With this enabled a thousands separator and a decimal mark will get looked up in your `I18n` translation files. In a Rails application this may look like:
|
|
506
514
|
|
|
507
515
|
```yml
|
|
508
516
|
# config/locale/en.yml
|
|
@@ -526,7 +534,7 @@ This will work seamlessly with [rails-i18n](https://github.com/svenfuchs/rails-i
|
|
|
526
534
|
|
|
527
535
|
If you wish to disable this feature and use defaults instead:
|
|
528
536
|
|
|
529
|
-
```
|
|
537
|
+
```ruby
|
|
530
538
|
Money.locale_backend = nil
|
|
531
539
|
```
|
|
532
540
|
|
|
@@ -594,7 +602,7 @@ If you don't have some locale and don't want to get a runtime error such as:
|
|
|
594
602
|
I18n::InvalidLocale: :en is not a valid locale
|
|
595
603
|
|
|
596
604
|
Set the following:
|
|
597
|
-
```
|
|
605
|
+
```ruby
|
|
598
606
|
I18n.enforce_available_locales = false
|
|
599
607
|
```
|
|
600
608
|
|
|
@@ -602,18 +610,11 @@ I18n.enforce_available_locales = false
|
|
|
602
610
|
|
|
603
611
|
Prior to v6.9.0 heuristic analysis of string input was part of this gem. Since then it was extracted in to [money-heuristics gem](https://github.com/RubyMoney/money-heuristics).
|
|
604
612
|
|
|
605
|
-
##
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
* The first is to test your application and where applicable update the
|
|
614
|
-
application to accept a `BigDecimal` return value. This is the recommended
|
|
615
|
-
path.
|
|
616
|
-
* The second is to migrate from the `#amount` and `#dollars` methods to use
|
|
617
|
-
the `#to_f` method instead. This option should only be used where `Float`
|
|
618
|
-
is the desired type and nothing else will do for your application's
|
|
619
|
-
requirements.
|
|
613
|
+
## Upgrade Guides
|
|
614
|
+
|
|
615
|
+
When upgrading between major versions, please refer to the appropriate upgrade guide:
|
|
616
|
+
|
|
617
|
+
- **[Upgrading to 7.0](UPGRADING-7.0.md)** - Guide for migrating from 6.x to 7.0
|
|
618
|
+
- **[Upgrading to 6.0](UPGRADING-6.0.md)** - Guide for upgrading to version 6.0
|
|
619
|
+
|
|
620
|
+
These guides provide detailed information about breaking changes, new features, and step-by-step migration instructions.
|
|
@@ -31,6 +31,22 @@
|
|
|
31
31
|
"iso_numeric": "288",
|
|
32
32
|
"smallest_denomination": 1
|
|
33
33
|
},
|
|
34
|
+
"hrk": {
|
|
35
|
+
"priority": 100,
|
|
36
|
+
"iso_code": "HRK",
|
|
37
|
+
"name": "Croatian Kuna",
|
|
38
|
+
"symbol": "kn",
|
|
39
|
+
"alternate_symbols": [],
|
|
40
|
+
"subunit": "Lipa",
|
|
41
|
+
"subunit_to_unit": 100,
|
|
42
|
+
"symbol_first": false,
|
|
43
|
+
"format": "%n %u",
|
|
44
|
+
"html_entity": "",
|
|
45
|
+
"decimal_mark": ",",
|
|
46
|
+
"thousands_separator": ".",
|
|
47
|
+
"iso_numeric": "191",
|
|
48
|
+
"smallest_denomination": 1
|
|
49
|
+
},
|
|
34
50
|
"ltl": {
|
|
35
51
|
"priority": 100,
|
|
36
52
|
"iso_code": "LTL",
|
|
@@ -99,6 +115,7 @@
|
|
|
99
115
|
"iso_code": "TMM",
|
|
100
116
|
"name": "Turkmenistani Manat",
|
|
101
117
|
"symbol": "m",
|
|
118
|
+
"disambiguate_symbol": "TMM",
|
|
102
119
|
"alternate_symbols": [],
|
|
103
120
|
"subunit": "Tennesi",
|
|
104
121
|
"subunit_to_unit": 100,
|