money 6.13.8 → 6.14.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 +3 -0
- data/README.md +10 -5
- data/config/currency_backwards_compatible.json +4 -0
- data/config/currency_iso.json +96 -3
- data/config/currency_non_iso.json +1 -0
- data/lib/money/bank/variable_exchange.rb +4 -2
- data/lib/money/currency.rb +8 -3
- data/lib/money/money.rb +52 -21
- data/lib/money/money/allocation.rb +7 -1
- data/lib/money/money/arithmetic.rb +15 -10
- data/lib/money/money/formatting_rules.rb +2 -0
- data/lib/money/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e355db8bf8840c00422e9dd38b20dd86f0e8b64d495f4070d4ca1871cb83a6b
|
4
|
+
data.tar.gz: 2ad4f5c341ef5302ed3a7d14f094ad941a64c12473a6bf8b0f796dd096734130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83ad5d10e2480f8f47ad8c92a2db23c7da1a69b587e194e25ffd4d024bf124c4abced87478b1b18c1542b50df7a3daa0d44d834f1e89cfb7e6e7d233c77675f3
|
7
|
+
data.tar.gz: 5ffa2bd650dad694b048d0b648a3059750b24b60712e93224967f0b2814c0451eed8b6b3f252ccf621ca1b92d61ad1157131238a2dfa5cfa3f9b33baa05162c4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
[](https://rubygems.org/gems/money)
|
4
4
|
[](https://travis-ci.org/RubyMoney/money)
|
5
5
|
[](https://codeclimate.com/github/RubyMoney/money)
|
6
|
-
[](https://coveralls.io/r/RubyMoney/money?branch=master)
|
7
6
|
[](https://inch-ci.org/github/RubyMoney/money)
|
8
7
|
[](https://opensource.org/licenses/MIT)
|
9
8
|
|
@@ -316,11 +315,10 @@ The following example implements an `ActiveRecord` store to save exchange rates
|
|
316
315
|
```ruby
|
317
316
|
# rails g model exchange_rate from:string to:string rate:float
|
318
317
|
|
319
|
-
|
320
|
-
class ExchangeRate < ActiveRecord::Base
|
318
|
+
class ExchangeRate < ApplicationRecord
|
321
319
|
def self.get_rate(from_iso_code, to_iso_code)
|
322
320
|
rate = find_by(from: from_iso_code, to: to_iso_code)
|
323
|
-
rate
|
321
|
+
rate&.rate
|
324
322
|
end
|
325
323
|
|
326
324
|
def self.add_rate(from_iso_code, to_iso_code, rate)
|
@@ -328,6 +326,14 @@ class ExchangeRate < ActiveRecord::Base
|
|
328
326
|
exrate.rate = rate
|
329
327
|
exrate.save!
|
330
328
|
end
|
329
|
+
|
330
|
+
def self.each_rate
|
331
|
+
return find_each unless block_given?
|
332
|
+
|
333
|
+
find_each do |rate|
|
334
|
+
yield rate.from, rate.to, rate.rate
|
335
|
+
end
|
336
|
+
end
|
331
337
|
end
|
332
338
|
```
|
333
339
|
|
@@ -429,7 +435,6 @@ Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
|
429
435
|
```
|
430
436
|
See [BigDecimal::ROUND_MODE](https://ruby-doc.org/stdlib-2.5.1/libdoc/bigdecimal/rdoc/BigDecimal.html#ROUND_MODE) for more information
|
431
437
|
|
432
|
-
|
433
438
|
## Ruby on Rails
|
434
439
|
|
435
440
|
To integrate money in a Rails application use [money-rails](https://github.com/RubyMoney/money-rails).
|
@@ -8,6 +8,7 @@
|
|
8
8
|
"subunit": "Sent",
|
9
9
|
"subunit_to_unit": 100,
|
10
10
|
"symbol_first": false,
|
11
|
+
"format": "%n %u",
|
11
12
|
"html_entity": "",
|
12
13
|
"decimal_mark": ".",
|
13
14
|
"thousands_separator": ",",
|
@@ -39,6 +40,7 @@
|
|
39
40
|
"subunit": "Centas",
|
40
41
|
"subunit_to_unit": 100,
|
41
42
|
"symbol_first": false,
|
43
|
+
"format": "%n %u",
|
42
44
|
"html_entity": "",
|
43
45
|
"decimal_mark": ".",
|
44
46
|
"thousands_separator": ",",
|
@@ -70,6 +72,7 @@
|
|
70
72
|
"subunit": "Khoums",
|
71
73
|
"subunit_to_unit": 5,
|
72
74
|
"symbol_first": false,
|
75
|
+
"format": "%n %u",
|
73
76
|
"html_entity": "",
|
74
77
|
"decimal_mark": ".",
|
75
78
|
"thousands_separator": ",",
|
@@ -100,6 +103,7 @@
|
|
100
103
|
"subunit": "Tennesi",
|
101
104
|
"subunit_to_unit": 100,
|
102
105
|
"symbol_first": false,
|
106
|
+
"format": "%n %u",
|
103
107
|
"html_entity": "",
|
104
108
|
"decimal_mark": ".",
|
105
109
|
"thousands_separator": ",",
|
data/config/currency_iso.json
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
"subunit": "Fils",
|
9
9
|
"subunit_to_unit": 100,
|
10
10
|
"symbol_first": false,
|
11
|
+
"format": "%n %u",
|
11
12
|
"html_entity": "",
|
12
13
|
"decimal_mark": ".",
|
13
14
|
"thousands_separator": ",",
|
@@ -23,6 +24,7 @@
|
|
23
24
|
"subunit": "Pul",
|
24
25
|
"subunit_to_unit": 100,
|
25
26
|
"symbol_first": false,
|
27
|
+
"format": "%n %u",
|
26
28
|
"html_entity": "",
|
27
29
|
"decimal_mark": ".",
|
28
30
|
"thousands_separator": ",",
|
@@ -39,6 +41,7 @@
|
|
39
41
|
"subunit": "Qintar",
|
40
42
|
"subunit_to_unit": 100,
|
41
43
|
"symbol_first": false,
|
44
|
+
"format": "%n %u",
|
42
45
|
"html_entity": "",
|
43
46
|
"decimal_mark": ".",
|
44
47
|
"thousands_separator": ",",
|
@@ -54,6 +57,7 @@
|
|
54
57
|
"subunit": "Luma",
|
55
58
|
"subunit_to_unit": 100,
|
56
59
|
"symbol_first": false,
|
60
|
+
"format": "%n %u",
|
57
61
|
"html_entity": "",
|
58
62
|
"decimal_mark": ".",
|
59
63
|
"thousands_separator": ",",
|
@@ -84,6 +88,7 @@
|
|
84
88
|
"subunit": "Cêntimo",
|
85
89
|
"subunit_to_unit": 100,
|
86
90
|
"symbol_first": false,
|
91
|
+
"format": "%n %u",
|
87
92
|
"html_entity": "",
|
88
93
|
"decimal_mark": ".",
|
89
94
|
"thousands_separator": ",",
|
@@ -131,6 +136,7 @@
|
|
131
136
|
"subunit": "Cent",
|
132
137
|
"subunit_to_unit": 100,
|
133
138
|
"symbol_first": false,
|
139
|
+
"format": "%n %u",
|
134
140
|
"html_entity": "ƒ",
|
135
141
|
"decimal_mark": ".",
|
136
142
|
"thousands_separator": ",",
|
@@ -207,6 +213,7 @@
|
|
207
213
|
"subunit": "Stotinka",
|
208
214
|
"subunit_to_unit": 100,
|
209
215
|
"symbol_first": false,
|
216
|
+
"format": "%n %u",
|
210
217
|
"html_entity": "",
|
211
218
|
"decimal_mark": ".",
|
212
219
|
"thousands_separator": ",",
|
@@ -217,7 +224,7 @@
|
|
217
224
|
"priority": 100,
|
218
225
|
"iso_code": "BHD",
|
219
226
|
"name": "Bahraini Dinar",
|
220
|
-
"symbol": "
|
227
|
+
"symbol": "د.ب",
|
221
228
|
"alternate_symbols": ["BD"],
|
222
229
|
"subunit": "Fils",
|
223
230
|
"subunit_to_unit": 1000,
|
@@ -238,6 +245,7 @@
|
|
238
245
|
"subunit": "Centime",
|
239
246
|
"subunit_to_unit": 1,
|
240
247
|
"symbol_first": false,
|
248
|
+
"format": "%n %u",
|
241
249
|
"html_entity": "",
|
242
250
|
"decimal_mark": ".",
|
243
251
|
"thousands_separator": ",",
|
@@ -330,6 +338,7 @@
|
|
330
338
|
"subunit": "Chertrum",
|
331
339
|
"subunit_to_unit": 100,
|
332
340
|
"symbol_first": false,
|
341
|
+
"format": "%n %u",
|
333
342
|
"html_entity": "",
|
334
343
|
"decimal_mark": ".",
|
335
344
|
"thousands_separator": ",",
|
@@ -361,6 +370,7 @@
|
|
361
370
|
"subunit": "Kapeyka",
|
362
371
|
"subunit_to_unit": 100,
|
363
372
|
"symbol_first": false,
|
373
|
+
"format": "%n %u",
|
364
374
|
"html_entity": "",
|
365
375
|
"decimal_mark": ",",
|
366
376
|
"thousands_separator": " ",
|
@@ -377,6 +387,7 @@
|
|
377
387
|
"subunit": null,
|
378
388
|
"subunit_to_unit": 1,
|
379
389
|
"symbol_first": false,
|
390
|
+
"format": "%n %u",
|
380
391
|
"html_entity": "",
|
381
392
|
"decimal_mark": ",",
|
382
393
|
"thousands_separator": " ",
|
@@ -425,6 +436,7 @@
|
|
425
436
|
"subunit": "Centime",
|
426
437
|
"subunit_to_unit": 100,
|
427
438
|
"symbol_first": false,
|
439
|
+
"format": "%n %u",
|
428
440
|
"html_entity": "",
|
429
441
|
"decimal_mark": ".",
|
430
442
|
"thousands_separator": ",",
|
@@ -440,6 +452,7 @@
|
|
440
452
|
"subunit": "Rappen",
|
441
453
|
"subunit_to_unit": 100,
|
442
454
|
"symbol_first": true,
|
455
|
+
"format": "%u %n",
|
443
456
|
"html_entity": "",
|
444
457
|
"decimal_mark": ".",
|
445
458
|
"thousands_separator": ",",
|
@@ -532,6 +545,7 @@
|
|
532
545
|
"subunit": "Centavo",
|
533
546
|
"subunit_to_unit": 100,
|
534
547
|
"symbol_first": false,
|
548
|
+
"format": "%n %u",
|
535
549
|
"html_entity": "",
|
536
550
|
"decimal_mark": ".",
|
537
551
|
"thousands_separator": ",",
|
@@ -564,6 +578,7 @@
|
|
564
578
|
"subunit": "Centavo",
|
565
579
|
"subunit_to_unit": 100,
|
566
580
|
"symbol_first": false,
|
581
|
+
"format": "%n %u",
|
567
582
|
"html_entity": "",
|
568
583
|
"decimal_mark": ".",
|
569
584
|
"thousands_separator": ",",
|
@@ -579,6 +594,7 @@
|
|
579
594
|
"subunit": "Haléř",
|
580
595
|
"subunit_to_unit": 100,
|
581
596
|
"symbol_first": false,
|
597
|
+
"format": "%n %u",
|
582
598
|
"html_entity": "",
|
583
599
|
"decimal_mark": ",",
|
584
600
|
"thousands_separator": " ",
|
@@ -594,6 +610,7 @@
|
|
594
610
|
"subunit": "Centime",
|
595
611
|
"subunit_to_unit": 1,
|
596
612
|
"symbol_first": false,
|
613
|
+
"format": "%n %u",
|
597
614
|
"html_entity": "",
|
598
615
|
"decimal_mark": ".",
|
599
616
|
"thousands_separator": ",",
|
@@ -610,6 +627,7 @@
|
|
610
627
|
"subunit": "Øre",
|
611
628
|
"subunit_to_unit": 100,
|
612
629
|
"symbol_first": false,
|
630
|
+
"format": "%n %u",
|
613
631
|
"html_entity": "",
|
614
632
|
"decimal_mark": ",",
|
615
633
|
"thousands_separator": ".",
|
@@ -641,6 +659,7 @@
|
|
641
659
|
"subunit": "Centime",
|
642
660
|
"subunit_to_unit": 100,
|
643
661
|
"symbol_first": false,
|
662
|
+
"format": "%n %u",
|
644
663
|
"html_entity": "",
|
645
664
|
"decimal_mark": ".",
|
646
665
|
"thousands_separator": ",",
|
@@ -671,6 +690,7 @@
|
|
671
690
|
"subunit": "Cent",
|
672
691
|
"subunit_to_unit": 100,
|
673
692
|
"symbol_first": false,
|
693
|
+
"format": "%n %u",
|
674
694
|
"html_entity": "",
|
675
695
|
"decimal_mark": ".",
|
676
696
|
"thousands_separator": ",",
|
@@ -687,6 +707,7 @@
|
|
687
707
|
"subunit": "Santim",
|
688
708
|
"subunit_to_unit": 100,
|
689
709
|
"symbol_first": false,
|
710
|
+
"format": "%n %u",
|
690
711
|
"html_entity": "",
|
691
712
|
"decimal_mark": ".",
|
692
713
|
"thousands_separator": ",",
|
@@ -718,6 +739,7 @@
|
|
718
739
|
"subunit": "Cent",
|
719
740
|
"subunit_to_unit": 100,
|
720
741
|
"symbol_first": false,
|
742
|
+
"format": "%n %u",
|
721
743
|
"html_entity": "$",
|
722
744
|
"decimal_mark": ".",
|
723
745
|
"thousands_separator": ",",
|
@@ -734,6 +756,7 @@
|
|
734
756
|
"subunit": "Penny",
|
735
757
|
"subunit_to_unit": 100,
|
736
758
|
"symbol_first": false,
|
759
|
+
"format": "%n %u",
|
737
760
|
"html_entity": "£",
|
738
761
|
"decimal_mark": ".",
|
739
762
|
"thousands_separator": ",",
|
@@ -764,6 +787,7 @@
|
|
764
787
|
"subunit": "Tetri",
|
765
788
|
"subunit_to_unit": 100,
|
766
789
|
"symbol_first": false,
|
790
|
+
"format": "%n %u",
|
767
791
|
"html_entity": "",
|
768
792
|
"decimal_mark": ".",
|
769
793
|
"thousands_separator": ",",
|
@@ -810,6 +834,7 @@
|
|
810
834
|
"subunit": "Butut",
|
811
835
|
"subunit_to_unit": 100,
|
812
836
|
"symbol_first": false,
|
837
|
+
"format": "%n %u",
|
813
838
|
"html_entity": "",
|
814
839
|
"decimal_mark": ".",
|
815
840
|
"thousands_separator": ",",
|
@@ -826,6 +851,7 @@
|
|
826
851
|
"subunit": "Centime",
|
827
852
|
"subunit_to_unit": 1,
|
828
853
|
"symbol_first": false,
|
854
|
+
"format": "%n %u",
|
829
855
|
"html_entity": "",
|
830
856
|
"decimal_mark": ".",
|
831
857
|
"thousands_separator": ",",
|
@@ -857,6 +883,7 @@
|
|
857
883
|
"subunit": "Cent",
|
858
884
|
"subunit_to_unit": 100,
|
859
885
|
"symbol_first": false,
|
886
|
+
"format": "%n %u",
|
860
887
|
"html_entity": "$",
|
861
888
|
"decimal_mark": ".",
|
862
889
|
"thousands_separator": ",",
|
@@ -904,6 +931,7 @@
|
|
904
931
|
"subunit": "Lipa",
|
905
932
|
"subunit_to_unit": 100,
|
906
933
|
"symbol_first": false,
|
934
|
+
"format": "%n %u",
|
907
935
|
"html_entity": "",
|
908
936
|
"decimal_mark": ",",
|
909
937
|
"thousands_separator": ".",
|
@@ -919,6 +947,7 @@
|
|
919
947
|
"subunit": "Centime",
|
920
948
|
"subunit_to_unit": 100,
|
921
949
|
"symbol_first": false,
|
950
|
+
"format": "%n %u",
|
922
951
|
"html_entity": "",
|
923
952
|
"decimal_mark": ".",
|
924
953
|
"thousands_separator": ",",
|
@@ -934,6 +963,7 @@
|
|
934
963
|
"subunit": "",
|
935
964
|
"subunit_to_unit": 1,
|
936
965
|
"symbol_first": false,
|
966
|
+
"format": "%n %u",
|
937
967
|
"html_entity": "",
|
938
968
|
"decimal_mark": ",",
|
939
969
|
"thousands_separator": " ",
|
@@ -994,6 +1024,7 @@
|
|
994
1024
|
"subunit": "Fils",
|
995
1025
|
"subunit_to_unit": 1000,
|
996
1026
|
"symbol_first": false,
|
1027
|
+
"format": "%n %u",
|
997
1028
|
"html_entity": "",
|
998
1029
|
"decimal_mark": ".",
|
999
1030
|
"thousands_separator": ",",
|
@@ -1024,6 +1055,7 @@
|
|
1024
1055
|
"subunit": null,
|
1025
1056
|
"subunit_to_unit": 1,
|
1026
1057
|
"symbol_first": false,
|
1058
|
+
"format": "%n %u",
|
1027
1059
|
"html_entity": "",
|
1028
1060
|
"decimal_mark": ",",
|
1029
1061
|
"thousands_separator": ".",
|
@@ -1100,6 +1132,7 @@
|
|
1100
1132
|
"subunit": "Tyiyn",
|
1101
1133
|
"subunit_to_unit": 100,
|
1102
1134
|
"symbol_first": false,
|
1135
|
+
"format": "%n %u",
|
1103
1136
|
"html_entity": "",
|
1104
1137
|
"decimal_mark": ".",
|
1105
1138
|
"thousands_separator": ",",
|
@@ -1115,6 +1148,7 @@
|
|
1115
1148
|
"subunit": "Sen",
|
1116
1149
|
"subunit_to_unit": 100,
|
1117
1150
|
"symbol_first": false,
|
1151
|
+
"format": "%n %u",
|
1118
1152
|
"html_entity": "៛",
|
1119
1153
|
"decimal_mark": ".",
|
1120
1154
|
"thousands_separator": ",",
|
@@ -1131,6 +1165,7 @@
|
|
1131
1165
|
"subunit": "Centime",
|
1132
1166
|
"subunit_to_unit": 1,
|
1133
1167
|
"symbol_first": false,
|
1168
|
+
"format": "%n %u",
|
1134
1169
|
"html_entity": "",
|
1135
1170
|
"decimal_mark": ".",
|
1136
1171
|
"thousands_separator": ",",
|
@@ -1146,6 +1181,7 @@
|
|
1146
1181
|
"subunit": "Chŏn",
|
1147
1182
|
"subunit_to_unit": 100,
|
1148
1183
|
"symbol_first": false,
|
1184
|
+
"format": "%n %u",
|
1149
1185
|
"html_entity": "₩",
|
1150
1186
|
"decimal_mark": ".",
|
1151
1187
|
"thousands_separator": ",",
|
@@ -1207,6 +1243,7 @@
|
|
1207
1243
|
"subunit": "Tiyn",
|
1208
1244
|
"subunit_to_unit": 100,
|
1209
1245
|
"symbol_first": false,
|
1246
|
+
"format": "%n %u",
|
1210
1247
|
"html_entity": "",
|
1211
1248
|
"decimal_mark": ".",
|
1212
1249
|
"thousands_separator": ",",
|
@@ -1222,6 +1259,7 @@
|
|
1222
1259
|
"subunit": "Att",
|
1223
1260
|
"subunit_to_unit": 100,
|
1224
1261
|
"symbol_first": false,
|
1262
|
+
"format": "%n %u",
|
1225
1263
|
"html_entity": "₭",
|
1226
1264
|
"decimal_mark": ".",
|
1227
1265
|
"thousands_separator": ",",
|
@@ -1253,6 +1291,7 @@
|
|
1253
1291
|
"subunit": "Cent",
|
1254
1292
|
"subunit_to_unit": 100,
|
1255
1293
|
"symbol_first": false,
|
1294
|
+
"format": "%n %u",
|
1256
1295
|
"html_entity": "₨",
|
1257
1296
|
"decimal_mark": ".",
|
1258
1297
|
"thousands_separator": ",",
|
@@ -1269,6 +1308,7 @@
|
|
1269
1308
|
"subunit": "Cent",
|
1270
1309
|
"subunit_to_unit": 100,
|
1271
1310
|
"symbol_first": false,
|
1311
|
+
"format": "%n %u",
|
1272
1312
|
"html_entity": "$",
|
1273
1313
|
"decimal_mark": ".",
|
1274
1314
|
"thousands_separator": ",",
|
@@ -1285,6 +1325,7 @@
|
|
1285
1325
|
"subunit": "Sente",
|
1286
1326
|
"subunit_to_unit": 100,
|
1287
1327
|
"symbol_first": false,
|
1328
|
+
"format": "%n %u",
|
1288
1329
|
"html_entity": "",
|
1289
1330
|
"decimal_mark": ".",
|
1290
1331
|
"thousands_separator": ",",
|
@@ -1300,6 +1341,7 @@
|
|
1300
1341
|
"subunit": "Dirham",
|
1301
1342
|
"subunit_to_unit": 1000,
|
1302
1343
|
"symbol_first": false,
|
1344
|
+
"format": "%n %u",
|
1303
1345
|
"html_entity": "",
|
1304
1346
|
"decimal_mark": ".",
|
1305
1347
|
"thousands_separator": ",",
|
@@ -1315,6 +1357,7 @@
|
|
1315
1357
|
"subunit": "Centime",
|
1316
1358
|
"subunit_to_unit": 100,
|
1317
1359
|
"symbol_first": false,
|
1360
|
+
"format": "%n %u",
|
1318
1361
|
"html_entity": "",
|
1319
1362
|
"decimal_mark": ".",
|
1320
1363
|
"thousands_separator": ",",
|
@@ -1330,6 +1373,7 @@
|
|
1330
1373
|
"subunit": "Ban",
|
1331
1374
|
"subunit_to_unit": 100,
|
1332
1375
|
"symbol_first": false,
|
1376
|
+
"format": "%n %u",
|
1333
1377
|
"html_entity": "",
|
1334
1378
|
"decimal_mark": ".",
|
1335
1379
|
"thousands_separator": ",",
|
@@ -1360,6 +1404,7 @@
|
|
1360
1404
|
"subunit": "Deni",
|
1361
1405
|
"subunit_to_unit": 100,
|
1362
1406
|
"symbol_first": false,
|
1407
|
+
"format": "%n %u",
|
1363
1408
|
"html_entity": "",
|
1364
1409
|
"decimal_mark": ".",
|
1365
1410
|
"thousands_separator": ",",
|
@@ -1376,6 +1421,7 @@
|
|
1376
1421
|
"subunit": "Pya",
|
1377
1422
|
"subunit_to_unit": 100,
|
1378
1423
|
"symbol_first": false,
|
1424
|
+
"format": "%n %u",
|
1379
1425
|
"html_entity": "",
|
1380
1426
|
"decimal_mark": ".",
|
1381
1427
|
"thousands_separator": ",",
|
@@ -1391,6 +1437,7 @@
|
|
1391
1437
|
"subunit": "Möngö",
|
1392
1438
|
"subunit_to_unit": 100,
|
1393
1439
|
"symbol_first": false,
|
1440
|
+
"format": "%n %u",
|
1394
1441
|
"html_entity": "₮",
|
1395
1442
|
"decimal_mark": ".",
|
1396
1443
|
"thousands_separator": ",",
|
@@ -1406,6 +1453,7 @@
|
|
1406
1453
|
"subunit": "Avo",
|
1407
1454
|
"subunit_to_unit": 100,
|
1408
1455
|
"symbol_first": false,
|
1456
|
+
"format": "%n %u",
|
1409
1457
|
"html_entity": "",
|
1410
1458
|
"decimal_mark": ".",
|
1411
1459
|
"thousands_separator": ",",
|
@@ -1421,6 +1469,7 @@
|
|
1421
1469
|
"subunit": "Khoums",
|
1422
1470
|
"subunit_to_unit": 5,
|
1423
1471
|
"symbol_first": false,
|
1472
|
+
"format": "%n %u",
|
1424
1473
|
"html_entity": "",
|
1425
1474
|
"decimal_mark": ".",
|
1426
1475
|
"thousands_separator": ",",
|
@@ -1451,6 +1500,7 @@
|
|
1451
1500
|
"subunit": "Laari",
|
1452
1501
|
"subunit_to_unit": 100,
|
1453
1502
|
"symbol_first": false,
|
1503
|
+
"format": "%n %u",
|
1454
1504
|
"html_entity": "",
|
1455
1505
|
"decimal_mark": ".",
|
1456
1506
|
"thousands_separator": ",",
|
@@ -1466,6 +1516,7 @@
|
|
1466
1516
|
"subunit": "Tambala",
|
1467
1517
|
"subunit_to_unit": 100,
|
1468
1518
|
"symbol_first": false,
|
1519
|
+
"format": "%n %u",
|
1469
1520
|
"html_entity": "",
|
1470
1521
|
"decimal_mark": ".",
|
1471
1522
|
"thousands_separator": ",",
|
@@ -1528,6 +1579,7 @@
|
|
1528
1579
|
"subunit": "Cent",
|
1529
1580
|
"subunit_to_unit": 100,
|
1530
1581
|
"symbol_first": false,
|
1582
|
+
"format": "%n %u",
|
1531
1583
|
"html_entity": "$",
|
1532
1584
|
"decimal_mark": ".",
|
1533
1585
|
"thousands_separator": ",",
|
@@ -1575,6 +1627,7 @@
|
|
1575
1627
|
"subunit": "Øre",
|
1576
1628
|
"subunit_to_unit": 100,
|
1577
1629
|
"symbol_first": false,
|
1630
|
+
"format": "%n %u",
|
1578
1631
|
"html_entity": "kr",
|
1579
1632
|
"decimal_mark": ",",
|
1580
1633
|
"thousands_separator": ".",
|
@@ -1585,9 +1638,9 @@
|
|
1585
1638
|
"priority": 100,
|
1586
1639
|
"iso_code": "NPR",
|
1587
1640
|
"name": "Nepalese Rupee",
|
1588
|
-
"symbol": "
|
1641
|
+
"symbol": "Rs.",
|
1589
1642
|
"disambiguate_symbol": "NPR",
|
1590
|
-
"alternate_symbols": ["Rs", "रू"],
|
1643
|
+
"alternate_symbols": ["Rs", "रू", "₨"],
|
1591
1644
|
"subunit": "Paisa",
|
1592
1645
|
"subunit_to_unit": 100,
|
1593
1646
|
"symbol_first": true,
|
@@ -1668,6 +1721,7 @@
|
|
1668
1721
|
"subunit": "Toea",
|
1669
1722
|
"subunit_to_unit": 100,
|
1670
1723
|
"symbol_first": false,
|
1724
|
+
"format": "%n %u",
|
1671
1725
|
"html_entity": "",
|
1672
1726
|
"decimal_mark": ".",
|
1673
1727
|
"thousands_separator": ",",
|
@@ -1714,6 +1768,7 @@
|
|
1714
1768
|
"subunit": "Grosz",
|
1715
1769
|
"subunit_to_unit": 100,
|
1716
1770
|
"symbol_first": false,
|
1771
|
+
"format": "%n %u",
|
1717
1772
|
"html_entity": "zł",
|
1718
1773
|
"decimal_mark": ",",
|
1719
1774
|
"thousands_separator": " ",
|
@@ -1744,6 +1799,7 @@
|
|
1744
1799
|
"subunit": "Dirham",
|
1745
1800
|
"subunit_to_unit": 100,
|
1746
1801
|
"symbol_first": false,
|
1802
|
+
"format": "%n %u",
|
1747
1803
|
"html_entity": "﷼",
|
1748
1804
|
"decimal_mark": ".",
|
1749
1805
|
"thousands_separator": ",",
|
@@ -1759,6 +1815,7 @@
|
|
1759
1815
|
"subunit": "Bani",
|
1760
1816
|
"subunit_to_unit": 100,
|
1761
1817
|
"symbol_first": false,
|
1818
|
+
"format": "%n %u",
|
1762
1819
|
"html_entity": "",
|
1763
1820
|
"decimal_mark": ",",
|
1764
1821
|
"thousands_separator": ".",
|
@@ -1789,6 +1846,7 @@
|
|
1789
1846
|
"subunit": "Kopeck",
|
1790
1847
|
"subunit_to_unit": 100,
|
1791
1848
|
"symbol_first": false,
|
1849
|
+
"format": "%n %u",
|
1792
1850
|
"html_entity": "₽",
|
1793
1851
|
"decimal_mark": ",",
|
1794
1852
|
"thousands_separator": ".",
|
@@ -1804,6 +1862,7 @@
|
|
1804
1862
|
"subunit": "Centime",
|
1805
1863
|
"subunit_to_unit": 1,
|
1806
1864
|
"symbol_first": false,
|
1865
|
+
"format": "%n %u",
|
1807
1866
|
"html_entity": "",
|
1808
1867
|
"decimal_mark": ".",
|
1809
1868
|
"thousands_separator": ",",
|
@@ -1835,6 +1894,7 @@
|
|
1835
1894
|
"subunit": "Cent",
|
1836
1895
|
"subunit_to_unit": 100,
|
1837
1896
|
"symbol_first": false,
|
1897
|
+
"format": "%n %u",
|
1838
1898
|
"html_entity": "$",
|
1839
1899
|
"decimal_mark": ".",
|
1840
1900
|
"thousands_separator": ",",
|
@@ -1851,6 +1911,7 @@
|
|
1851
1911
|
"subunit": "Cent",
|
1852
1912
|
"subunit_to_unit": 100,
|
1853
1913
|
"symbol_first": false,
|
1914
|
+
"format": "%n %u",
|
1854
1915
|
"html_entity": "₨",
|
1855
1916
|
"decimal_mark": ".",
|
1856
1917
|
"thousands_separator": ",",
|
@@ -1883,6 +1944,7 @@
|
|
1883
1944
|
"subunit": "Öre",
|
1884
1945
|
"subunit_to_unit": 100,
|
1885
1946
|
"symbol_first": false,
|
1947
|
+
"format": "%n %u",
|
1886
1948
|
"html_entity": "",
|
1887
1949
|
"decimal_mark": ",",
|
1888
1950
|
"thousands_separator": " ",
|
@@ -1915,6 +1977,7 @@
|
|
1915
1977
|
"subunit": "Penny",
|
1916
1978
|
"subunit_to_unit": 100,
|
1917
1979
|
"symbol_first": false,
|
1980
|
+
"format": "%n %u",
|
1918
1981
|
"html_entity": "£",
|
1919
1982
|
"decimal_mark": ".",
|
1920
1983
|
"thousands_separator": ",",
|
@@ -1945,6 +2008,7 @@
|
|
1945
2008
|
"subunit": "Cent",
|
1946
2009
|
"subunit_to_unit": 100,
|
1947
2010
|
"symbol_first": false,
|
2011
|
+
"format": "%n %u",
|
1948
2012
|
"html_entity": "",
|
1949
2013
|
"decimal_mark": ".",
|
1950
2014
|
"thousands_separator": ",",
|
@@ -1960,6 +2024,7 @@
|
|
1960
2024
|
"subunit": "Cent",
|
1961
2025
|
"subunit_to_unit": 100,
|
1962
2026
|
"symbol_first": false,
|
2027
|
+
"format": "%n %u",
|
1963
2028
|
"html_entity": "",
|
1964
2029
|
"decimal_mark": ".",
|
1965
2030
|
"thousands_separator": ",",
|
@@ -1976,6 +2041,7 @@
|
|
1976
2041
|
"subunit": "Cent",
|
1977
2042
|
"subunit_to_unit": 100,
|
1978
2043
|
"symbol_first": false,
|
2044
|
+
"format": "%n %u",
|
1979
2045
|
"html_entity": "",
|
1980
2046
|
"decimal_mark": ".",
|
1981
2047
|
"thousands_separator": ",",
|
@@ -1992,6 +2058,7 @@
|
|
1992
2058
|
"subunit": "piaster",
|
1993
2059
|
"subunit_to_unit": 100,
|
1994
2060
|
"symbol_first": false,
|
2061
|
+
"format": "%n %u",
|
1995
2062
|
"html_entity": "£",
|
1996
2063
|
"decimal_mark": ".",
|
1997
2064
|
"thousands_separator": ",",
|
@@ -2007,6 +2074,7 @@
|
|
2007
2074
|
"subunit": "Cêntimo",
|
2008
2075
|
"subunit_to_unit": 100,
|
2009
2076
|
"symbol_first": false,
|
2077
|
+
"format": "%n %u",
|
2010
2078
|
"html_entity": "",
|
2011
2079
|
"decimal_mark": ".",
|
2012
2080
|
"thousands_separator": ",",
|
@@ -2037,6 +2105,7 @@
|
|
2037
2105
|
"subunit": "Piastre",
|
2038
2106
|
"subunit_to_unit": 100,
|
2039
2107
|
"symbol_first": false,
|
2108
|
+
"format": "%n %u",
|
2040
2109
|
"html_entity": "£",
|
2041
2110
|
"decimal_mark": ".",
|
2042
2111
|
"thousands_separator": ",",
|
@@ -2082,6 +2151,7 @@
|
|
2082
2151
|
"subunit": "Diram",
|
2083
2152
|
"subunit_to_unit": 100,
|
2084
2153
|
"symbol_first": false,
|
2154
|
+
"format": "%n %u",
|
2085
2155
|
"html_entity": "",
|
2086
2156
|
"decimal_mark": ".",
|
2087
2157
|
"thousands_separator": ",",
|
@@ -2097,6 +2167,7 @@
|
|
2097
2167
|
"subunit": "Tenge",
|
2098
2168
|
"subunit_to_unit": 100,
|
2099
2169
|
"symbol_first": false,
|
2170
|
+
"format": "%n %u",
|
2100
2171
|
"html_entity": "",
|
2101
2172
|
"decimal_mark": ".",
|
2102
2173
|
"thousands_separator": ",",
|
@@ -2112,6 +2183,7 @@
|
|
2112
2183
|
"subunit": "Millime",
|
2113
2184
|
"subunit_to_unit": 1000,
|
2114
2185
|
"symbol_first": false,
|
2186
|
+
"format": "%n %u",
|
2115
2187
|
"html_entity": "",
|
2116
2188
|
"decimal_mark": ".",
|
2117
2189
|
"thousands_separator": ",",
|
@@ -2158,6 +2230,7 @@
|
|
2158
2230
|
"subunit": "Cent",
|
2159
2231
|
"subunit_to_unit": 100,
|
2160
2232
|
"symbol_first": false,
|
2233
|
+
"format": "%n %u",
|
2161
2234
|
"html_entity": "$",
|
2162
2235
|
"decimal_mark": ".",
|
2163
2236
|
"thousands_separator": ",",
|
@@ -2204,6 +2277,7 @@
|
|
2204
2277
|
"subunit": "Kopiyka",
|
2205
2278
|
"subunit_to_unit": 100,
|
2206
2279
|
"symbol_first": false,
|
2280
|
+
"format": "%n %u",
|
2207
2281
|
"html_entity": "₴",
|
2208
2282
|
"decimal_mark": ".",
|
2209
2283
|
"thousands_separator": ",",
|
@@ -2219,6 +2293,7 @@
|
|
2219
2293
|
"subunit": "Cent",
|
2220
2294
|
"subunit_to_unit": 1,
|
2221
2295
|
"symbol_first": false,
|
2296
|
+
"format": "%n %u",
|
2222
2297
|
"html_entity": "",
|
2223
2298
|
"decimal_mark": ".",
|
2224
2299
|
"thousands_separator": ",",
|
@@ -2265,6 +2340,7 @@
|
|
2265
2340
|
"subunit": "Tiyin",
|
2266
2341
|
"subunit_to_unit": 100,
|
2267
2342
|
"symbol_first": false,
|
2343
|
+
"format": "%n %u",
|
2268
2344
|
"html_entity": "",
|
2269
2345
|
"decimal_mark": ".",
|
2270
2346
|
"thousands_separator": ",",
|
@@ -2295,6 +2371,7 @@
|
|
2295
2371
|
"subunit": "Hào",
|
2296
2372
|
"subunit_to_unit": 1,
|
2297
2373
|
"symbol_first": false,
|
2374
|
+
"format": "%n %u",
|
2298
2375
|
"html_entity": "₫",
|
2299
2376
|
"decimal_mark": ",",
|
2300
2377
|
"thousands_separator": ".",
|
@@ -2326,6 +2403,7 @@
|
|
2326
2403
|
"subunit": "Sene",
|
2327
2404
|
"subunit_to_unit": 100,
|
2328
2405
|
"symbol_first": false,
|
2406
|
+
"format": "%n %u",
|
2329
2407
|
"html_entity": "",
|
2330
2408
|
"decimal_mark": ".",
|
2331
2409
|
"thousands_separator": ",",
|
@@ -2342,6 +2420,7 @@
|
|
2342
2420
|
"subunit": "Centime",
|
2343
2421
|
"subunit_to_unit": 1,
|
2344
2422
|
"symbol_first": false,
|
2423
|
+
"format": "%n %u",
|
2345
2424
|
"html_entity": "",
|
2346
2425
|
"decimal_mark": ".",
|
2347
2426
|
"thousands_separator": ",",
|
@@ -2358,6 +2437,7 @@
|
|
2358
2437
|
"subunit": "oz",
|
2359
2438
|
"subunit_to_unit": 1,
|
2360
2439
|
"symbol_first": false,
|
2440
|
+
"format": "%n %u",
|
2361
2441
|
"html_entity": "",
|
2362
2442
|
"decimal_mark": ".",
|
2363
2443
|
"thousands_separator": ",",
|
@@ -2373,6 +2453,7 @@
|
|
2373
2453
|
"subunit": "oz",
|
2374
2454
|
"subunit_to_unit": 1,
|
2375
2455
|
"symbol_first": false,
|
2456
|
+
"format": "%n %u",
|
2376
2457
|
"html_entity": "",
|
2377
2458
|
"decimal_mark": ".",
|
2378
2459
|
"thousands_separator": ",",
|
@@ -2388,6 +2469,7 @@
|
|
2388
2469
|
"subunit": "",
|
2389
2470
|
"subunit_to_unit": 1,
|
2390
2471
|
"symbol_first": false,
|
2472
|
+
"format": "%n %u",
|
2391
2473
|
"html_entity": "",
|
2392
2474
|
"decimal_mark": ".",
|
2393
2475
|
"thousands_separator": ",",
|
@@ -2403,6 +2485,7 @@
|
|
2403
2485
|
"subunit": "",
|
2404
2486
|
"subunit_to_unit": 1,
|
2405
2487
|
"symbol_first": false,
|
2488
|
+
"format": "%n %u",
|
2406
2489
|
"html_entity": "",
|
2407
2490
|
"decimal_mark": ".",
|
2408
2491
|
"thousands_separator": ",",
|
@@ -2418,6 +2501,7 @@
|
|
2418
2501
|
"subunit": "",
|
2419
2502
|
"subunit_to_unit": 1,
|
2420
2503
|
"symbol_first": false,
|
2504
|
+
"format": "%n %u",
|
2421
2505
|
"html_entity": "",
|
2422
2506
|
"decimal_mark": ".",
|
2423
2507
|
"thousands_separator": ",",
|
@@ -2433,6 +2517,7 @@
|
|
2433
2517
|
"subunit": "",
|
2434
2518
|
"subunit_to_unit": 1,
|
2435
2519
|
"symbol_first": false,
|
2520
|
+
"format": "%n %u",
|
2436
2521
|
"html_entity": "",
|
2437
2522
|
"decimal_mark": ".",
|
2438
2523
|
"thousands_separator": ",",
|
@@ -2463,6 +2548,7 @@
|
|
2463
2548
|
"subunit": "",
|
2464
2549
|
"subunit_to_unit": 1,
|
2465
2550
|
"symbol_first": false,
|
2551
|
+
"format": "%n %u",
|
2466
2552
|
"html_entity": "$",
|
2467
2553
|
"decimal_mark": ".",
|
2468
2554
|
"thousands_separator": ",",
|
@@ -2478,6 +2564,7 @@
|
|
2478
2564
|
"subunit": "Centime",
|
2479
2565
|
"subunit_to_unit": 1,
|
2480
2566
|
"symbol_first": false,
|
2567
|
+
"format": "%n %u",
|
2481
2568
|
"html_entity": "",
|
2482
2569
|
"decimal_mark": ".",
|
2483
2570
|
"thousands_separator": ",",
|
@@ -2494,6 +2581,7 @@
|
|
2494
2581
|
"subunit": "oz",
|
2495
2582
|
"subunit_to_unit": 1,
|
2496
2583
|
"symbol_first": false,
|
2584
|
+
"format": "%n %u",
|
2497
2585
|
"html_entity": "",
|
2498
2586
|
"decimal_mark": ".",
|
2499
2587
|
"thousands_separator": ",",
|
@@ -2508,6 +2596,7 @@
|
|
2508
2596
|
"subunit": "Centime",
|
2509
2597
|
"subunit_to_unit": 1,
|
2510
2598
|
"symbol_first": false,
|
2599
|
+
"format": "%n %u",
|
2511
2600
|
"html_entity": "",
|
2512
2601
|
"decimal_mark": ".",
|
2513
2602
|
"thousands_separator": ",",
|
@@ -2523,6 +2612,7 @@
|
|
2523
2612
|
"subunit": "",
|
2524
2613
|
"subunit_to_unit": 1,
|
2525
2614
|
"symbol_first": false,
|
2615
|
+
"format": "%n %u",
|
2526
2616
|
"html_entity": "",
|
2527
2617
|
"decimal_mark": ".",
|
2528
2618
|
"thousands_separator": ",",
|
@@ -2538,6 +2628,7 @@
|
|
2538
2628
|
"subunit": "",
|
2539
2629
|
"subunit_to_unit": 1,
|
2540
2630
|
"symbol_first": false,
|
2631
|
+
"format": "%n %u",
|
2541
2632
|
"html_entity": "",
|
2542
2633
|
"decimal_mark": ".",
|
2543
2634
|
"thousands_separator": ",",
|
@@ -2553,6 +2644,7 @@
|
|
2553
2644
|
"subunit": "Fils",
|
2554
2645
|
"subunit_to_unit": 100,
|
2555
2646
|
"symbol_first": false,
|
2647
|
+
"format": "%n %u",
|
2556
2648
|
"html_entity": "﷼",
|
2557
2649
|
"decimal_mark": ".",
|
2558
2650
|
"thousands_separator": ",",
|
@@ -2584,6 +2676,7 @@
|
|
2584
2676
|
"subunit": "Ngwee",
|
2585
2677
|
"subunit_to_unit": 100,
|
2586
2678
|
"symbol_first": false,
|
2679
|
+
"format": "%n %u",
|
2587
2680
|
"html_entity": "",
|
2588
2681
|
"decimal_mark": ".",
|
2589
2682
|
"thousands_separator": ",",
|
@@ -113,8 +113,10 @@ class Money
|
|
113
113
|
else
|
114
114
|
if rate = get_rate(from.currency, to_currency)
|
115
115
|
fractional = calculate_fractional(from, to_currency)
|
116
|
-
from.
|
117
|
-
exchange(fractional, rate, &block),
|
116
|
+
from.dup_with(
|
117
|
+
fractional: exchange(fractional, rate, &block),
|
118
|
+
currency: to_currency,
|
119
|
+
bank: self
|
118
120
|
)
|
119
121
|
else
|
120
122
|
raise UnknownRate, "No conversion rate known for '#{from.currency.iso_code}' -> '#{to_currency}'"
|
data/lib/money/currency.rb
CHANGED
@@ -128,7 +128,7 @@ class Money
|
|
128
128
|
# @return [Array]
|
129
129
|
#
|
130
130
|
# @example
|
131
|
-
# Money::Currency.
|
131
|
+
# Money::Currency.all()
|
132
132
|
# [#<Currency ..USD>, 'CAD', 'EUR']...
|
133
133
|
def all
|
134
134
|
table.keys.map do |curr|
|
@@ -206,6 +206,10 @@ class Money
|
|
206
206
|
all.each { |c| yield(c) }
|
207
207
|
end
|
208
208
|
|
209
|
+
def reset!
|
210
|
+
@@instances = {}
|
211
|
+
@table = Loader.load_currencies
|
212
|
+
end
|
209
213
|
|
210
214
|
private
|
211
215
|
|
@@ -253,7 +257,7 @@ class Money
|
|
253
257
|
|
254
258
|
attr_reader :id, :priority, :iso_code, :iso_numeric, :name, :symbol,
|
255
259
|
:disambiguate_symbol, :html_entity, :subunit, :subunit_to_unit, :decimal_mark,
|
256
|
-
:thousands_separator, :symbol_first, :smallest_denomination
|
260
|
+
:thousands_separator, :symbol_first, :smallest_denomination, :format
|
257
261
|
|
258
262
|
alias_method :separator, :decimal_mark
|
259
263
|
alias_method :delimiter, :thousands_separator
|
@@ -341,7 +345,7 @@ class Money
|
|
341
345
|
# @example
|
342
346
|
# Money::Currency.new(:usd) #=> #<Currency id: usd ...>
|
343
347
|
def inspect
|
344
|
-
"#<#{self.class.name} id: #{id}, priority: #{priority}, symbol_first: #{symbol_first}, thousands_separator: #{thousands_separator}, html_entity: #{html_entity}, decimal_mark: #{decimal_mark}, name: #{name}, symbol: #{symbol}, subunit_to_unit: #{subunit_to_unit}, exponent: #{exponent}, iso_code: #{iso_code}, iso_numeric: #{iso_numeric}, subunit: #{subunit}, smallest_denomination: #{smallest_denomination}>"
|
348
|
+
"#<#{self.class.name} id: #{id}, priority: #{priority}, symbol_first: #{symbol_first}, thousands_separator: #{thousands_separator}, html_entity: #{html_entity}, decimal_mark: #{decimal_mark}, name: #{name}, symbol: #{symbol}, subunit_to_unit: #{subunit_to_unit}, exponent: #{exponent}, iso_code: #{iso_code}, iso_numeric: #{iso_numeric}, subunit: #{subunit}, smallest_denomination: #{smallest_denomination}, format: #{format}>"
|
345
349
|
end
|
346
350
|
|
347
351
|
# Returns a string representation corresponding to the upcase +id+
|
@@ -441,6 +445,7 @@ class Money
|
|
441
445
|
@symbol = data[:symbol]
|
442
446
|
@symbol_first = data[:symbol_first]
|
443
447
|
@thousands_separator = data[:thousands_separator]
|
448
|
+
@format = data[:format]
|
444
449
|
end
|
445
450
|
end
|
446
451
|
end
|
data/lib/money/money.rb
CHANGED
@@ -121,19 +121,27 @@ class Money
|
|
121
121
|
#
|
122
122
|
# @return [Boolean]
|
123
123
|
#
|
124
|
-
# @!attribute [rw]
|
125
|
-
#
|
126
|
-
#
|
127
|
-
# @return [Boolean]
|
124
|
+
# @!attribute [rw] default_infinite_precision
|
125
|
+
# @return [Boolean] Use this to enable infinite precision cents as the
|
126
|
+
# global default
|
128
127
|
#
|
129
128
|
# @!attribute [rw] conversion_precision
|
130
129
|
# Used to specify precision for converting Rational to BigDecimal
|
131
130
|
#
|
132
131
|
# @return [Integer]
|
133
|
-
attr_accessor :
|
134
|
-
:infinite_precision, :conversion_precision
|
135
|
-
|
132
|
+
attr_accessor :default_formatting_rules, :default_infinite_precision, :conversion_precision
|
136
133
|
attr_reader :use_i18n, :locale_backend
|
134
|
+
attr_writer :default_bank
|
135
|
+
|
136
|
+
def infinite_precision
|
137
|
+
warn '[DEPRECATION] `Money.infinite_precision` is deprecated - use `Money.default_infinite_precision` instead'
|
138
|
+
default_infinite_precision
|
139
|
+
end
|
140
|
+
|
141
|
+
def infinite_precision=(value)
|
142
|
+
warn '[DEPRECATION] `Money.infinite_precision=` is deprecated - use `Money.default_infinite_precision= ` instead'
|
143
|
+
self.default_infinite_precision = value
|
144
|
+
end
|
137
145
|
end
|
138
146
|
|
139
147
|
# @!attribute default_currency
|
@@ -160,6 +168,14 @@ class Money
|
|
160
168
|
@default_currency = currency
|
161
169
|
end
|
162
170
|
|
171
|
+
def self.default_bank
|
172
|
+
if @default_bank.respond_to?(:call)
|
173
|
+
@default_bank.call
|
174
|
+
else
|
175
|
+
@default_bank
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
163
179
|
def self.locale_backend=(value)
|
164
180
|
@locale_backend = value ? LocaleBackend.find(value) : nil
|
165
181
|
end
|
@@ -195,7 +211,7 @@ class Money
|
|
195
211
|
self.locale_backend = :legacy
|
196
212
|
|
197
213
|
# Default to not using infinite precision cents
|
198
|
-
self.
|
214
|
+
self.default_infinite_precision = false
|
199
215
|
|
200
216
|
# Default to bankers rounding
|
201
217
|
self.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
@@ -278,7 +294,8 @@ class Money
|
|
278
294
|
#
|
279
295
|
# @param [Numeric] amount The numerical value of the money.
|
280
296
|
# @param [Currency, String, Symbol] currency The currency format.
|
281
|
-
# @param [
|
297
|
+
# @param [Hash] options Optional settings for the new Money instance
|
298
|
+
# @option [Money::Bank::*] :bank The exchange bank to use.
|
282
299
|
#
|
283
300
|
# @example
|
284
301
|
# Money.from_amount(23.45, "USD") # => #<Money fractional:2345 currency:USD>
|
@@ -287,13 +304,12 @@ class Money
|
|
287
304
|
# @return [Money]
|
288
305
|
#
|
289
306
|
# @see #initialize
|
290
|
-
def self.from_amount(amount, currency = default_currency,
|
307
|
+
def self.from_amount(amount, currency = default_currency, options = {})
|
291
308
|
raise ArgumentError, "'amount' must be numeric" unless Numeric === amount
|
292
309
|
|
293
310
|
currency = Currency.wrap(currency) || Money.default_currency
|
294
311
|
value = amount.to_d * currency.subunit_to_unit
|
295
|
-
value
|
296
|
-
new(value, currency, bank)
|
312
|
+
new(value, currency, options)
|
297
313
|
end
|
298
314
|
|
299
315
|
# Creates a new Money object of value given in the
|
@@ -307,7 +323,8 @@ class Money
|
|
307
323
|
# argument, a Money will be created in that currency with fractional value
|
308
324
|
# = 0.
|
309
325
|
# @param [Currency, String, Symbol] currency The currency format.
|
310
|
-
# @param [
|
326
|
+
# @param [Hash] options Optional settings for the new Money instance
|
327
|
+
# @option [Money::Bank::*] :bank The exchange bank to use.
|
311
328
|
#
|
312
329
|
# @return [Money]
|
313
330
|
#
|
@@ -316,11 +333,17 @@ class Money
|
|
316
333
|
# Money.new(100, "USD") #=> #<Money @fractional=100 @currency="USD">
|
317
334
|
# Money.new(100, "EUR") #=> #<Money @fractional=100 @currency="EUR">
|
318
335
|
#
|
319
|
-
def initialize(obj, currency = Money.default_currency,
|
336
|
+
def initialize( obj, currency = Money.default_currency, options = {})
|
337
|
+
# For backwards compatability, if options is not a Hash, treat it as a bank parameter
|
338
|
+
unless options.is_a?(Hash)
|
339
|
+
options = { bank: options }
|
340
|
+
end
|
341
|
+
|
320
342
|
@fractional = as_d(obj.respond_to?(:fractional) ? obj.fractional : obj)
|
321
343
|
@currency = obj.respond_to?(:currency) ? obj.currency : Currency.wrap(currency)
|
322
344
|
@currency ||= Money.default_currency
|
323
|
-
@bank = obj.respond_to?(:bank) ? obj.bank : bank
|
345
|
+
@bank = obj.respond_to?(:bank) ? obj.bank : options[:bank]
|
346
|
+
@bank ||= Money.default_bank
|
324
347
|
|
325
348
|
# BigDecimal can be Infinity and NaN, money of that amount does not make sense
|
326
349
|
raise ArgumentError, 'must be initialized with a finite value' unless @fractional.finite?
|
@@ -469,7 +492,7 @@ class Money
|
|
469
492
|
if !new_currency || currency == new_currency
|
470
493
|
self
|
471
494
|
else
|
472
|
-
|
495
|
+
dup_with(currency: new_currency)
|
473
496
|
end
|
474
497
|
end
|
475
498
|
|
@@ -565,8 +588,8 @@ class Money
|
|
565
588
|
# Money.new(100, "USD").allocate(3) #=> [Money.new(34), Money.new(33), Money.new(33)]
|
566
589
|
#
|
567
590
|
def allocate(parts)
|
568
|
-
amounts = Money::Allocation.generate(fractional, parts, !Money.
|
569
|
-
amounts.map { |amount|
|
591
|
+
amounts = Money::Allocation.generate(fractional, parts, !Money.default_infinite_precision)
|
592
|
+
amounts.map { |amount| dup_with(fractional: amount) }
|
570
593
|
end
|
571
594
|
alias_method :split, :allocate
|
572
595
|
|
@@ -583,11 +606,11 @@ class Money
|
|
583
606
|
# Money.new(10.1, 'USD').round #=> Money.new(10, 'USD')
|
584
607
|
#
|
585
608
|
# @see
|
586
|
-
# Money.
|
609
|
+
# Money.default_infinite_precision
|
587
610
|
#
|
588
611
|
def round(rounding_mode = self.class.rounding_mode, rounding_precision = 0)
|
589
612
|
rounded_amount = as_d(@fractional).round(rounding_precision, rounding_mode)
|
590
|
-
|
613
|
+
dup_with(fractional: rounded_amount)
|
591
614
|
end
|
592
615
|
|
593
616
|
# Creates a formatted price string according to several rules.
|
@@ -618,6 +641,14 @@ class Money
|
|
618
641
|
Money::Formatter::DEFAULTS[:decimal_mark]
|
619
642
|
end
|
620
643
|
|
644
|
+
def dup_with(options = {})
|
645
|
+
self.class.new(
|
646
|
+
options[:fractional] || fractional,
|
647
|
+
options[:currency] || currency,
|
648
|
+
bank: options[:bank] || bank
|
649
|
+
)
|
650
|
+
end
|
651
|
+
|
621
652
|
private
|
622
653
|
|
623
654
|
def as_d(num)
|
@@ -629,7 +660,7 @@ class Money
|
|
629
660
|
end
|
630
661
|
|
631
662
|
def return_value(value)
|
632
|
-
if self.class.
|
663
|
+
if self.class.default_infinite_precision
|
633
664
|
value
|
634
665
|
else
|
635
666
|
value.round(0, self.class.rounding_mode).to_i
|
@@ -13,7 +13,13 @@ class Money
|
|
13
13
|
# Array<Numeric> — allocates the amounts proportionally to the given array
|
14
14
|
#
|
15
15
|
def self.generate(amount, parts, whole_amounts = true)
|
16
|
-
parts = parts.is_a?(Numeric)
|
16
|
+
parts = if parts.is_a?(Numeric)
|
17
|
+
Array.new(parts, 1)
|
18
|
+
elsif parts.all?(&:zero?)
|
19
|
+
Array.new(parts.count, 1)
|
20
|
+
else
|
21
|
+
parts.dup
|
22
|
+
end
|
17
23
|
|
18
24
|
raise ArgumentError, 'need at least one party' if parts.empty?
|
19
25
|
|
@@ -16,7 +16,7 @@ class Money
|
|
16
16
|
# @example
|
17
17
|
# - Money.new(100) #=> #<Money @fractional=-100>
|
18
18
|
def -@
|
19
|
-
|
19
|
+
dup_with(fractional: -fractional)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Checks whether two Money objects have the same currency and the same
|
@@ -57,7 +57,12 @@ class Money
|
|
57
57
|
return unless other.respond_to?(:zero?) && other.zero?
|
58
58
|
return other.is_a?(CoercedNumeric) ? 0 <=> fractional : fractional <=> 0
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
|
+
# Always allow comparison with zero
|
62
|
+
if zero? || other.zero?
|
63
|
+
return fractional <=> other.fractional
|
64
|
+
end
|
65
|
+
|
61
66
|
other = other.exchange_to(currency)
|
62
67
|
fractional <=> other.fractional
|
63
68
|
rescue Money::Bank::UnknownRate
|
@@ -132,10 +137,10 @@ class Money
|
|
132
137
|
when Money
|
133
138
|
other = other.exchange_to(currency)
|
134
139
|
new_fractional = fractional.public_send(op, other.fractional)
|
135
|
-
|
140
|
+
dup_with(fractional: new_fractional)
|
136
141
|
when CoercedNumeric
|
137
142
|
raise TypeError, non_zero_message.call(other.value) unless other.zero?
|
138
|
-
|
143
|
+
dup_with(fractional: other.value.public_send(op, fractional))
|
139
144
|
when Numeric
|
140
145
|
raise TypeError, non_zero_message.call(other) unless other.zero?
|
141
146
|
self
|
@@ -162,7 +167,7 @@ class Money
|
|
162
167
|
def *(value)
|
163
168
|
value = value.value if value.is_a?(CoercedNumeric)
|
164
169
|
if value.is_a? Numeric
|
165
|
-
|
170
|
+
dup_with(fractional: fractional * value)
|
166
171
|
else
|
167
172
|
raise TypeError, "Can't multiply a #{self.class.name} by a #{value.class.name}'s value"
|
168
173
|
end
|
@@ -188,7 +193,7 @@ class Money
|
|
188
193
|
fractional / as_d(value.exchange_to(currency).fractional).to_f
|
189
194
|
else
|
190
195
|
raise TypeError, 'Can not divide by Money' if value.is_a?(CoercedNumeric)
|
191
|
-
|
196
|
+
dup_with(fractional: fractional / as_d(value))
|
192
197
|
end
|
193
198
|
end
|
194
199
|
|
@@ -226,13 +231,13 @@ class Money
|
|
226
231
|
def divmod_money(val)
|
227
232
|
cents = val.exchange_to(currency).cents
|
228
233
|
quotient, remainder = fractional.divmod(cents)
|
229
|
-
[quotient,
|
234
|
+
[quotient, dup_with(fractional: remainder)]
|
230
235
|
end
|
231
236
|
private :divmod_money
|
232
237
|
|
233
238
|
def divmod_other(val)
|
234
239
|
quotient, remainder = fractional.divmod(as_d(val))
|
235
|
-
[
|
240
|
+
[dup_with(fractional: quotient), dup_with(fractional: remainder)]
|
236
241
|
end
|
237
242
|
private :divmod_other
|
238
243
|
|
@@ -276,7 +281,7 @@ class Money
|
|
276
281
|
if (fractional < 0 && val < 0) || (fractional > 0 && val > 0)
|
277
282
|
self.modulo(val)
|
278
283
|
else
|
279
|
-
self.modulo(val) - (val.is_a?(Money) ? val :
|
284
|
+
self.modulo(val) - (val.is_a?(Money) ? val : dup_with(fractional: val))
|
280
285
|
end
|
281
286
|
end
|
282
287
|
|
@@ -287,7 +292,7 @@ class Money
|
|
287
292
|
# @example
|
288
293
|
# Money.new(-100).abs #=> #<Money @fractional=100>
|
289
294
|
def abs
|
290
|
-
|
295
|
+
dup_with(fractional: fractional.abs)
|
291
296
|
end
|
292
297
|
|
293
298
|
# Test if the money amount is zero.
|
data/lib/money/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
- Anthony Dmitriyev
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -144,7 +144,7 @@ metadata:
|
|
144
144
|
changelog_uri: https://github.com/RubyMoney/money/blob/master/CHANGELOG.md
|
145
145
|
source_code_uri: https://github.com/RubyMoney/money/
|
146
146
|
bug_tracker_uri: https://github.com/RubyMoney/money/issues
|
147
|
-
post_install_message:
|
147
|
+
post_install_message:
|
148
148
|
rdoc_options: []
|
149
149
|
require_paths:
|
150
150
|
- lib
|
@@ -159,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
163
|
-
signing_key:
|
162
|
+
rubygems_version: 3.0.3
|
163
|
+
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: A Ruby Library for dealing with money and currency conversion.
|
166
166
|
test_files: []
|