money 6.19.0 → 7.0.2
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 +105 -47
- data/LICENSE +1 -1
- data/README.md +57 -54
- data/config/currency_backwards_compatible.json +1 -0
- data/config/currency_iso.json +42 -12
- 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 +37 -11
- 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 +27 -8
- data/lib/money/money/arithmetic.rb +49 -33
- data/lib/money/money/constructors.rb +2 -0
- data/lib/money/money/formatter.rb +14 -63
- 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 -9
- metadata +12 -74
- 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: cbdcafa7432cc94f273e6d50d820af8e6656707f9a4eb738d8ae694191d8f470
|
|
4
|
+
data.tar.gz: '093235eead41422c4804dcafde91b396c80f1b4c2d269606f2ce6287ad613871'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87ca3a9c81395fd38474dc8f46ceec7a0484054093f8aed50ff3a1358ea6214851d2fd81b165d68d94e5902e6229ad03debae12dfacab7dd043359d025f15d64
|
|
7
|
+
data.tar.gz: 8b8a0e2a12646b28b1859c226fbe3ef1b534458ec198d3cd51124263624709b7ced902ce9637e5409061ed0eefe3df67a70e159c9281ccd841e2dda1c1a0b4c1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,69 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 7.0.2
|
|
6
|
+
|
|
7
|
+
- Fix `Money::Currency.register` exception when table is not initialized.
|
|
8
|
+
|
|
9
|
+
## 7.0.1
|
|
10
|
+
|
|
11
|
+
- Re-publishing gem to fix file permissions https://github.com/RubyMoney/money/issues/1170
|
|
12
|
+
|
|
13
|
+
## 7.0.0
|
|
14
|
+
|
|
15
|
+
- **Breaking change**: Require Ruby >= 3.1 and i18n ~> 1.9
|
|
16
|
+
- **Breaking change**: Remove deprecated formatting rules:
|
|
17
|
+
- `:html`
|
|
18
|
+
- `:html_wrap_symbol`
|
|
19
|
+
- `:symbol_position`
|
|
20
|
+
- `:symbol_before_without_space`
|
|
21
|
+
- `:symbol_after_without_space`
|
|
22
|
+
- **Breaking change**: Remove deprecated methods:
|
|
23
|
+
- `Money.infinite_precision`.
|
|
24
|
+
- `Money.infinite_precision=`.
|
|
25
|
+
- `Money#currency_as_string`.
|
|
26
|
+
- `Money#currency_as_string=`.
|
|
27
|
+
- `Money.use_i18n` and `Money.use_i18n=` (use `Money.locale_backend = :i18n` instead).
|
|
28
|
+
- **Breaking change**: Remove legacy locale backend. The default locale backend is now `:currency` which uses currency definitions for formatting.
|
|
29
|
+
- **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.
|
|
30
|
+
- **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.
|
|
31
|
+
- **Potential breaking change**: Fix RSD (Serbian Dinar) formatting to be like `12.345,42 RSD`
|
|
32
|
+
- **Potential breaking change**: Fix USDC decimals places from 2 to 6
|
|
33
|
+
- **Potential breaking change**: Fix MGA (Malagasy Ariary) to be a zero-decimal currency (changing subunit_to_unit from 5 to 1)
|
|
34
|
+
- **Potential breaking change**: Remove special handling for Japanese language only
|
|
35
|
+
- **Potential breaking change**: Adjust formatting rules to use i18n translations for `:format`
|
|
36
|
+
- **Potential breaking change**: Not allow divide by zero
|
|
37
|
+
- Updated Armenian Dram sign and HTML entity
|
|
38
|
+
- Updated the Turkmen Manat symbol and HTML entity and added disambiguation symbol for TMM
|
|
39
|
+
- Expose Money::VERSION
|
|
40
|
+
- Fix typo in ILS currency
|
|
41
|
+
- Add Zimbabwe Gold (ZWG) currency
|
|
42
|
+
- Update thousands_separator for CHF
|
|
43
|
+
- Add Caribbean Guilder (XCG) as replacement for Netherlands Antillean Gulden (ANG)
|
|
44
|
+
- Add `Money.strict_eql_compare = true` so that comparing zero amounts with different currencies using `Money#eql?` returns `false`
|
|
45
|
+
```rb
|
|
46
|
+
Money.new(0, "USD").eql?(Money.new(0, "EUR")) #=> true
|
|
47
|
+
#> [DEPRECATION] Comparing 0 USD with 0 EUR using `#eql?` will return false…
|
|
48
|
+
|
|
49
|
+
Money.strict_eql_compare = true
|
|
50
|
+
Money.new(0, "USD").eql?(Money.new(0, "EUR")) #=> false
|
|
51
|
+
```
|
|
52
|
+
- Add `Money#to_nearest_cash_value` to return a rounded Money instance to the smallest denomination
|
|
53
|
+
- Deprecate `Money#round_to_nearest_cash_value` in favor of calling `to_nearest_cash_value.fractional`
|
|
54
|
+
- Deprecate `Money#dollars` in favor of `Money#amount`.
|
|
55
|
+
- Deprecate `Money.from_dollars` in favor of `Money.from_amount`.
|
|
56
|
+
- Add `Money::Currency#cents_based?` to check if currency is cents-based
|
|
57
|
+
- Add ability to nest `Money.with_rounding_mode` blocks
|
|
58
|
+
- Allow `nil` to be used as a default_currency
|
|
59
|
+
- Improve performance of `find_by_iso_numeric` method
|
|
60
|
+
- Add ability to nest `Money.with_bank` blocks
|
|
61
|
+
- 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.
|
|
6
62
|
|
|
7
63
|
## 6.19.0
|
|
8
64
|
|
|
9
65
|
- Change Peruvian Sol (PEN) decimal mark and thousands separator.
|
|
66
|
+
- Fix deprecation warning for BigDecimal being moved out from stdlib.
|
|
10
67
|
- Improves Precision and Simplifies Allocation Logic
|
|
11
68
|
- explicit declaration of i18n locales
|
|
12
69
|
- Add space to CHF format
|
|
@@ -15,6 +72,7 @@
|
|
|
15
72
|
## 6.18.0
|
|
16
73
|
|
|
17
74
|
- Add second dobra (STN) from São Tomé and Príncipe
|
|
75
|
+
- Add Sierra Leonean (new) leone (SLE) from Sierra Leone
|
|
18
76
|
- Correct South African Rand (ZAR) to use comma decimal mark, and space thousands separator
|
|
19
77
|
- Use euro symbol as html_entity for euro currency
|
|
20
78
|
- Update Georgian Lari symbol
|
|
@@ -211,7 +269,7 @@
|
|
|
211
269
|
return `nil` as `Comparable#==` will not rescue exceptions in the next release.
|
|
212
270
|
- Fix `Currency` specs for `#exponent` and `#decimal_places` not making assertions.
|
|
213
271
|
- Fix a couple of Ruby warnings found in specs.
|
|
214
|
-
- Fix `Money#-`,`Money#+`
|
|
272
|
+
- Fix `Money#-`,`Money#+` arithmetic for Ruby 2.3+ : check for zero value without using eql? with a Fixnum. (#577)
|
|
215
273
|
- Use `Money#decimal_mark` when formatting with `rounded_infinite_precision` rule
|
|
216
274
|
set to `true`.
|
|
217
275
|
- Replaced meta-defined `thousands_separator` and `decimal_mark` methods with regular methods. (#579)
|
|
@@ -258,7 +316,7 @@
|
|
|
258
316
|
- Fix formatting of NGN - show symbol before amount
|
|
259
317
|
- Switch default and alternate symbols for RUB currency
|
|
260
318
|
- Fix symbol for TRY currency
|
|
261
|
-
- Add `Money.default_formatting_rules` hash, meant to define default rules for
|
|
319
|
+
- 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
|
|
262
320
|
- Add support for the new official symbol for Russian Ruble (RUB) — «₽»
|
|
263
321
|
|
|
264
322
|
## 6.2.1
|
|
@@ -427,7 +485,7 @@ Features
|
|
|
427
485
|
|
|
428
486
|
Bugfixes
|
|
429
487
|
--------
|
|
430
|
-
- EEK currency is no longer used, kept for BC ([#issue/110](
|
|
488
|
+
- EEK currency is no longer used, kept for BC ([#issue/110](https://github.com/RubyMoney/money/issues/110))
|
|
431
489
|
- Lithuanian Litas symbol position fixed (laurynas)
|
|
432
490
|
- Fixed README typos (phlipper)
|
|
433
491
|
- Fixed README typos (pwim)
|
|
@@ -553,11 +611,11 @@ Bugfixes
|
|
|
553
611
|
--------
|
|
554
612
|
- Updated Money#to_s to respect :separator and :subunit_to_unit.
|
|
555
613
|
- Fixed Money#format for :subunit_to_unit != 100.
|
|
556
|
-
([#issue/37](
|
|
614
|
+
([#issue/37](https://github.com/RubyMoney/money/issues/37))
|
|
557
615
|
- Fixed String#to_money for :subunit_to_unit != 100.
|
|
558
|
-
([#issue/36](
|
|
616
|
+
([#issue/36](https://github.com/RubyMoney/money/issues/36))
|
|
559
617
|
- Removed duplicate currencies.
|
|
560
|
-
([#issue/38](
|
|
618
|
+
([#issue/38](https://github.com/RubyMoney/money/issues/38))
|
|
561
619
|
- Fixed issue related to JRuby returning 2 for Math.log10(1000).floor instead
|
|
562
620
|
of correctly returning 3.
|
|
563
621
|
|
|
@@ -568,22 +626,22 @@ Features
|
|
|
568
626
|
--------
|
|
569
627
|
- Added support for creating objects with the main monetary unit instead of
|
|
570
628
|
cents.
|
|
571
|
-
([#issue/25](
|
|
629
|
+
([#issue/25](https://github.com/RubyMoney/money/issues/25))
|
|
572
630
|
- Deprecated `Money#format` with separate params instead of Hash. Deprecation
|
|
573
631
|
target set to Money 3.5.0.
|
|
574
|
-
([#issue/31](
|
|
632
|
+
([#issue/31](https://github.com/RubyMoney/money/issues/31))
|
|
575
633
|
- Deprecated `Money#new(0, currency: "EUR")` in favor of
|
|
576
634
|
`Money#new(0, "EUR")`. Deprecation target set to Money 3.5.0.
|
|
577
|
-
([#issue/31](
|
|
635
|
+
([#issue/31](https://github.com/RubyMoney/money/issues/31))
|
|
578
636
|
- Throw ArgumentError when trying to multiply two Money objects together.
|
|
579
|
-
([#issue/29](
|
|
637
|
+
([#issue/29](https://github.com/RubyMoney/money/issues/29))
|
|
580
638
|
- Update Money#parse to use :subunit_to_unit
|
|
581
|
-
([#issue/30](
|
|
639
|
+
([#issue/30](https://github.com/RubyMoney/money/issues/30))
|
|
582
640
|
|
|
583
641
|
Bugfixes
|
|
584
642
|
--------
|
|
585
643
|
- Downgraded required_rubygems_version to >= 1.3.6.
|
|
586
|
-
([#issue/26](
|
|
644
|
+
([#issue/26](https://github.com/RubyMoney/money/issues/26))
|
|
587
645
|
- Use BigDecimal when floating point calculations are needed.
|
|
588
646
|
- Ruby 1.9.2 compatibility enhancements.
|
|
589
647
|
|
|
@@ -593,32 +651,32 @@ Money 3.1.0
|
|
|
593
651
|
Features
|
|
594
652
|
--------
|
|
595
653
|
- Implemented `Money::Bank::Base`.
|
|
596
|
-
([#issue/14](
|
|
654
|
+
([#issue/14](https://github.com/RubyMoney/money/issues/14))
|
|
597
655
|
- Added `Money::Bank::Base#exchange_with`.
|
|
598
656
|
- Deprecated `Money::Bank::Base#exchange`. Deprecation target set to Money
|
|
599
657
|
3.2.0.
|
|
600
|
-
-
|
|
658
|
+
- Implemented `Money::Bank::VariableExchange`
|
|
601
659
|
- Deprecated `Money::VariableExchangeBank`. Deprecation target set to Money
|
|
602
660
|
3.2.0.
|
|
603
661
|
- Deprecate `Money::SYMBOLS`, `Money::SEPARATORS` and `Money::DELIMITERS`.
|
|
604
662
|
Deprecation target set to Money 3.2.0.
|
|
605
|
-
([#issue/16](
|
|
663
|
+
([#issue/16](https://github.com/RubyMoney/money/issues/16))
|
|
606
664
|
- Implemented `#has` for `Money` and `Money::Currency`.
|
|
607
665
|
- Refactored test suite to conform to RSpec conventions.
|
|
608
|
-
- Moved project from [FooBarWidget](
|
|
609
|
-
[RubyMoney](
|
|
666
|
+
- Moved project from [FooBarWidget](https://github.com/FooBarWidget) to
|
|
667
|
+
[RubyMoney](https://github.com/RubyMoney)
|
|
610
668
|
- Added Simone Carletti to list of authors.
|
|
611
669
|
- Moved `@rounding_method` from `Money::Bank::VariableExchange` to
|
|
612
670
|
`Money::Bank::Base`.
|
|
613
|
-
([#issue/18](
|
|
671
|
+
([#issue/18](https://github.com/RubyMoney/money/issues/18))
|
|
614
672
|
- Added `#setup` to `Money::Bank::Base`. Called from `#initialize`.
|
|
615
|
-
([#issue/19](
|
|
616
|
-
- Added [google_currency](
|
|
673
|
+
([#issue/19](https://github.com/RubyMoney/money/issues/19))
|
|
674
|
+
- Added [google_currency](https://github.com/RubyMoney/google_currency) to list
|
|
617
675
|
of Currency Exchange Implementations.
|
|
618
676
|
- Added `#export_rates` to `Money::Bank::VariableExchange`.
|
|
619
|
-
([#issue/21](
|
|
677
|
+
([#issue/21](https://github.com/RubyMoney/money/issues/21))
|
|
620
678
|
- Added `#import_rates` to `Money::Bank::VariableExchange`.
|
|
621
|
-
([#issue/21](
|
|
679
|
+
([#issue/21](https://github.com/RubyMoney/money/issues/21))
|
|
622
680
|
- Removed dependency on Jeweler.
|
|
623
681
|
- Replaced usage of hanna with yardoc.
|
|
624
682
|
- Rewrote/reformatted all documentation.
|
|
@@ -626,30 +684,30 @@ Features
|
|
|
626
684
|
Bugfixes
|
|
627
685
|
--------
|
|
628
686
|
- Fixed incorrect URLs in documentation.
|
|
629
|
-
([#issue/17](
|
|
687
|
+
([#issue/17](https://github.com/RubyMoney/money/issues/17))
|
|
630
688
|
- Updated `:subunit_to_unit` for HKD from 10 to 100.
|
|
631
|
-
([#issue/20](
|
|
689
|
+
([#issue/20](https://github.com/RubyMoney/money/issues/20))
|
|
632
690
|
- Updated Ghanaian Cedi to use correct ISO Code, GHS.
|
|
633
|
-
([#issue/22](
|
|
691
|
+
([#issue/22](https://github.com/RubyMoney/money/issues/22))
|
|
634
692
|
- Make `default` rake task call `spec`.
|
|
635
|
-
([#issue/23](
|
|
693
|
+
([#issue/23](https://github.com/RubyMoney/money/issues/23))
|
|
636
694
|
|
|
637
695
|
Money 3.1.0.pre3
|
|
638
696
|
================
|
|
639
697
|
|
|
640
698
|
Features
|
|
641
699
|
--------
|
|
642
|
-
- Added [google_currency](
|
|
700
|
+
- Added [google_currency](https://github.com/RubyMoney/google_currency) to list
|
|
643
701
|
of Currency Exchange Implementations.
|
|
644
702
|
- Added `#export_rates` to `Money::Bank::VariableExchange`.
|
|
645
|
-
([#issue/21](
|
|
703
|
+
([#issue/21](https://github.com/RubyMoney/money/issues/21))
|
|
646
704
|
- Added `#import_rates` to `Money::Bank::VariableExchange`.
|
|
647
|
-
([#issue/21](
|
|
705
|
+
([#issue/21](https://github.com/RubyMoney/money/issues/21))
|
|
648
706
|
|
|
649
707
|
Bugfixes
|
|
650
708
|
--------
|
|
651
709
|
- Updated `:subunit_to_unit` for HKD from 10 to 100.
|
|
652
|
-
([#issue/20](
|
|
710
|
+
([#issue/20](https://github.com/RubyMoney/money/issues/20))
|
|
653
711
|
|
|
654
712
|
Money 3.1.0.pre2
|
|
655
713
|
================
|
|
@@ -658,14 +716,14 @@ Features
|
|
|
658
716
|
--------
|
|
659
717
|
- Moved `@rounding_method` from `Money::Bank::VariableExchange` to
|
|
660
718
|
`Money::Bank::Base`.
|
|
661
|
-
([#issue/18](
|
|
719
|
+
([#issue/18](https://github.com/RubyMoney/money/issues/18))
|
|
662
720
|
- Added `#setup` to `Money::Bank::Base`. Called from `#initialize`.
|
|
663
|
-
([#issue/19](
|
|
721
|
+
([#issue/19](https://github.com/RubyMoney/money/issues/19))
|
|
664
722
|
|
|
665
723
|
Bugfixes
|
|
666
724
|
--------
|
|
667
725
|
- Fixed incorrect URLs in documentation.
|
|
668
|
-
([#issue/17](
|
|
726
|
+
([#issue/17](https://github.com/RubyMoney/money/issues/17))
|
|
669
727
|
|
|
670
728
|
Money 3.1.0.pre1
|
|
671
729
|
================
|
|
@@ -673,26 +731,26 @@ Money 3.1.0.pre1
|
|
|
673
731
|
Features
|
|
674
732
|
--------
|
|
675
733
|
- Implemented `Money::Bank::Base`.
|
|
676
|
-
([#issue/14](
|
|
734
|
+
([#issue/14](https://github.com/RubyMoney/money/issues/14))
|
|
677
735
|
- Added `Money::Bank::Base#exchange_with`.
|
|
678
736
|
- Deprecated `Money::Bank::Base#exchange`. Deprecation target set to Money
|
|
679
737
|
3.2.0.
|
|
680
|
-
-
|
|
738
|
+
- Implemented `Money::Bank::VariableExchange`
|
|
681
739
|
- Deprecated `Money::VariableExchangeBank`. Deprecation target set to Money
|
|
682
740
|
3.2.0.
|
|
683
741
|
- Deprecate `Money::SYMBOLS`, `Money::SEPARATORS` and `Money::DELIMITERS`.
|
|
684
742
|
Deprecation target set to Money 3.2.0.
|
|
685
|
-
([#issue/16](
|
|
743
|
+
([#issue/16](https://github.com/RubyMoney/money/issues/16))
|
|
686
744
|
- Implemented `#has` for `Money` and `Money::Currency`.
|
|
687
745
|
- Refactored test suite to conform to RSpec conventions.
|
|
688
|
-
- Moved project from [FooBarWidget](
|
|
689
|
-
[RubyMoney](
|
|
746
|
+
- Moved project from [FooBarWidget](https://github.com/FooBarWidget) to
|
|
747
|
+
[RubyMoney](https://github.com/RubyMoney)
|
|
690
748
|
- Added Simone Carletti to list of authors.
|
|
691
749
|
|
|
692
750
|
Bugfixes
|
|
693
751
|
--------
|
|
694
752
|
- Fixed rounding error in `Numeric#to_money`.
|
|
695
|
-
([#issue/15](
|
|
753
|
+
([#issue/15](https://github.com/RubyMoney/money/issues/15))
|
|
696
754
|
|
|
697
755
|
Money 3.0.5
|
|
698
756
|
===========
|
|
@@ -703,11 +761,11 @@ Features
|
|
|
703
761
|
- Added ability to pass a block to `VariableExchangeBank#new` or `#exchange`,
|
|
704
762
|
specifying a custom truncation method
|
|
705
763
|
- Added optional `currency` argument to` Numeric#to_money`.
|
|
706
|
-
([#issue/11](
|
|
764
|
+
([#issue/11](https://github.com/RubyMoney/money/issues/11))
|
|
707
765
|
- Added optional `currency` argument to `String#to_money`.
|
|
708
|
-
([#issue/11](
|
|
766
|
+
([#issue/11](https://github.com/RubyMoney/money/issues/11))
|
|
709
767
|
- Use '¤' as the default currency symbol.
|
|
710
|
-
([#issue/10](
|
|
768
|
+
([#issue/10](https://github.com/RubyMoney/money/issues/10))
|
|
711
769
|
|
|
712
770
|
Bugfixes
|
|
713
771
|
--------
|
|
@@ -716,7 +774,7 @@ Bugfixes
|
|
|
716
774
|
- Fixed issue when exchanging currencies with different `:subunit_to_unit`
|
|
717
775
|
values.
|
|
718
776
|
- `Numeric#to_money` now respects `:subunit_to_unit`.
|
|
719
|
-
([#issue/12](
|
|
777
|
+
([#issue/12](https://github.com/RubyMoney/money/issues/12))
|
|
720
778
|
|
|
721
779
|
Money 3.0.4
|
|
722
780
|
===========
|
|
@@ -763,7 +821,7 @@ Features
|
|
|
763
821
|
--------
|
|
764
822
|
- Version Bump due to compatibility changes with ActiveRecord. See
|
|
765
823
|
conversation
|
|
766
|
-
[here](
|
|
824
|
+
[here](https://github.com/RubyMoney/money/issues/4#issuecomment-224880)
|
|
767
825
|
for more information.
|
|
768
826
|
|
|
769
827
|
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
|
-
|
|
8
|
+
⚠️ 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,7 +54,7 @@ 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
|
|
|
63
60
|
# explicitly define locales
|
|
@@ -105,7 +102,7 @@ Currencies are consistently represented as instances of `Money::Currency`.
|
|
|
105
102
|
The most part of `Money` APIs allows you to supply either a `String` or a
|
|
106
103
|
`Money::Currency`.
|
|
107
104
|
|
|
108
|
-
```
|
|
105
|
+
```ruby
|
|
109
106
|
Money.from_cents(1000, "USD") == Money.from_cents(1000, Money::Currency.new("USD"))
|
|
110
107
|
Money.from_cents(1000, "EUR").currency == Money::Currency.new("EUR")
|
|
111
108
|
```
|
|
@@ -113,16 +110,17 @@ Money.from_cents(1000, "EUR").currency == Money::Currency.new("EUR")
|
|
|
113
110
|
A `Money::Currency` instance holds all the information about the currency,
|
|
114
111
|
including the currency symbol, name and much more.
|
|
115
112
|
|
|
116
|
-
```
|
|
113
|
+
```ruby
|
|
117
114
|
currency = Money.from_cents(1000, "USD").currency
|
|
118
|
-
currency.iso_code
|
|
119
|
-
currency.name
|
|
115
|
+
currency.iso_code #=> "USD"
|
|
116
|
+
currency.name #=> "United States Dollar"
|
|
117
|
+
currency.cents_based? #=> true
|
|
120
118
|
```
|
|
121
119
|
|
|
122
120
|
To define a new `Money::Currency` use `Money::Currency.register` as shown
|
|
123
121
|
below.
|
|
124
122
|
|
|
125
|
-
```
|
|
123
|
+
```ruby
|
|
126
124
|
curr = {
|
|
127
125
|
priority: 1,
|
|
128
126
|
iso_code: "USD",
|
|
@@ -166,7 +164,7 @@ selector like the one available
|
|
|
166
164
|
custom methods to return the list of major currencies and all currencies as
|
|
167
165
|
follows:
|
|
168
166
|
|
|
169
|
-
```
|
|
167
|
+
```ruby
|
|
170
168
|
# Returns an array of currency id where
|
|
171
169
|
# priority < 10
|
|
172
170
|
def major_currencies(hash)
|
|
@@ -194,23 +192,22 @@ all_currencies(Money::Currency.table)
|
|
|
194
192
|
|
|
195
193
|
### Default Currency
|
|
196
194
|
|
|
197
|
-
|
|
198
|
-
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:
|
|
199
196
|
|
|
200
|
-
```
|
|
197
|
+
```ruby
|
|
201
198
|
Money.default_currency = Money::Currency.new("CAD")
|
|
202
199
|
```
|
|
203
200
|
|
|
204
|
-
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.
|
|
205
202
|
|
|
206
203
|
### Currency Exponent
|
|
207
204
|
|
|
208
205
|
The exponent of a money value is the number of digits after the decimal
|
|
209
206
|
separator (which separates the major unit from the minor unit). See e.g.
|
|
210
|
-
[ISO 4217](https://www.
|
|
207
|
+
[ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) for more
|
|
211
208
|
information. You can find the exponent (as an `Integer`) by
|
|
212
209
|
|
|
213
|
-
```
|
|
210
|
+
```ruby
|
|
214
211
|
Money::Currency.new("USD").exponent # => 2
|
|
215
212
|
Money::Currency.new("JPY").exponent # => 0
|
|
216
213
|
Money::Currency.new("MGA").exponent # => 1
|
|
@@ -220,7 +217,7 @@ Money::Currency.new("MGA").exponent # => 1
|
|
|
220
217
|
|
|
221
218
|
To find a given currency by ISO 4217 numeric code (three digits) you can do
|
|
222
219
|
|
|
223
|
-
```
|
|
220
|
+
```ruby
|
|
224
221
|
Money::Currency.find_by_iso_numeric(978) #=> Money::Currency.new(:eur)
|
|
225
222
|
```
|
|
226
223
|
|
|
@@ -230,7 +227,7 @@ Exchanging money is performed through an exchange bank object. The default
|
|
|
230
227
|
exchange bank object requires one to manually specify the exchange rate. Here's
|
|
231
228
|
an example of how it works:
|
|
232
229
|
|
|
233
|
-
```
|
|
230
|
+
```ruby
|
|
234
231
|
Money.add_rate("USD", "CAD", 1.24515)
|
|
235
232
|
Money.add_rate("CAD", "USD", 0.803115)
|
|
236
233
|
|
|
@@ -240,7 +237,7 @@ Money.ca_dollar(100).exchange_to("USD") # => Money.from_cents(80, "USD")
|
|
|
240
237
|
|
|
241
238
|
Comparison and arithmetic operations work as expected:
|
|
242
239
|
|
|
243
|
-
```
|
|
240
|
+
```ruby
|
|
244
241
|
Money.from_cents(1000, "USD") <=> Money.from_cents(900, "USD") # => 1; 9.00 USD is smaller
|
|
245
242
|
Money.from_cents(1000, "EUR") + Money.from_cents(10, "EUR") == Money.from_cents(1010, "EUR")
|
|
246
243
|
|
|
@@ -348,14 +345,13 @@ end
|
|
|
348
345
|
The following example implements a `Redis` store to save exchange rates to a redis database.
|
|
349
346
|
|
|
350
347
|
```ruby
|
|
351
|
-
|
|
352
348
|
class RedisRateStore
|
|
353
349
|
INDEX_KEY_SEPARATOR = '_TO_'.freeze
|
|
354
|
-
|
|
350
|
+
|
|
355
351
|
# Using second db of the redis instance
|
|
356
352
|
# because sidekiq uses the first db
|
|
357
353
|
REDIS_DATABASE = 1
|
|
358
|
-
|
|
354
|
+
|
|
359
355
|
# Using Hash to store rates data
|
|
360
356
|
REDIS_STORE_KEY = 'rates'
|
|
361
357
|
|
|
@@ -410,9 +406,9 @@ Money.from_cents(1000, 'USD').exchange_to('CAD') #=> #<Money fractional:900 curr
|
|
|
410
406
|
```
|
|
411
407
|
|
|
412
408
|
There is nothing stopping you from creating store objects which scrapes
|
|
413
|
-
[XE](
|
|
409
|
+
[XE](https://www.xe.com) for the current rates or just returns `rand(2)`:
|
|
414
410
|
|
|
415
|
-
```
|
|
411
|
+
```ruby
|
|
416
412
|
Money.default_bank = Money::Bank::VariableExchange.new(StoreWhichScrapesXeDotCom.new)
|
|
417
413
|
```
|
|
418
414
|
|
|
@@ -426,7 +422,7 @@ Money.default_bank = MyCustomBank.new(Money::RatesStore::Memory.new)
|
|
|
426
422
|
If you wish to disable automatic currency conversion to prevent arithmetic when
|
|
427
423
|
currencies don't match:
|
|
428
424
|
|
|
429
|
-
```
|
|
425
|
+
```ruby
|
|
430
426
|
Money.disallow_currency_conversion!
|
|
431
427
|
```
|
|
432
428
|
|
|
@@ -448,15 +444,21 @@ implementations.
|
|
|
448
444
|
|
|
449
445
|
## Formatting
|
|
450
446
|
|
|
451
|
-
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).
|
|
452
448
|
|
|
453
|
-
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:
|
|
454
450
|
|
|
455
451
|
```ruby
|
|
456
452
|
m = Money.from_cents('123', :gbp) # => #<Money fractional:123 currency:GBP>
|
|
457
453
|
m.format(symbol: m.currency.to_s + ' ') # => "GBP 1.23"
|
|
458
454
|
```
|
|
459
455
|
|
|
456
|
+
If you would like to customize currency symbols to avoid ambiguity between currencies, you can:
|
|
457
|
+
|
|
458
|
+
```ruby
|
|
459
|
+
Money::Currency.table[:hkd][:symbol] = 'HK$'
|
|
460
|
+
```
|
|
461
|
+
|
|
460
462
|
## Rounding
|
|
461
463
|
|
|
462
464
|
By default, `Money` objects are rounded to the nearest cent and the additional precision is not preserved:
|
|
@@ -474,23 +476,31 @@ Money.from_amount(2.34567).format #=> "$2.34567"
|
|
|
474
476
|
|
|
475
477
|
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.
|
|
476
478
|
|
|
477
|
-
```
|
|
479
|
+
```ruby
|
|
478
480
|
# Float
|
|
479
481
|
2.34567.round #=> 2
|
|
480
482
|
2.34567.round(2) #=> 2.35
|
|
481
483
|
|
|
482
484
|
# Money
|
|
483
485
|
Money.default_infinite_precision = true
|
|
484
|
-
Money.from_cents(2.34567).format
|
|
486
|
+
Money.from_cents(2.34567).format #=> "$0.0234567"
|
|
485
487
|
Money.from_cents(2.34567).round.format #=> "$0.02"
|
|
486
|
-
Money.from_cents(2.34567).round(BigDecimal::
|
|
488
|
+
Money.from_cents(2.34567).round(BigDecimal::ROUND_DOWN, 2).format #=> "$0.0234"
|
|
487
489
|
```
|
|
488
490
|
|
|
489
491
|
You can set the default rounding mode by passing one of the `BigDecimal` mode enumerables like so:
|
|
492
|
+
|
|
490
493
|
```ruby
|
|
491
494
|
Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
|
492
495
|
```
|
|
493
|
-
|
|
496
|
+
|
|
497
|
+
See [BigDecimal::ROUND_MODE](https://ruby-doc.org/3.4.1/gems/bigdecimal/BigDecimal.html#ROUND_MODE) for more information.
|
|
498
|
+
|
|
499
|
+
To round to the nearest cash value in currencies without small denominations:
|
|
500
|
+
|
|
501
|
+
```ruby
|
|
502
|
+
Money.from_cents(11_11, "CHF").to_nearest_cash_value.format # => "CHF 11.10"
|
|
503
|
+
```
|
|
494
504
|
|
|
495
505
|
## Ruby on Rails
|
|
496
506
|
|
|
@@ -506,7 +516,7 @@ In order to localize formatting you can use `I18n` gem:
|
|
|
506
516
|
Money.locale_backend = :i18n
|
|
507
517
|
```
|
|
508
518
|
|
|
509
|
-
With this enabled a thousands
|
|
519
|
+
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:
|
|
510
520
|
|
|
511
521
|
```yml
|
|
512
522
|
# config/locale/en.yml
|
|
@@ -530,7 +540,7 @@ This will work seamlessly with [rails-i18n](https://github.com/svenfuchs/rails-i
|
|
|
530
540
|
|
|
531
541
|
If you wish to disable this feature and use defaults instead:
|
|
532
542
|
|
|
533
|
-
```
|
|
543
|
+
```ruby
|
|
534
544
|
Money.locale_backend = nil
|
|
535
545
|
```
|
|
536
546
|
|
|
@@ -598,7 +608,7 @@ If you don't have some locale and don't want to get a runtime error such as:
|
|
|
598
608
|
I18n::InvalidLocale: :en is not a valid locale
|
|
599
609
|
|
|
600
610
|
Set the following:
|
|
601
|
-
```
|
|
611
|
+
```ruby
|
|
602
612
|
I18n.enforce_available_locales = false
|
|
603
613
|
```
|
|
604
614
|
|
|
@@ -606,18 +616,11 @@ I18n.enforce_available_locales = false
|
|
|
606
616
|
|
|
607
617
|
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).
|
|
608
618
|
|
|
609
|
-
##
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
* The first is to test your application and where applicable update the
|
|
618
|
-
application to accept a `BigDecimal` return value. This is the recommended
|
|
619
|
-
path.
|
|
620
|
-
* The second is to migrate from the `#amount` and `#dollars` methods to use
|
|
621
|
-
the `#to_f` method instead. This option should only be used where `Float`
|
|
622
|
-
is the desired type and nothing else will do for your application's
|
|
623
|
-
requirements.
|
|
619
|
+
## Upgrade Guides
|
|
620
|
+
|
|
621
|
+
When upgrading between major versions, please refer to the appropriate upgrade guide:
|
|
622
|
+
|
|
623
|
+
- [Upgrading to 7.0](https://github.com/RubyMoney/money/blob/main/UPGRADING-7.0.md) - Guide for migrating from 6.x to 7.0
|
|
624
|
+
- [Upgrading to 6.0](https://github.com/RubyMoney/money/blob/main/UPGRADING-6.0.md) - Guide for upgrading to version 6.0
|
|
625
|
+
|
|
626
|
+
These guides provide detailed information about breaking changes, new features, and step-by-step migration instructions.
|