money 6.3.0 → 6.4.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/.gitignore +3 -0
- data/AUTHORS +4 -0
- data/CHANGELOG.md +7 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/config/currency_backwards_compatible.json +6 -0
- data/config/currency_iso.json +71 -11
- data/config/currency_non_iso.json +1 -0
- data/lib/money/currency.rb +3 -1
- data/lib/money/money.rb +24 -8
- data/lib/money/money/formatting.rb +26 -6
- data/lib/money/version.rb +1 -1
- data/money.gemspec +1 -1
- data/spec/money/formatting_spec.rb +80 -6
- data/spec/money_spec.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b17085ec48ad637f79d50632f0f33a940e17a22
|
4
|
+
data.tar.gz: 76f462a0d1b62562694324fb4f97d96d5c101765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd0bc7415006f620e9e5bea076d2248d63353c82cca3ca11e8c3c29ab6420b1ed6163b6042cc743035a017be2178f48ba07014594edda8b1e4ee3d133949d399
|
7
|
+
data.tar.gz: 742631af8dff373d776438ce74d99ac01437387046e87cb8a3ef68498fc3d2fe64860a4f9d6280fb70ccc4c94df8fb3c0b84e0ff4a4e5f6ca115e6d5beb4892a
|
data/.gitignore
CHANGED
data/AUTHORS
CHANGED
@@ -29,6 +29,7 @@ Exoth
|
|
29
29
|
François Beausoleil
|
30
30
|
François Klingler
|
31
31
|
Francisco Trindade
|
32
|
+
Gabriel Gilder
|
32
33
|
Gee-Hsien Chuang
|
33
34
|
Hakan Ensari
|
34
35
|
Hongli Lai
|
@@ -56,6 +57,7 @@ kirillian
|
|
56
57
|
Laurynas Butkus
|
57
58
|
Marcel Scherf
|
58
59
|
Marco Otte-Witte
|
60
|
+
Mateus Gomes
|
59
61
|
Mateusz Wolsza
|
60
62
|
Matias Korhonen
|
61
63
|
Matt Jankowski
|
@@ -90,6 +92,7 @@ Shane Emmons
|
|
90
92
|
Simone Carletti
|
91
93
|
Spencer Rinehart
|
92
94
|
Steve Morris
|
95
|
+
Yok
|
93
96
|
Thomas E Enebo
|
94
97
|
Thomas Weymuth
|
95
98
|
Ticean Bennett
|
@@ -107,3 +110,4 @@ Tien Nguyen
|
|
107
110
|
Wei Zhu
|
108
111
|
Zubin Henner
|
109
112
|
Troels Knak-Nielsen
|
113
|
+
Edwin Vlieg
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## Next release
|
4
4
|
- Add method to round a given amount of money to the nearest possible value in cash (aka Swedish rounding).
|
5
|
+
- Fixed the subunit_to_unit values of the CLP and KRW currencies
|
6
|
+
- Add option for `disambiguate` symbols for formatting
|
7
|
+
- Fixed the subunit_to_unit values of the VND currency
|
8
|
+
- Fix formatting of NGN - show symbol before amount
|
9
|
+
- Switch default and alternate symbols for RUB currency
|
10
|
+
- Fix symbol for TRY currency
|
11
|
+
- Add `Money.default_formatting_rules` hash, meant to define default rules for everytime `Money#format` is called. They can be overwritten if provided on method call
|
5
12
|
|
6
13
|
## 6.2.1
|
7
14
|
- Ensure set is loaded
|
data/README.md
CHANGED
@@ -295,6 +295,8 @@ If you wish to disable this feature:
|
|
295
295
|
Money.use_i18n = false
|
296
296
|
```
|
297
297
|
|
298
|
+
*Note: There are several formatting rules for when `Money#format` is called. For more information, check out the [formatting module](https://github.com/RubyMoney/money/blob/master/lib/money/money/formatting.rb).*
|
299
|
+
|
298
300
|
## Migration Notes
|
299
301
|
|
300
302
|
#### Version 6.0.0
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "bundler/gem_tasks"
|
3
3
|
require "rake/clean"
|
4
|
+
require "rspec/core/rake_task"
|
4
5
|
|
5
6
|
CLOBBER.include('doc', '.yardoc')
|
6
7
|
|
@@ -9,3 +10,8 @@ require "yard"
|
|
9
10
|
YARD::Rake::YardocTask.new do |t|
|
10
11
|
t.options << "--files" << "CHANGELOG.md,LICENSE"
|
11
12
|
end
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
15
|
+
t.fail_on_error = false
|
16
|
+
end
|
17
|
+
|
@@ -19,6 +19,7 @@
|
|
19
19
|
"iso_code": "GHS",
|
20
20
|
"name": "Ghanaian Cedi",
|
21
21
|
"symbol": "₵",
|
22
|
+
"disambiguate_symbol": "GH₵",
|
22
23
|
"alternate_symbols": ["GH₵"],
|
23
24
|
"subunit": "Pesewa",
|
24
25
|
"subunit_to_unit": 100,
|
@@ -64,6 +65,7 @@
|
|
64
65
|
"iso_code": "JPY",
|
65
66
|
"name": "Japanese Yen",
|
66
67
|
"symbol": "¥",
|
68
|
+
"disambiguate_symbol": "JPY",
|
67
69
|
"alternate_symbols": ["円", "圓"],
|
68
70
|
"subunit": "Sen",
|
69
71
|
"subunit_to_unit": 100,
|
@@ -79,6 +81,7 @@
|
|
79
81
|
"iso_code": "ZWD",
|
80
82
|
"name": "Zimbabwean Dollar",
|
81
83
|
"symbol": "$",
|
84
|
+
"disambiguate_symbol": "ZWD",
|
82
85
|
"alternate_symbols": ["Z$"],
|
83
86
|
"subunit": "Cent",
|
84
87
|
"subunit_to_unit": 100,
|
@@ -94,6 +97,7 @@
|
|
94
97
|
"iso_code": "ZWL",
|
95
98
|
"name": "Zimbabwean Dollar",
|
96
99
|
"symbol": "$",
|
100
|
+
"disambiguate_symbol": "ZWL",
|
97
101
|
"alternate_symbols": ["Z$"],
|
98
102
|
"subunit": "Cent",
|
99
103
|
"subunit_to_unit": 100,
|
@@ -109,6 +113,7 @@
|
|
109
113
|
"iso_code": "ZWN",
|
110
114
|
"name": "Zimbabwean Dollar",
|
111
115
|
"symbol": "$",
|
116
|
+
"disambiguate_symbol": "ZWN",
|
112
117
|
"alternate_symbols": ["Z$"],
|
113
118
|
"subunit": "Cent",
|
114
119
|
"subunit_to_unit": 100,
|
@@ -124,6 +129,7 @@
|
|
124
129
|
"iso_code": "ZWR",
|
125
130
|
"name": "Zimbabwean Dollar",
|
126
131
|
"symbol": "$",
|
132
|
+
"disambiguate_symbol": "ZWR",
|
127
133
|
"alternate_symbols": ["Z$"],
|
128
134
|
"subunit": "Cent",
|
129
135
|
"subunit_to_unit": 100,
|
data/config/currency_iso.json
CHANGED
@@ -34,6 +34,7 @@
|
|
34
34
|
"iso_code": "ALL",
|
35
35
|
"name": "Albanian Lek",
|
36
36
|
"symbol": "L",
|
37
|
+
"disambiguate_symbol": "Lek",
|
37
38
|
"alternate_symbols": ["Lek"],
|
38
39
|
"subunit": "Qintar",
|
39
40
|
"subunit_to_unit": 100,
|
@@ -94,6 +95,7 @@
|
|
94
95
|
"iso_code": "ARS",
|
95
96
|
"name": "Argentine Peso",
|
96
97
|
"symbol": "$",
|
98
|
+
"disambiguate_symbol": "$m/n",
|
97
99
|
"alternate_symbols": ["$m/n", "m$n"],
|
98
100
|
"subunit": "Centavo",
|
99
101
|
"subunit_to_unit": 100,
|
@@ -109,6 +111,7 @@
|
|
109
111
|
"iso_code": "AUD",
|
110
112
|
"name": "Australian Dollar",
|
111
113
|
"symbol": "$",
|
114
|
+
"disambiguate_symbol": "A$",
|
112
115
|
"alternate_symbols": ["A$"],
|
113
116
|
"subunit": "Cent",
|
114
117
|
"subunit_to_unit": 100,
|
@@ -169,6 +172,7 @@
|
|
169
172
|
"iso_code": "BBD",
|
170
173
|
"name": "Barbadian Dollar",
|
171
174
|
"symbol": "$",
|
175
|
+
"disambiguate_symbol": "Bds$",
|
172
176
|
"alternate_symbols": ["Bds$"],
|
173
177
|
"subunit": "Cent",
|
174
178
|
"subunit_to_unit": 100,
|
@@ -229,6 +233,7 @@
|
|
229
233
|
"iso_code": "BIF",
|
230
234
|
"name": "Burundian Franc",
|
231
235
|
"symbol": "Fr",
|
236
|
+
"disambiguate_symbol": "FBu",
|
232
237
|
"alternate_symbols": ["FBu"],
|
233
238
|
"subunit": "Centime",
|
234
239
|
"subunit_to_unit": 100,
|
@@ -244,6 +249,7 @@
|
|
244
249
|
"iso_code": "BMD",
|
245
250
|
"name": "Bermudian Dollar",
|
246
251
|
"symbol": "$",
|
252
|
+
"disambiguate_symbol": "BD$",
|
247
253
|
"alternate_symbols": ["BD$"],
|
248
254
|
"subunit": "Cent",
|
249
255
|
"subunit_to_unit": 100,
|
@@ -259,6 +265,7 @@
|
|
259
265
|
"iso_code": "BND",
|
260
266
|
"name": "Brunei Dollar",
|
261
267
|
"symbol": "$",
|
268
|
+
"disambiguate_symbol": "BND",
|
262
269
|
"alternate_symbols": ["B$"],
|
263
270
|
"subunit": "Sen",
|
264
271
|
"subunit_to_unit": 100,
|
@@ -303,6 +310,7 @@
|
|
303
310
|
"iso_code": "BSD",
|
304
311
|
"name": "Bahamian Dollar",
|
305
312
|
"symbol": "$",
|
313
|
+
"disambiguate_symbol": "BSD",
|
306
314
|
"alternate_symbols": ["B$"],
|
307
315
|
"subunit": "Cent",
|
308
316
|
"subunit_to_unit": 100,
|
@@ -348,6 +356,7 @@
|
|
348
356
|
"iso_code": "BYR",
|
349
357
|
"name": "Belarusian Ruble",
|
350
358
|
"symbol": "Br",
|
359
|
+
"disambiguate_symbol": "BYR",
|
351
360
|
"alternate_symbols": [""],
|
352
361
|
"subunit": "Kapyeyka",
|
353
362
|
"subunit_to_unit": 100,
|
@@ -363,6 +372,7 @@
|
|
363
372
|
"iso_code": "BZD",
|
364
373
|
"name": "Belize Dollar",
|
365
374
|
"symbol": "$",
|
375
|
+
"disambiguate_symbol": "BZ$",
|
366
376
|
"alternate_symbols": ["BZ$"],
|
367
377
|
"subunit": "Cent",
|
368
378
|
"subunit_to_unit": 100,
|
@@ -378,6 +388,7 @@
|
|
378
388
|
"iso_code": "CAD",
|
379
389
|
"name": "Canadian Dollar",
|
380
390
|
"symbol": "$",
|
391
|
+
"disambiguate_symbol": "C$",
|
381
392
|
"alternate_symbols": ["C$", "CAD$"],
|
382
393
|
"subunit": "Cent",
|
383
394
|
"subunit_to_unit": 100,
|
@@ -393,6 +404,7 @@
|
|
393
404
|
"iso_code": "CDF",
|
394
405
|
"name": "Congolese Franc",
|
395
406
|
"symbol": "Fr",
|
407
|
+
"disambiguate_symbol": "FC",
|
396
408
|
"alternate_symbols": ["FC"],
|
397
409
|
"subunit": "Centime",
|
398
410
|
"subunit_to_unit": 100,
|
@@ -437,9 +449,10 @@
|
|
437
449
|
"iso_code": "CLP",
|
438
450
|
"name": "Chilean Peso",
|
439
451
|
"symbol": "$",
|
452
|
+
"disambiguate_symbol": "CLP",
|
440
453
|
"alternate_symbols": [],
|
441
454
|
"subunit": "Peso",
|
442
|
-
"subunit_to_unit":
|
455
|
+
"subunit_to_unit": 100,
|
443
456
|
"symbol_first": true,
|
444
457
|
"html_entity": "$",
|
445
458
|
"decimal_mark": ",",
|
@@ -456,7 +469,7 @@
|
|
456
469
|
"subunit": "Fen",
|
457
470
|
"subunit_to_unit": 100,
|
458
471
|
"symbol_first": true,
|
459
|
-
"html_entity": "
|
472
|
+
"html_entity": "¥",
|
460
473
|
"decimal_mark": ".",
|
461
474
|
"thousands_separator": ",",
|
462
475
|
"iso_numeric": "156",
|
@@ -467,6 +480,7 @@
|
|
467
480
|
"iso_code": "COP",
|
468
481
|
"name": "Colombian Peso",
|
469
482
|
"symbol": "$",
|
483
|
+
"disambiguate_symbol": "COL$",
|
470
484
|
"alternate_symbols": ["COL$"],
|
471
485
|
"subunit": "Centavo",
|
472
486
|
"subunit_to_unit": 100,
|
@@ -497,6 +511,7 @@
|
|
497
511
|
"iso_code": "CUC",
|
498
512
|
"name": "Cuban Convertible Peso",
|
499
513
|
"symbol": "$",
|
514
|
+
"disambiguate_symbol": "CUC$",
|
500
515
|
"alternate_symbols": ["CUC$"],
|
501
516
|
"subunit": "Centavo",
|
502
517
|
"subunit_to_unit": 100,
|
@@ -512,6 +527,7 @@
|
|
512
527
|
"iso_code": "CUP",
|
513
528
|
"name": "Cuban Peso",
|
514
529
|
"symbol": "$",
|
530
|
+
"disambiguate_symbol": "$MN",
|
515
531
|
"alternate_symbols": ["$MN"],
|
516
532
|
"subunit": "Centavo",
|
517
533
|
"subunit_to_unit": 100,
|
@@ -527,6 +543,7 @@
|
|
527
543
|
"iso_code": "CVE",
|
528
544
|
"name": "Cape Verdean Escudo",
|
529
545
|
"symbol": "$",
|
546
|
+
"disambiguate_symbol": "Esc",
|
530
547
|
"alternate_symbols": ["Esc"],
|
531
548
|
"subunit": "Centavo",
|
532
549
|
"subunit_to_unit": 100,
|
@@ -545,7 +562,7 @@
|
|
545
562
|
"alternate_symbols": [],
|
546
563
|
"subunit": "Haléř",
|
547
564
|
"subunit_to_unit": 100,
|
548
|
-
"symbol_first":
|
565
|
+
"symbol_first": false,
|
549
566
|
"html_entity": "",
|
550
567
|
"decimal_mark": ",",
|
551
568
|
"thousands_separator": ".",
|
@@ -572,6 +589,7 @@
|
|
572
589
|
"iso_code": "DKK",
|
573
590
|
"name": "Danish Krone",
|
574
591
|
"symbol": "kr",
|
592
|
+
"disambiguate_symbol": "DKK",
|
575
593
|
"alternate_symbols": [",-"],
|
576
594
|
"subunit": "Øre",
|
577
595
|
"subunit_to_unit": 100,
|
@@ -587,6 +605,7 @@
|
|
587
605
|
"iso_code": "DOP",
|
588
606
|
"name": "Dominican Peso",
|
589
607
|
"symbol": "$",
|
608
|
+
"disambiguate_symbol": "RD$",
|
590
609
|
"alternate_symbols": ["RD$"],
|
591
610
|
"subunit": "Centavo",
|
592
611
|
"subunit_to_unit": 100,
|
@@ -647,6 +666,7 @@
|
|
647
666
|
"iso_code": "ETB",
|
648
667
|
"name": "Ethiopian Birr",
|
649
668
|
"symbol": "Br",
|
669
|
+
"disambiguate_symbol": "ETB",
|
650
670
|
"alternate_symbols": [],
|
651
671
|
"subunit": "Santim",
|
652
672
|
"subunit_to_unit": 100,
|
@@ -677,6 +697,7 @@
|
|
677
697
|
"iso_code": "FJD",
|
678
698
|
"name": "Fijian Dollar",
|
679
699
|
"symbol": "$",
|
700
|
+
"disambiguate_symbol": "FJ$",
|
680
701
|
"alternate_symbols": ["FJ$"],
|
681
702
|
"subunit": "Cent",
|
682
703
|
"subunit_to_unit": 100,
|
@@ -692,6 +713,7 @@
|
|
692
713
|
"iso_code": "FKP",
|
693
714
|
"name": "Falkland Pound",
|
694
715
|
"symbol": "£",
|
716
|
+
"disambiguate_symbol": "FK£",
|
695
717
|
"alternate_symbols": ["FK£"],
|
696
718
|
"subunit": "Penny",
|
697
719
|
"subunit_to_unit": 100,
|
@@ -752,6 +774,7 @@
|
|
752
774
|
"iso_code": "GIP",
|
753
775
|
"name": "Gibraltar Pound",
|
754
776
|
"symbol": "£",
|
777
|
+
"disambiguate_symbol": "GIP",
|
755
778
|
"alternate_symbols": [],
|
756
779
|
"subunit": "Penny",
|
757
780
|
"subunit_to_unit": 100,
|
@@ -782,6 +805,7 @@
|
|
782
805
|
"iso_code": "GNF",
|
783
806
|
"name": "Guinean Franc",
|
784
807
|
"symbol": "Fr",
|
808
|
+
"disambiguate_symbol": "FG",
|
785
809
|
"alternate_symbols": ["FG", "GFr"],
|
786
810
|
"subunit": "Centime",
|
787
811
|
"subunit_to_unit": 100,
|
@@ -812,6 +836,7 @@
|
|
812
836
|
"iso_code": "GYD",
|
813
837
|
"name": "Guyanese Dollar",
|
814
838
|
"symbol": "$",
|
839
|
+
"disambiguate_symbol": "G$",
|
815
840
|
"alternate_symbols": ["G$"],
|
816
841
|
"subunit": "Cent",
|
817
842
|
"subunit_to_unit": 100,
|
@@ -827,6 +852,7 @@
|
|
827
852
|
"iso_code": "HKD",
|
828
853
|
"name": "Hong Kong Dollar",
|
829
854
|
"symbol": "$",
|
855
|
+
"disambiguate_symbol": "HK$",
|
830
856
|
"alternate_symbols": ["HK$"],
|
831
857
|
"subunit": "Cent",
|
832
858
|
"subunit_to_unit": 100,
|
@@ -842,6 +868,7 @@
|
|
842
868
|
"iso_code": "HNL",
|
843
869
|
"name": "Honduran Lempira",
|
844
870
|
"symbol": "L",
|
871
|
+
"disambiguate_symbol": "HNL",
|
845
872
|
"alternate_symbols": [],
|
846
873
|
"subunit": "Centavo",
|
847
874
|
"subunit_to_unit": 100,
|
@@ -992,6 +1019,7 @@
|
|
992
1019
|
"iso_code": "JMD",
|
993
1020
|
"name": "Jamaican Dollar",
|
994
1021
|
"symbol": "$",
|
1022
|
+
"disambiguate_symbol": "J$",
|
995
1023
|
"alternate_symbols": ["J$"],
|
996
1024
|
"subunit": "Cent",
|
997
1025
|
"subunit_to_unit": 100,
|
@@ -1082,6 +1110,7 @@
|
|
1082
1110
|
"iso_code": "KMF",
|
1083
1111
|
"name": "Comorian Franc",
|
1084
1112
|
"symbol": "Fr",
|
1113
|
+
"disambiguate_symbol": "CF",
|
1085
1114
|
"alternate_symbols": ["CF"],
|
1086
1115
|
"subunit": "Centime",
|
1087
1116
|
"subunit_to_unit": 100,
|
@@ -1113,7 +1142,7 @@
|
|
1113
1142
|
"name": "South Korean Won",
|
1114
1143
|
"symbol": "₩",
|
1115
1144
|
"subunit": null,
|
1116
|
-
"subunit_to_unit":
|
1145
|
+
"subunit_to_unit": 100,
|
1117
1146
|
"alternate_symbols": [],
|
1118
1147
|
"symbol_first": true,
|
1119
1148
|
"html_entity": "₩",
|
@@ -1142,6 +1171,7 @@
|
|
1142
1171
|
"iso_code": "KYD",
|
1143
1172
|
"name": "Cayman Islands Dollar",
|
1144
1173
|
"symbol": "$",
|
1174
|
+
"disambiguate_symbol": "CI$",
|
1145
1175
|
"alternate_symbols": ["CI$"],
|
1146
1176
|
"subunit": "Cent",
|
1147
1177
|
"subunit_to_unit": 100,
|
@@ -1202,6 +1232,7 @@
|
|
1202
1232
|
"iso_code": "LKR",
|
1203
1233
|
"name": "Sri Lankan Rupee",
|
1204
1234
|
"symbol": "₨",
|
1235
|
+
"disambiguate_symbol": "SLRs",
|
1205
1236
|
"alternate_symbols": ["රු", "ரூ", "SLRs", "/-"],
|
1206
1237
|
"subunit": "Cent",
|
1207
1238
|
"subunit_to_unit": 100,
|
@@ -1217,6 +1248,7 @@
|
|
1217
1248
|
"iso_code": "LRD",
|
1218
1249
|
"name": "Liberian Dollar",
|
1219
1250
|
"symbol": "$",
|
1251
|
+
"disambiguate_symbol": "L$",
|
1220
1252
|
"alternate_symbols": ["L$"],
|
1221
1253
|
"subunit": "Cent",
|
1222
1254
|
"subunit_to_unit": 100,
|
@@ -1232,6 +1264,7 @@
|
|
1232
1264
|
"iso_code": "LSL",
|
1233
1265
|
"name": "Lesotho Loti",
|
1234
1266
|
"symbol": "L",
|
1267
|
+
"disambiguate_symbol": "M",
|
1235
1268
|
"alternate_symbols": ["M"],
|
1236
1269
|
"subunit": "Sente",
|
1237
1270
|
"subunit_to_unit": 100,
|
@@ -1352,6 +1385,7 @@
|
|
1352
1385
|
"iso_code": "MMK",
|
1353
1386
|
"name": "Myanmar Kyat",
|
1354
1387
|
"symbol": "K",
|
1388
|
+
"disambiguate_symbol": "MMK",
|
1355
1389
|
"alternate_symbols": [],
|
1356
1390
|
"subunit": "Pya",
|
1357
1391
|
"subunit_to_unit": 100,
|
@@ -1457,6 +1491,7 @@
|
|
1457
1491
|
"iso_code": "MXN",
|
1458
1492
|
"name": "Mexican Peso",
|
1459
1493
|
"symbol": "$",
|
1494
|
+
"disambiguate_symbol": "MEX$",
|
1460
1495
|
"alternate_symbols": ["MEX$"],
|
1461
1496
|
"subunit": "Centavo",
|
1462
1497
|
"subunit_to_unit": 100,
|
@@ -1502,6 +1537,7 @@
|
|
1502
1537
|
"iso_code": "NAD",
|
1503
1538
|
"name": "Namibian Dollar",
|
1504
1539
|
"symbol": "$",
|
1540
|
+
"disambiguate_symbol": "N$",
|
1505
1541
|
"alternate_symbols": ["N$"],
|
1506
1542
|
"subunit": "Cent",
|
1507
1543
|
"subunit_to_unit": 100,
|
@@ -1520,7 +1556,7 @@
|
|
1520
1556
|
"alternate_symbols": [],
|
1521
1557
|
"subunit": "Kobo",
|
1522
1558
|
"subunit_to_unit": 100,
|
1523
|
-
"symbol_first":
|
1559
|
+
"symbol_first": true,
|
1524
1560
|
"html_entity": "₦",
|
1525
1561
|
"decimal_mark": ".",
|
1526
1562
|
"thousands_separator": ",",
|
@@ -1547,6 +1583,7 @@
|
|
1547
1583
|
"iso_code": "NOK",
|
1548
1584
|
"name": "Norwegian Krone",
|
1549
1585
|
"symbol": "kr",
|
1586
|
+
"disambiguate_symbol": "NOK",
|
1550
1587
|
"alternate_symbols": [",-"],
|
1551
1588
|
"subunit": "Øre",
|
1552
1589
|
"subunit_to_unit": 100,
|
@@ -1562,6 +1599,7 @@
|
|
1562
1599
|
"iso_code": "NPR",
|
1563
1600
|
"name": "Nepalese Rupee",
|
1564
1601
|
"symbol": "₨",
|
1602
|
+
"disambiguate_symbol": "NPR",
|
1565
1603
|
"alternate_symbols": ["Rs", "रू"],
|
1566
1604
|
"subunit": "Paisa",
|
1567
1605
|
"subunit_to_unit": 100,
|
@@ -1577,6 +1615,7 @@
|
|
1577
1615
|
"iso_code": "NZD",
|
1578
1616
|
"name": "New Zealand Dollar",
|
1579
1617
|
"symbol": "$",
|
1618
|
+
"disambiguate_symbol": "NZ$",
|
1580
1619
|
"alternate_symbols": ["NZ$"],
|
1581
1620
|
"subunit": "Cent",
|
1582
1621
|
"subunit_to_unit": 100,
|
@@ -1637,6 +1676,7 @@
|
|
1637
1676
|
"iso_code": "PGK",
|
1638
1677
|
"name": "Papua New Guinean Kina",
|
1639
1678
|
"symbol": "K",
|
1679
|
+
"disambiguate_symbol": "PGK",
|
1640
1680
|
"alternate_symbols": [],
|
1641
1681
|
"subunit": "Toea",
|
1642
1682
|
"subunit_to_unit": 100,
|
@@ -1667,6 +1707,7 @@
|
|
1667
1707
|
"iso_code": "PKR",
|
1668
1708
|
"name": "Pakistani Rupee",
|
1669
1709
|
"symbol": "₨",
|
1710
|
+
"disambiguate_symbol": "PKR",
|
1670
1711
|
"alternate_symbols": ["Rs"],
|
1671
1712
|
"subunit": "Paisa",
|
1672
1713
|
"subunit_to_unit": 100,
|
@@ -1756,8 +1797,8 @@
|
|
1756
1797
|
"priority": 100,
|
1757
1798
|
"iso_code": "RUB",
|
1758
1799
|
"name": "Russian Ruble",
|
1759
|
-
"symbol": "
|
1760
|
-
"alternate_symbols": ["
|
1800
|
+
"symbol": "руб",
|
1801
|
+
"alternate_symbols": ["р.", "₽"],
|
1761
1802
|
"subunit": "Kopek",
|
1762
1803
|
"subunit_to_unit": 100,
|
1763
1804
|
"symbol_first": false,
|
@@ -1802,6 +1843,7 @@
|
|
1802
1843
|
"iso_code": "SBD",
|
1803
1844
|
"name": "Solomon Islands Dollar",
|
1804
1845
|
"symbol": "$",
|
1846
|
+
"disambiguate_symbol": "SI$",
|
1805
1847
|
"alternate_symbols": ["SI$"],
|
1806
1848
|
"subunit": "Cent",
|
1807
1849
|
"subunit_to_unit": 100,
|
@@ -1817,6 +1859,7 @@
|
|
1817
1859
|
"iso_code": "SCR",
|
1818
1860
|
"name": "Seychellois Rupee",
|
1819
1861
|
"symbol": "₨",
|
1862
|
+
"disambiguate_symbol": "SRe",
|
1820
1863
|
"alternate_symbols": ["SRe", "SR"],
|
1821
1864
|
"subunit": "Cent",
|
1822
1865
|
"subunit_to_unit": 100,
|
@@ -1832,6 +1875,7 @@
|
|
1832
1875
|
"iso_code": "SDG",
|
1833
1876
|
"name": "Sudanese Pound",
|
1834
1877
|
"symbol": "£",
|
1878
|
+
"disambiguate_symbol": "SDG",
|
1835
1879
|
"alternate_symbols": [],
|
1836
1880
|
"subunit": "Piastre",
|
1837
1881
|
"subunit_to_unit": 100,
|
@@ -1847,6 +1891,7 @@
|
|
1847
1891
|
"iso_code": "SEK",
|
1848
1892
|
"name": "Swedish Krona",
|
1849
1893
|
"symbol": "kr",
|
1894
|
+
"disambiguate_symbol": "SEK",
|
1850
1895
|
"alternate_symbols": [":-"],
|
1851
1896
|
"subunit": "Öre",
|
1852
1897
|
"subunit_to_unit": 100,
|
@@ -1862,6 +1907,7 @@
|
|
1862
1907
|
"iso_code": "SGD",
|
1863
1908
|
"name": "Singapore Dollar",
|
1864
1909
|
"symbol": "$",
|
1910
|
+
"disambiguate_symbol": "S$",
|
1865
1911
|
"alternate_symbols": ["S$"],
|
1866
1912
|
"subunit": "Cent",
|
1867
1913
|
"subunit_to_unit": 100,
|
@@ -1877,6 +1923,7 @@
|
|
1877
1923
|
"iso_code": "SHP",
|
1878
1924
|
"name": "Saint Helenian Pound",
|
1879
1925
|
"symbol": "£",
|
1926
|
+
"disambiguate_symbol": "SHP",
|
1880
1927
|
"alternate_symbols": [],
|
1881
1928
|
"subunit": "Penny",
|
1882
1929
|
"subunit_to_unit": 100,
|
@@ -1937,6 +1984,7 @@
|
|
1937
1984
|
"iso_code": "SRD",
|
1938
1985
|
"name": "Surinamese Dollar",
|
1939
1986
|
"symbol": "$",
|
1987
|
+
"disambiguate_symbol": "SRD",
|
1940
1988
|
"alternate_symbols": [],
|
1941
1989
|
"subunit": "Cent",
|
1942
1990
|
"subunit_to_unit": 100,
|
@@ -1952,6 +2000,7 @@
|
|
1952
2000
|
"iso_code": "SSP",
|
1953
2001
|
"name": "South Sudanese Pound",
|
1954
2002
|
"symbol": "£",
|
2003
|
+
"disambiguate_symbol": "SSP",
|
1955
2004
|
"alternate_symbols": [],
|
1956
2005
|
"subunit": "piaster",
|
1957
2006
|
"subunit_to_unit": 100,
|
@@ -2012,6 +2061,7 @@
|
|
2012
2061
|
"iso_code": "SZL",
|
2013
2062
|
"name": "Swazi Lilangeni",
|
2014
2063
|
"symbol": "L",
|
2064
|
+
"disambiguate_symbol": "SZL",
|
2015
2065
|
"alternate_symbols": ["E"],
|
2016
2066
|
"subunit": "Cent",
|
2017
2067
|
"subunit_to_unit": 100,
|
@@ -2101,8 +2151,8 @@
|
|
2101
2151
|
"priority": 100,
|
2102
2152
|
"iso_code": "TRY",
|
2103
2153
|
"name": "Turkish Lira",
|
2104
|
-
"symbol": "
|
2105
|
-
"alternate_symbols": [],
|
2154
|
+
"symbol": "₺",
|
2155
|
+
"alternate_symbols": ["TL"],
|
2106
2156
|
"subunit": "kuruş",
|
2107
2157
|
"subunit_to_unit": 100,
|
2108
2158
|
"symbol_first": false,
|
@@ -2117,6 +2167,7 @@
|
|
2117
2167
|
"iso_code": "TTD",
|
2118
2168
|
"name": "Trinidad and Tobago Dollar",
|
2119
2169
|
"symbol": "$",
|
2170
|
+
"disambiguate_symbol": "TT$",
|
2120
2171
|
"alternate_symbols": ["TT$"],
|
2121
2172
|
"subunit": "Cent",
|
2122
2173
|
"subunit_to_unit": 100,
|
@@ -2132,6 +2183,7 @@
|
|
2132
2183
|
"iso_code": "TWD",
|
2133
2184
|
"name": "New Taiwan Dollar",
|
2134
2185
|
"symbol": "$",
|
2186
|
+
"disambiguate_symbol": "NT$",
|
2135
2187
|
"alternate_symbols": ["NT$"],
|
2136
2188
|
"subunit": "Cent",
|
2137
2189
|
"subunit_to_unit": 100,
|
@@ -2254,13 +2306,13 @@
|
|
2254
2306
|
"symbol": "₫",
|
2255
2307
|
"alternate_symbols": [],
|
2256
2308
|
"subunit": "Hào",
|
2257
|
-
"subunit_to_unit":
|
2309
|
+
"subunit_to_unit": 1,
|
2258
2310
|
"symbol_first": true,
|
2259
2311
|
"html_entity": "₫",
|
2260
2312
|
"decimal_mark": ",",
|
2261
2313
|
"thousands_separator": ".",
|
2262
2314
|
"iso_numeric": "704",
|
2263
|
-
"smallest_denomination":
|
2315
|
+
"smallest_denomination": 100
|
2264
2316
|
},
|
2265
2317
|
"vuv": {
|
2266
2318
|
"priority": 100,
|
@@ -2282,6 +2334,7 @@
|
|
2282
2334
|
"iso_code": "WST",
|
2283
2335
|
"name": "Samoan Tala",
|
2284
2336
|
"symbol": "T",
|
2337
|
+
"disambiguate_symbol": "WS$",
|
2285
2338
|
"alternate_symbols": ["WS$", "SAT", "ST"],
|
2286
2339
|
"subunit": "Sene",
|
2287
2340
|
"subunit_to_unit": 100,
|
@@ -2297,6 +2350,7 @@
|
|
2297
2350
|
"iso_code": "XAF",
|
2298
2351
|
"name": "Central African Cfa Franc",
|
2299
2352
|
"symbol": "Fr",
|
2353
|
+
"disambiguate_symbol": "FCFA",
|
2300
2354
|
"alternate_symbols": ["FCFA"],
|
2301
2355
|
"subunit": "Centime",
|
2302
2356
|
"subunit_to_unit": 100,
|
@@ -2312,6 +2366,7 @@
|
|
2312
2366
|
"iso_code": "XAG",
|
2313
2367
|
"name": "Silver (Troy Ounce)",
|
2314
2368
|
"symbol": "oz t",
|
2369
|
+
"disambiguate_symbol": "XAG",
|
2315
2370
|
"alternate_symbols": [],
|
2316
2371
|
"subunit": "oz",
|
2317
2372
|
"subunit_to_unit": 1,
|
@@ -2326,6 +2381,7 @@
|
|
2326
2381
|
"iso_code": "XAU",
|
2327
2382
|
"name": "Gold (Troy Ounce)",
|
2328
2383
|
"symbol": "oz t",
|
2384
|
+
"disambiguate_symbol": "XAU",
|
2329
2385
|
"alternate_symbols": [],
|
2330
2386
|
"subunit": "oz",
|
2331
2387
|
"subunit_to_unit": 1,
|
@@ -2340,6 +2396,7 @@
|
|
2340
2396
|
"iso_code": "XCD",
|
2341
2397
|
"name": "East Caribbean Dollar",
|
2342
2398
|
"symbol": "$",
|
2399
|
+
"disambiguate_symbol": "EX$",
|
2343
2400
|
"alternate_symbols": ["EC$"],
|
2344
2401
|
"subunit": "Cent",
|
2345
2402
|
"subunit_to_unit": 100,
|
@@ -2369,6 +2426,7 @@
|
|
2369
2426
|
"iso_code": "XOF",
|
2370
2427
|
"name": "West African Cfa Franc",
|
2371
2428
|
"symbol": "Fr",
|
2429
|
+
"disambiguate_symbol": "CFA",
|
2372
2430
|
"alternate_symbols": ["CFA"],
|
2373
2431
|
"subunit": "Centime",
|
2374
2432
|
"subunit_to_unit": 100,
|
@@ -2429,6 +2487,7 @@
|
|
2429
2487
|
"iso_code": "ZMK",
|
2430
2488
|
"name": "Zambian Kwacha",
|
2431
2489
|
"symbol": "ZK",
|
2490
|
+
"disambiguate_symbol": "ZMK",
|
2432
2491
|
"alternate_symbols": [],
|
2433
2492
|
"subunit": "Ngwee",
|
2434
2493
|
"subunit_to_unit": 100,
|
@@ -2444,6 +2503,7 @@
|
|
2444
2503
|
"iso_code": "ZMW",
|
2445
2504
|
"name": "Zambian Kwacha",
|
2446
2505
|
"symbol": "ZK",
|
2506
|
+
"disambiguate_symbol": "ZMW",
|
2447
2507
|
"alternate_symbols": [],
|
2448
2508
|
"subunit": "Ngwee",
|
2449
2509
|
"subunit_to_unit": 100,
|
data/lib/money/currency.rb
CHANGED
@@ -141,6 +141,7 @@ class Money
|
|
141
141
|
# defined by the ISO 4217 standard.
|
142
142
|
# @attr_reader [String] name The currency name.
|
143
143
|
# @attr_reader [String] symbol The currency symbol (UTF-8 encoded).
|
144
|
+
# @attr_reader [String] disambiguate_symbol Alternative currency used if symbol is ambiguous
|
144
145
|
# @attr_reader [String] html_entity The html entity for the currency symbol
|
145
146
|
# @attr_reader [String] subunit The name of the fractional monetary unit.
|
146
147
|
# @attr_reader [Integer] subunit_to_unit The proportion between the unit
|
@@ -155,7 +156,7 @@ class Money
|
|
155
156
|
# possible (in the subunit of this currency)
|
156
157
|
|
157
158
|
attr_reader :id, :priority, :iso_code, :iso_numeric, :name, :symbol,
|
158
|
-
:html_entity, :subunit, :subunit_to_unit, :decimal_mark,
|
159
|
+
:disambiguate_symbol, :html_entity, :subunit, :subunit_to_unit, :decimal_mark,
|
159
160
|
:thousands_separator, :symbol_first, :smallest_denomination
|
160
161
|
|
161
162
|
alias_method :separator, :decimal_mark
|
@@ -180,6 +181,7 @@ class Money
|
|
180
181
|
@iso_code = data[:iso_code]
|
181
182
|
@name = data[:name]
|
182
183
|
@symbol = data[:symbol]
|
184
|
+
@disambiguate_symbol = data[:disambiguate_symbol]
|
183
185
|
@alternate_symbols = data[:alternate_symbols]
|
184
186
|
@subunit = data[:subunit]
|
185
187
|
@subunit_to_unit = data[:subunit_to_unit]
|
data/lib/money/money.rb
CHANGED
@@ -15,7 +15,7 @@ require "money/money/formatting"
|
|
15
15
|
# @see http://en.wikipedia.org/wiki/Money
|
16
16
|
class Money
|
17
17
|
include Comparable, Money::Arithmetic, Money::Formatting
|
18
|
-
|
18
|
+
|
19
19
|
# Raised when smallest denomination of a currency is not defined
|
20
20
|
class UndefinedSmallestDenomination < StandardError; end
|
21
21
|
|
@@ -52,7 +52,7 @@ class Money
|
|
52
52
|
|
53
53
|
return_value(fractional)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# Round a given amount of money to the nearest possible amount in cash value. For
|
57
57
|
# example, in Swiss francs (CHF), the smallest possible amount of cash value is
|
58
58
|
# CHF 0.05. Therefore, this method rounds CHF 0.07 to CHF 0.05, and CHF 0.08 to
|
@@ -66,11 +66,11 @@ class Money
|
|
66
66
|
unless self.currency.smallest_denomination
|
67
67
|
raise UndefinedSmallestDenomination, 'Smallest denomination of this currency is not defined'
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
fractional = as_d(@fractional)
|
71
71
|
smallest_denomination = as_d(self.currency.smallest_denomination)
|
72
72
|
rounded_value = (fractional / smallest_denomination).round(0, self.class.rounding_mode) * smallest_denomination
|
73
|
-
|
73
|
+
|
74
74
|
return_value(rounded_value)
|
75
75
|
end
|
76
76
|
|
@@ -86,18 +86,34 @@ class Money
|
|
86
86
|
# This property allows you to specify the default bank object. The default
|
87
87
|
# value for this property is an instance of +Bank::VariableExchange.+ It
|
88
88
|
# allows one to specify custom exchange rates.
|
89
|
+
#
|
89
90
|
# @attr_accessor [Money::Currency] default_currency The default currency,
|
90
91
|
# which is used when +Money.new+ is called without an explicit currency
|
91
92
|
# argument. The default value is Currency.new("USD"). The value must be a
|
92
93
|
# valid +Money::Currency+ instance.
|
94
|
+
#
|
95
|
+
# @attr_accessor [Hash] default_formatting_rules Use this to define a default
|
96
|
+
# hash of rules for everytime +Money#format+ is called.
|
97
|
+
# Rules provided on method call will be merged with the default ones.
|
98
|
+
# To overwrite a rule, just provide the intended value while calling +format+.
|
99
|
+
#
|
100
|
+
# @see +Money::Formatting#format+ for more details.
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# Money.default_formatting_rules = { :display_free => true }
|
104
|
+
# Money.new(0, "USD").format # => "free"
|
105
|
+
# Money.new(0, "USD").format(:display_free => false) # => "$0.00"
|
106
|
+
#
|
93
107
|
# @attr_accessor [true, false] use_i18n Use this to disable i18n even if
|
94
108
|
# it's used by other objects in your app.
|
109
|
+
#
|
95
110
|
# @attr_accessor [true, false] infinite_precision Use this to enable
|
96
111
|
# infinite precision cents
|
112
|
+
#
|
97
113
|
# @attr_accessor [Integer] conversion_precision Use this to specify
|
98
114
|
# precision for converting Rational to BigDecimal
|
99
|
-
attr_accessor :default_bank, :default_currency, :
|
100
|
-
:infinite_precision, :conversion_precision
|
115
|
+
attr_accessor :default_bank, :default_currency, :default_formatting_rules,
|
116
|
+
:use_i18n, :infinite_precision, :conversion_precision
|
101
117
|
|
102
118
|
# @attr_writer rounding_mode Use this to specify the rounding mode
|
103
119
|
attr_writer :rounding_mode
|
@@ -260,7 +276,7 @@ class Money
|
|
260
276
|
def initialize(obj, currency = Money.default_currency, bank = Money.default_bank)
|
261
277
|
@fractional = obj.respond_to?(:fractional) ? obj.fractional : as_d(obj)
|
262
278
|
@currency = obj.respond_to?(:currency) ? obj.currency : Currency.wrap(currency)
|
263
|
-
@currency ||= Money.default_currency
|
279
|
+
@currency ||= Money.default_currency
|
264
280
|
@bank = obj.respond_to?(:bank) ? obj.bank : bank
|
265
281
|
end
|
266
282
|
|
@@ -618,7 +634,7 @@ class Money
|
|
618
634
|
index < remainder ? high : low
|
619
635
|
end
|
620
636
|
end
|
621
|
-
|
637
|
+
|
622
638
|
def return_value(value)
|
623
639
|
if self.class.infinite_precision
|
624
640
|
value
|
@@ -13,12 +13,11 @@ class Money
|
|
13
13
|
def self.define_i18n_method(method, name, character)
|
14
14
|
define_method(method) do
|
15
15
|
if self.class.use_i18n
|
16
|
-
|
17
|
-
:"number.currency.format
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
)
|
16
|
+
begin
|
17
|
+
I18n.t name, :scope => "number.currency.format", :raise => true
|
18
|
+
rescue I18n::MissingTranslationData => e
|
19
|
+
I18n.t name, :scope =>"number.format", :default => (currency.send(method) || character)
|
20
|
+
end
|
22
21
|
else
|
23
22
|
currency.send(method) || character
|
24
23
|
end
|
@@ -180,10 +179,25 @@ class Money
|
|
180
179
|
# Money.new(100, "GBP").format(:sign_positive => false, :sign_before_symbol => true) #=> "£1.00"
|
181
180
|
# Money.new(100, "GBP").format(:sign_positive => false, :sign_before_symbol => false) #=> "£1.00"
|
182
181
|
# Money.new(100, "GBP").format #=> "£+1.00"
|
182
|
+
#
|
183
|
+
# @option *rules [Boolean] :disambiguate (false) Prevents the result from being ambiguous
|
184
|
+
# due to equal symbols for different currencies. Uses the `disambiguate_symbol`.
|
185
|
+
#
|
186
|
+
# @example
|
187
|
+
# Money.new(100, "USD").format(:disambiguate => false) #=> "$100.00"
|
188
|
+
# Money.new(100, "CAD").format(:disambiguate => false) #=> "$100.00"
|
189
|
+
# Money.new(100, "USD").format(:disambiguate => true) #=> "$100.00"
|
190
|
+
# Money.new(100, "CAD").format(:disambiguate => true) #=> "C$100.00"
|
191
|
+
#
|
192
|
+
# Note that the default rules can be defined through +Money.default_formatting_rules+ hash.
|
193
|
+
#
|
194
|
+
# @see +Money.default_formatting_rules+ for more information.
|
183
195
|
|
184
196
|
def format(*rules)
|
185
197
|
# support for old format parameters
|
186
198
|
rules = normalize_formatting_rules(rules)
|
199
|
+
|
200
|
+
rules = default_formatting_rules.merge(rules)
|
187
201
|
rules = localize_formatting_rules(rules)
|
188
202
|
|
189
203
|
if fractional == 0
|
@@ -298,6 +312,10 @@ class Money
|
|
298
312
|
end
|
299
313
|
end
|
300
314
|
|
315
|
+
def default_formatting_rules
|
316
|
+
self.class.default_formatting_rules || {}
|
317
|
+
end
|
318
|
+
|
301
319
|
def regexp_format(formatted, rules, decimal_mark, symbol_value)
|
302
320
|
regexp_decimal = Regexp.escape(decimal_mark)
|
303
321
|
if rules[:south_asian_number_formatting]
|
@@ -332,6 +350,8 @@ class Money
|
|
332
350
|
end
|
333
351
|
elsif rules[:html]
|
334
352
|
currency.html_entity == '' ? currency.symbol : currency.html_entity
|
353
|
+
elsif rules[:disambiguate] and currency.disambiguate_symbol
|
354
|
+
currency.disambiguate_symbol
|
335
355
|
else
|
336
356
|
symbol
|
337
357
|
end
|
data/lib/money/version.rb
CHANGED
data/money.gemspec
CHANGED
@@ -25,7 +25,7 @@ and choose the migration that best suits your application.
|
|
25
25
|
Test responsibly :-)
|
26
26
|
MSG
|
27
27
|
|
28
|
-
s.add_dependency 'i18n', ['>= 0.6.4', '<= 0.7.0.
|
28
|
+
s.add_dependency 'i18n', ['>= 0.6.4', '<= 0.7.0.beta1']
|
29
29
|
|
30
30
|
s.add_development_dependency "bundler", "~> 1.3"
|
31
31
|
s.add_development_dependency "rake"
|
@@ -120,7 +120,7 @@ describe Money, "formatting" do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
it "does not display a decimal when :subunit_to_unit is 1" do
|
123
|
-
expect(Money.new(10_00, "
|
123
|
+
expect(Money.new(10_00, "VUV").format).to eq "Vt1,000"
|
124
124
|
end
|
125
125
|
|
126
126
|
it "respects the thousands_separator and decimal_mark defaults" do
|
@@ -169,6 +169,40 @@ describe Money, "formatting" do
|
|
169
169
|
expect(Money.euro(1_234_567_12).format(:no_cents => true)).to eq "€1.234.567"
|
170
170
|
end
|
171
171
|
|
172
|
+
context 'when default_formatting_rules defines (display_free: true)' do
|
173
|
+
before do
|
174
|
+
Money.default_formatting_rules = { :display_free => "you won't pay a thing" }
|
175
|
+
end
|
176
|
+
|
177
|
+
after do
|
178
|
+
Money.default_formatting_rules = nil
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'with no rule provided' do
|
182
|
+
it 'acknowledges default rule' do
|
183
|
+
expect(Money.new(0, 'USD').format).to eq "you won't pay a thing"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'with rule (display_free: false) provided' do
|
188
|
+
it 'acknowledges provided rule' do
|
189
|
+
expect(Money.new(0, 'USD').format(:display_free => false)).to eq '$0.00'
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'when default_formatting_rules is not defined' do
|
195
|
+
before do
|
196
|
+
Money.default_formatting_rules = nil
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'acknowledges provided rule' do
|
200
|
+
it 'acknowledges provided rule' do
|
201
|
+
expect(Money.new(100, 'USD').format(:with_currency => true)).to eq '$1.00 USD'
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
172
206
|
describe ":with_currency option" do
|
173
207
|
specify "(:with_currency option => true) works as documented" do
|
174
208
|
expect(Money.ca_dollar(100).format(:with_currency => true)).to eq "$1.00 CAD"
|
@@ -191,7 +225,7 @@ describe Money, "formatting" do
|
|
191
225
|
it "inserts thousand separators if symbol contains decimal mark and no_cents is true" do
|
192
226
|
expect(Money.new(100000000, "AMD").format(:no_cents => true)).to eq "1,000,000 դր."
|
193
227
|
expect(Money.new(100000000, "USD").format(:no_cents => true)).to eq "$1,000,000"
|
194
|
-
expect(Money.new(100000000, "RUB").format(:no_cents => true)).to eq "1.000.000
|
228
|
+
expect(Money.new(100000000, "RUB").format(:no_cents => true)).to eq "1.000.000 руб"
|
195
229
|
end
|
196
230
|
|
197
231
|
it "doesn't incorrectly format HTML" do
|
@@ -207,8 +241,8 @@ describe Money, "formatting" do
|
|
207
241
|
expect(Money.new(10034, "VUV").format(:no_cents_if_whole => true, :symbol => false)).to eq "10,034"
|
208
242
|
expect(Money.new(10000, "MGA").format(:no_cents_if_whole => true, :symbol => false)).to eq "2,000"
|
209
243
|
expect(Money.new(10034, "MGA").format(:no_cents_if_whole => true, :symbol => false)).to eq "2,006.4"
|
210
|
-
expect(Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "
|
211
|
-
expect(Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "
|
244
|
+
expect(Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "10.000"
|
245
|
+
expect(Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "10.034"
|
212
246
|
expect(Money.new(10000, "USD").format(:no_cents_if_whole => true, :symbol => false)).to eq "100"
|
213
247
|
expect(Money.new(10034, "USD").format(:no_cents_if_whole => true, :symbol => false)).to eq "100.34"
|
214
248
|
expect(Money.new(10000, "IQD").format(:no_cents_if_whole => true, :symbol => false)).to eq "10"
|
@@ -220,8 +254,8 @@ describe Money, "formatting" do
|
|
220
254
|
expect(Money.new(10034, "VUV").format(:no_cents_if_whole => false, :symbol => false)).to eq "10,034"
|
221
255
|
expect(Money.new(10000, "MGA").format(:no_cents_if_whole => false, :symbol => false)).to eq "2,000.0"
|
222
256
|
expect(Money.new(10034, "MGA").format(:no_cents_if_whole => false, :symbol => false)).to eq "2,006.4"
|
223
|
-
expect(Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "
|
224
|
-
expect(Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "
|
257
|
+
expect(Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.000"
|
258
|
+
expect(Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.034"
|
225
259
|
expect(Money.new(10000, "USD").format(:no_cents_if_whole => false, :symbol => false)).to eq "100.00"
|
226
260
|
expect(Money.new(10034, "USD").format(:no_cents_if_whole => false, :symbol => false)).to eq "100.34"
|
227
261
|
expect(Money.new(10000, "IQD").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.000"
|
@@ -586,4 +620,44 @@ describe Money, "formatting" do
|
|
586
620
|
end
|
587
621
|
|
588
622
|
end
|
623
|
+
|
624
|
+
context "currencies with ambiguous signs" do
|
625
|
+
|
626
|
+
it "returns ambiguous signs when disambiguate is not set" do
|
627
|
+
expect(Money.new(1999_98, "USD").format).to eq("$1,999.98")
|
628
|
+
expect(Money.new(1999_98, "CAD").format).to eq("$1,999.98")
|
629
|
+
expect(Money.new(1999_98, "DKK").format).to eq("1.999,98 kr")
|
630
|
+
expect(Money.new(1999_98, "NOK").format).to eq("1.999,98 kr")
|
631
|
+
expect(Money.new(1999_98, "SEK").format).to eq("1 999,98 kr")
|
632
|
+
end
|
633
|
+
|
634
|
+
it "returns ambiguous signs when disambiguate is false" do
|
635
|
+
expect(Money.new(1999_98, "USD").format(disambiguate: false)).to eq("$1,999.98")
|
636
|
+
expect(Money.new(1999_98, "CAD").format(disambiguate: false)).to eq("$1,999.98")
|
637
|
+
expect(Money.new(1999_98, "DKK").format(disambiguate: false)).to eq("1.999,98 kr")
|
638
|
+
expect(Money.new(1999_98, "NOK").format(disambiguate: false)).to eq("1.999,98 kr")
|
639
|
+
expect(Money.new(1999_98, "SEK").format(disambiguate: false)).to eq("1 999,98 kr")
|
640
|
+
end
|
641
|
+
|
642
|
+
it "returns disambiguate signs when disambiguate: true" do
|
643
|
+
expect(Money.new(1999_98, "USD").format(disambiguate: true)).to eq("$1,999.98")
|
644
|
+
expect(Money.new(1999_98, "CAD").format(disambiguate: true)).to eq("C$1,999.98")
|
645
|
+
expect(Money.new(1999_98, "DKK").format(disambiguate: true)).to eq("1.999,98 DKK")
|
646
|
+
expect(Money.new(1999_98, "NOK").format(disambiguate: true)).to eq("1.999,98 NOK")
|
647
|
+
expect(Money.new(1999_98, "SEK").format(disambiguate: true)).to eq("1 999,98 SEK")
|
648
|
+
end
|
649
|
+
|
650
|
+
it "should never return an ambiguous format with disambiguate: true" do
|
651
|
+
formatted_results = {}
|
652
|
+
|
653
|
+
# When we format the same amount in all known currencies, disambiguate should return
|
654
|
+
# all different values
|
655
|
+
Money::Currency.all.each do |currency|
|
656
|
+
format = Money.new(1999_98, currency).format(disambiguate: true)
|
657
|
+
expect(formatted_results.keys).not_to include(format), "Format '#{format}' for #{currency} is ambiguous with currency #{formatted_results[format]}."
|
658
|
+
formatted_results[format] = currency
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
end
|
589
663
|
end
|
data/spec/money_spec.rb
CHANGED
@@ -385,7 +385,7 @@ YAML
|
|
385
385
|
it "respects :subunit_to_unit currency property" do
|
386
386
|
expect(Money.new(1_00, "USD").amount).to eq 1
|
387
387
|
expect(Money.new(1_000, "TND").amount).to eq 1
|
388
|
-
expect(Money.new(1, "
|
388
|
+
expect(Money.new(1, "VUV").amount).to eq 1
|
389
389
|
end
|
390
390
|
|
391
391
|
it "does not loose precision" do
|
@@ -473,7 +473,7 @@ YAML
|
|
473
473
|
end
|
474
474
|
|
475
475
|
it "does not have decimal when :subunit_to_unit == 1" do
|
476
|
-
expect(Money.new(10_00, "
|
476
|
+
expect(Money.new(10_00, "VUV").to_s).to eq "1000"
|
477
477
|
end
|
478
478
|
|
479
479
|
it "does not work when :subunit_to_unit == 5" do
|
@@ -502,7 +502,7 @@ YAML
|
|
502
502
|
end
|
503
503
|
|
504
504
|
it "shows fractional if needed when :subunut_to_unit == 1" do
|
505
|
-
expect(Money.new(10_00.1, "
|
505
|
+
expect(Money.new(10_00.1, "VUV").to_s).to eq "1000.1"
|
506
506
|
end
|
507
507
|
end
|
508
508
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 0.6.4
|
20
20
|
- - "<="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.7.0.
|
22
|
+
version: 0.7.0.beta1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 0.6.4
|
30
30
|
- - "<="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.7.0.
|
32
|
+
version: 0.7.0.beta1
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|