minting 1.6.1 → 1.6.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/README.md +1 -1
- data/bin/check-currencies +29 -0
- data/lib/minting/data/{currencies.yaml → world-currencies.yaml} +278 -1
- data/lib/minting/mint/{currency_store.rb → currency/currency_registry.rb} +28 -2
- data/lib/minting/mint/{world_currencies.rb → currency/world_currencies.rb} +3 -4
- data/lib/minting/mint/mint.rb +14 -1
- data/lib/minting/mint/parser.rb +1 -1
- data/lib/minting/mint.rb +3 -4
- data/lib/minting/money/formatting.rb +3 -3
- data/lib/minting/version.rb +1 -1
- metadata +6 -6
- data/lib/minting/mint/registry.rb +0 -37
- /data/lib/minting/mint/{currency.rb → currency/currency.rb} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0af1a3786bbef7fd2c9d3614ccd5076e0ad6f77fb35bd0d34e636355bafd4714
|
|
4
|
+
data.tar.gz: 520dfe15e4a3ddcd180a898769266d27502af54e3ad70503ed734ad351564639
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd835b1ff970861a98dff3f056feb8903e2cb5145f0b60e52372d754daa65d60461e5200cc07de954963c0f31d954f8a8f54faf0a4f16746119e1195dc3c206e
|
|
7
|
+
data.tar.gz: 5f4e58dea85c7129e00aeef897810053136ba8d30cd49a4f199376b0e4f45885680bf1225b518dd479174e473da6e538efe30831e834e2ce41b3fdaf0a81235c
|
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Fast, precise, and developer-friendly money handling for Ruby.
|
|
|
8
8
|
|
|
9
9
|
**Tired of floating-point errors in financial calculations?** Minting uses Rational numbers for perfect precision.
|
|
10
10
|
|
|
11
|
-
**Need performance?** Minting is 2× faster than alternatives for high-volume operations (often 10×+ for formatting). See the [Performance](
|
|
11
|
+
**Need performance?** Minting is 2× faster than alternatives for high-volume operations (often 10×+ for formatting). See the [Performance](https://github.com/gferraz/minting/blob/master/test/performance/README.md) section for full benchmarks.
|
|
12
12
|
|
|
13
13
|
**Want a clean API?** Minting provides an intuitive interface with helpful error messages.
|
|
14
14
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "yaml"
|
|
4
|
+
require "set"
|
|
5
|
+
|
|
6
|
+
yaml = YAML.load_file(
|
|
7
|
+
File.expand_path("~/code/minting/lib/minting/data/world-currencies.yaml")
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
minting_codes = yaml.map { |c| c["code"] }.to_set
|
|
11
|
+
|
|
12
|
+
iso_codes = %w[
|
|
13
|
+
AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM BBD BDT BGN BHD BIF BMD BND BOB
|
|
14
|
+
BRL BSD BTN BWP BYN BZD CAD CDF CHF CLP CNY COP CRC CUP CVE CZK DJF DKK DOP
|
|
15
|
+
DZD EGP ERN ETB EUR FJD FKP FOK GBP GEL GGP GHS GIP GMD GNF GTQ GYD HKD HNL
|
|
16
|
+
HRK HTG HUF IDR ILS IMP INR IQD IRR ISK JEP JMD JOD JPY KES KGS KHR KID KMF
|
|
17
|
+
KRW KWD KYD KZT LAK LBP LKR LRD LSL LYD MAD MDL MGA MKD MMK MNT MOP MRU MUR
|
|
18
|
+
MVR MWK MXN MYR MZN NAD NGN NIO NOK NPR NZD OMR PAB PEN PGK PHP PKR PLN PYG
|
|
19
|
+
QAR RON RSD RUB RWF SAR SBD SCR SDG SEK SGD SHP SLE SLL SOS SRD SSP STN SVC
|
|
20
|
+
SYP SZL THB TJS TMT TND TOP TRY TTD TVD TWD TZS UAH UGX USD UYU UZS VES VND
|
|
21
|
+
VUV WST XAF XCD XDR XOF XPF YER ZAR ZMW ZWL
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
missing = iso_codes.reject { |c| minting_codes.include?(c) }
|
|
25
|
+
if missing.empty?
|
|
26
|
+
puts "Currencies: #{minting_codes.size}. No currency missing!"
|
|
27
|
+
else
|
|
28
|
+
puts "Missing: #{missing.sort.join(", ")}"
|
|
29
|
+
end
|
|
@@ -133,6 +133,12 @@
|
|
|
133
133
|
symbol: د.إ
|
|
134
134
|
name: United Arab Emirates Dirham
|
|
135
135
|
priority: 600
|
|
136
|
+
- code: YER
|
|
137
|
+
country: YEM
|
|
138
|
+
subunit: 2
|
|
139
|
+
symbol: "﷼"
|
|
140
|
+
name: Yemeni Rial
|
|
141
|
+
priority: 114
|
|
136
142
|
- code: IDR
|
|
137
143
|
country: IDN
|
|
138
144
|
subunit: 2
|
|
@@ -151,6 +157,12 @@
|
|
|
151
157
|
symbol: "₦"
|
|
152
158
|
name: Nigerian Naira
|
|
153
159
|
priority: 111
|
|
160
|
+
- code: SOS
|
|
161
|
+
country: SOM
|
|
162
|
+
subunit: 2
|
|
163
|
+
symbol: Sh
|
|
164
|
+
name: Somali Shilling
|
|
165
|
+
priority: 110
|
|
154
166
|
- code: BDT
|
|
155
167
|
country: BGD
|
|
156
168
|
subunit: 2
|
|
@@ -169,12 +181,24 @@
|
|
|
169
181
|
symbol: "₽"
|
|
170
182
|
name: Russian Ruble
|
|
171
183
|
priority: 107
|
|
184
|
+
- code: SYP
|
|
185
|
+
country: SYR
|
|
186
|
+
subunit: 2
|
|
187
|
+
symbol: "£"
|
|
188
|
+
name: Syrian Pound
|
|
189
|
+
priority: 106
|
|
172
190
|
- code: ETB
|
|
173
191
|
country: ETH
|
|
174
192
|
subunit: 2
|
|
175
193
|
symbol: Br
|
|
176
194
|
name: Ethiopian Birr
|
|
177
195
|
priority: 105
|
|
196
|
+
- code: ZWL
|
|
197
|
+
country: ZWE
|
|
198
|
+
subunit: 2
|
|
199
|
+
symbol: Z$
|
|
200
|
+
name: Zimbabwean Dollar
|
|
201
|
+
priority: 104
|
|
178
202
|
- code: PHP
|
|
179
203
|
country: PHL
|
|
180
204
|
subunit: 2
|
|
@@ -211,6 +235,12 @@
|
|
|
211
235
|
symbol: "฿"
|
|
212
236
|
name: Thai Baht
|
|
213
237
|
priority: 98
|
|
238
|
+
- code: TMT
|
|
239
|
+
country: TKM
|
|
240
|
+
subunit: 2
|
|
241
|
+
symbol: m
|
|
242
|
+
name: Turkmenistani Manat
|
|
243
|
+
priority: 97
|
|
214
244
|
- code: TZS
|
|
215
245
|
country: TZA
|
|
216
246
|
subunit: 2
|
|
@@ -223,6 +253,12 @@
|
|
|
223
253
|
symbol: FCFA
|
|
224
254
|
name: Central African CFA franc
|
|
225
255
|
priority: 95
|
|
256
|
+
- code: DJF
|
|
257
|
+
country: DJI
|
|
258
|
+
subunit: 0
|
|
259
|
+
symbol: Fdj
|
|
260
|
+
name: Djiboutian Franc
|
|
261
|
+
priority: 94
|
|
226
262
|
- code: KES
|
|
227
263
|
country: KEN
|
|
228
264
|
subunit: 2
|
|
@@ -241,6 +277,12 @@
|
|
|
241
277
|
symbol: "$"
|
|
242
278
|
name: Colombian Peso
|
|
243
279
|
priority: 91
|
|
280
|
+
- code: ERN
|
|
281
|
+
country: ERI
|
|
282
|
+
subunit: 2
|
|
283
|
+
symbol: Nfk
|
|
284
|
+
name: Eritrean Nakfa
|
|
285
|
+
priority: 90
|
|
244
286
|
- code: UGX
|
|
245
287
|
country: UGA
|
|
246
288
|
subunit: 0
|
|
@@ -271,6 +313,12 @@
|
|
|
271
313
|
symbol: "؋"
|
|
272
314
|
name: Afghan Afghani
|
|
273
315
|
priority: 85
|
|
316
|
+
- code: LBP
|
|
317
|
+
country: LBN
|
|
318
|
+
subunit: 2
|
|
319
|
+
symbol: "£"
|
|
320
|
+
name: Lebanese Pound
|
|
321
|
+
priority: 84
|
|
274
322
|
- code: MAD
|
|
275
323
|
country: MAR
|
|
276
324
|
subunit: 2
|
|
@@ -283,6 +331,12 @@
|
|
|
283
331
|
symbol: zł
|
|
284
332
|
name: Polish Zloty
|
|
285
333
|
priority: 82
|
|
334
|
+
- code: SVC
|
|
335
|
+
country: SLV
|
|
336
|
+
subunit: 2
|
|
337
|
+
symbol: "$"
|
|
338
|
+
name: El Salvadoran Colón
|
|
339
|
+
priority: 81
|
|
286
340
|
- code: UAH
|
|
287
341
|
country: UKR
|
|
288
342
|
subunit: 2
|
|
@@ -337,6 +391,12 @@
|
|
|
337
391
|
symbol: Bs.
|
|
338
392
|
name: Venezuelan Bolívar
|
|
339
393
|
priority: 72
|
|
394
|
+
- code: SSP
|
|
395
|
+
country: SSD
|
|
396
|
+
subunit: 2
|
|
397
|
+
symbol: "£"
|
|
398
|
+
name: South Sudanese Pound
|
|
399
|
+
priority: 71
|
|
340
400
|
- code: TWD
|
|
341
401
|
country: TWN
|
|
342
402
|
subunit: 2
|
|
@@ -445,6 +505,18 @@
|
|
|
445
505
|
symbol: د.ا
|
|
446
506
|
name: Jordanian Dinar
|
|
447
507
|
priority: 53
|
|
508
|
+
- code: ALL
|
|
509
|
+
country: ALB
|
|
510
|
+
subunit: 2
|
|
511
|
+
symbol: L
|
|
512
|
+
name: Albanian Lek
|
|
513
|
+
priority: 52
|
|
514
|
+
- code: MKD
|
|
515
|
+
country: MKD
|
|
516
|
+
subunit: 2
|
|
517
|
+
symbol: ден
|
|
518
|
+
name: North Macedonian Denar
|
|
519
|
+
priority: 51
|
|
448
520
|
- code: AZN
|
|
449
521
|
country: AZE
|
|
450
522
|
subunit: 2
|
|
@@ -481,6 +553,18 @@
|
|
|
481
553
|
symbol: Br
|
|
482
554
|
name: Belarusian Ruble
|
|
483
555
|
priority: 45
|
|
556
|
+
- code: BAM
|
|
557
|
+
country: BIH
|
|
558
|
+
subunit: 2
|
|
559
|
+
symbol: KM
|
|
560
|
+
name: Bosnia and Herzegovina Convertible Mark
|
|
561
|
+
priority: 44
|
|
562
|
+
- code: MOP
|
|
563
|
+
country: MAC
|
|
564
|
+
subunit: 2
|
|
565
|
+
symbol: P
|
|
566
|
+
name: Macanese Pataca
|
|
567
|
+
priority: 43
|
|
484
568
|
- code: LAK
|
|
485
569
|
country: LAO
|
|
486
570
|
subunit: 2
|
|
@@ -493,6 +577,12 @@
|
|
|
493
577
|
symbol: лв
|
|
494
578
|
name: Kyrgyzstani Som
|
|
495
579
|
priority: 41
|
|
580
|
+
- code: MVR
|
|
581
|
+
country: MDV
|
|
582
|
+
subunit: 2
|
|
583
|
+
symbol: Rf
|
|
584
|
+
name: Maldivian Rufiyaa
|
|
585
|
+
priority: 40
|
|
496
586
|
- code: LYD
|
|
497
587
|
country: LBY
|
|
498
588
|
subunit: 3
|
|
@@ -523,6 +613,30 @@
|
|
|
523
613
|
symbol: лв
|
|
524
614
|
name: Bulgarian Lev
|
|
525
615
|
priority: 36
|
|
616
|
+
- code: GNF
|
|
617
|
+
country: GIN
|
|
618
|
+
subunit: 0
|
|
619
|
+
symbol: Fr
|
|
620
|
+
name: Guinean Franc
|
|
621
|
+
priority: 35
|
|
622
|
+
- code: GMD
|
|
623
|
+
country: GMB
|
|
624
|
+
subunit: 2
|
|
625
|
+
symbol: D
|
|
626
|
+
name: Gambian Dalasi
|
|
627
|
+
priority: 34
|
|
628
|
+
- code: SLL
|
|
629
|
+
country: SLE
|
|
630
|
+
subunit: 2
|
|
631
|
+
symbol: Le
|
|
632
|
+
name: Sierra Leonean Leone
|
|
633
|
+
priority: 33
|
|
634
|
+
- code: STN
|
|
635
|
+
country: STP
|
|
636
|
+
subunit: 2
|
|
637
|
+
symbol: Db
|
|
638
|
+
name: São Tomé and Príncipe Dobra
|
|
639
|
+
priority: 31
|
|
526
640
|
- code: CRC
|
|
527
641
|
country: CRI
|
|
528
642
|
subunit: 2
|
|
@@ -535,6 +649,12 @@
|
|
|
535
649
|
symbol: د.ك
|
|
536
650
|
name: Kuwaiti Dinar
|
|
537
651
|
priority: 30
|
|
652
|
+
- code: BTN
|
|
653
|
+
country: BTN
|
|
654
|
+
subunit: 2
|
|
655
|
+
symbol: Nu.
|
|
656
|
+
name: Bhutanese Ngultrum
|
|
657
|
+
priority: 30
|
|
538
658
|
- code: OMR
|
|
539
659
|
country: OMN
|
|
540
660
|
subunit: 3
|
|
@@ -553,6 +673,12 @@
|
|
|
553
673
|
symbol: kn
|
|
554
674
|
name: Croatian Kuna
|
|
555
675
|
priority: 27
|
|
676
|
+
- code: KMF
|
|
677
|
+
country: COM
|
|
678
|
+
subunit: 0
|
|
679
|
+
symbol: CF
|
|
680
|
+
name: Comorian Franc
|
|
681
|
+
priority: 26
|
|
556
682
|
- code: GEL
|
|
557
683
|
country: GEO
|
|
558
684
|
subunit: 2
|
|
@@ -565,6 +691,12 @@
|
|
|
565
691
|
symbol: "$U"
|
|
566
692
|
name: Uruguayan Peso
|
|
567
693
|
priority: 25
|
|
694
|
+
- code: SCR
|
|
695
|
+
country: SYC
|
|
696
|
+
subunit: 2
|
|
697
|
+
symbol: "₨"
|
|
698
|
+
name: Seychellois Rupee
|
|
699
|
+
priority: 24
|
|
568
700
|
- code: AMD
|
|
569
701
|
country: ARM
|
|
570
702
|
subunit: 2
|
|
@@ -583,6 +715,12 @@
|
|
|
583
715
|
symbol: "﷼"
|
|
584
716
|
name: Qatari Riyal
|
|
585
717
|
priority: 22
|
|
718
|
+
- code: MUR
|
|
719
|
+
country: MUS
|
|
720
|
+
subunit: 2
|
|
721
|
+
symbol: "₨"
|
|
722
|
+
name: Mauritian Rupee
|
|
723
|
+
priority: 22
|
|
586
724
|
- code: BWP
|
|
587
725
|
country: BWA
|
|
588
726
|
subunit: 2
|
|
@@ -595,24 +733,48 @@
|
|
|
595
733
|
symbol: L
|
|
596
734
|
name: Moldovan Leu
|
|
597
735
|
priority: 20
|
|
736
|
+
- code: ANG
|
|
737
|
+
country: null
|
|
738
|
+
subunit: 2
|
|
739
|
+
symbol: ƒ
|
|
740
|
+
name: Netherlands Antillean Guilder
|
|
741
|
+
priority: 19
|
|
598
742
|
- code: NAD
|
|
599
743
|
country: NAM
|
|
600
744
|
subunit: 2
|
|
601
745
|
symbol: N$
|
|
602
746
|
name: Namibian Dollar
|
|
603
747
|
priority: 19
|
|
748
|
+
- code: CVE
|
|
749
|
+
country: CPV
|
|
750
|
+
subunit: 2
|
|
751
|
+
symbol: $
|
|
752
|
+
name: Cape Verdean Escudo
|
|
753
|
+
priority: 18
|
|
604
754
|
- code: LSL
|
|
605
755
|
country: LSO
|
|
606
756
|
subunit: 2
|
|
607
757
|
symbol: L
|
|
608
758
|
name: Lesotho Loti
|
|
609
759
|
priority: 18
|
|
760
|
+
- code: GIP
|
|
761
|
+
country: GIB
|
|
762
|
+
subunit: 2
|
|
763
|
+
symbol: £
|
|
764
|
+
name: Gibraltar Pound
|
|
765
|
+
priority: 17
|
|
610
766
|
- code: BHD
|
|
611
767
|
country: BHR
|
|
612
768
|
subunit: 3
|
|
613
769
|
symbol: ".د.ب"
|
|
614
770
|
name: Bahraini Dinar
|
|
615
771
|
priority: 17
|
|
772
|
+
- code: FKP
|
|
773
|
+
country: FLK
|
|
774
|
+
subunit: 2
|
|
775
|
+
symbol: £
|
|
776
|
+
name: Falkland Islands Pound
|
|
777
|
+
priority: 16
|
|
616
778
|
- code: TTD
|
|
617
779
|
country: TTO
|
|
618
780
|
subunit: 2
|
|
@@ -710,8 +872,123 @@
|
|
|
710
872
|
name: Tongan Paʻanga
|
|
711
873
|
priority: 1
|
|
712
874
|
- code: XXX
|
|
713
|
-
country:
|
|
875
|
+
country: null
|
|
714
876
|
subunit: 0
|
|
715
877
|
symbol: ¤
|
|
716
878
|
name: No Currency
|
|
717
879
|
priority: 0
|
|
880
|
+
- code: AWG
|
|
881
|
+
country: ABW
|
|
882
|
+
subunit: 2
|
|
883
|
+
symbol: ƒ
|
|
884
|
+
name: Aruban Florin
|
|
885
|
+
priority: 0
|
|
886
|
+
- code: BMD
|
|
887
|
+
country: BMU
|
|
888
|
+
subunit: 2
|
|
889
|
+
symbol: "$"
|
|
890
|
+
name: Bermudian Dollar
|
|
891
|
+
priority: 0
|
|
892
|
+
- code: CDF
|
|
893
|
+
country: COD
|
|
894
|
+
subunit: 2
|
|
895
|
+
symbol: Fr
|
|
896
|
+
name: Congolese Franc
|
|
897
|
+
priority: 0
|
|
898
|
+
- code: CUP
|
|
899
|
+
country: CUB
|
|
900
|
+
subunit: 2
|
|
901
|
+
symbol: "$"
|
|
902
|
+
name: Cuban Peso
|
|
903
|
+
priority: 0
|
|
904
|
+
- code: FOK
|
|
905
|
+
country: FRO
|
|
906
|
+
subunit: 2
|
|
907
|
+
symbol: kr
|
|
908
|
+
name: Faroese Króna
|
|
909
|
+
priority: 0
|
|
910
|
+
- code: GGP
|
|
911
|
+
country: GGY
|
|
912
|
+
subunit: 2
|
|
913
|
+
symbol: £
|
|
914
|
+
name: Guernsey Pound
|
|
915
|
+
priority: 0
|
|
916
|
+
- code: IMP
|
|
917
|
+
country: IMN
|
|
918
|
+
subunit: 2
|
|
919
|
+
symbol: £
|
|
920
|
+
name: Manx Pound
|
|
921
|
+
priority: 0
|
|
922
|
+
- code: JEP
|
|
923
|
+
country: JEY
|
|
924
|
+
subunit: 2
|
|
925
|
+
symbol: £
|
|
926
|
+
name: Jersey Pound
|
|
927
|
+
priority: 0
|
|
928
|
+
- code: KID
|
|
929
|
+
country: KIR
|
|
930
|
+
subunit: 2
|
|
931
|
+
symbol: "$"
|
|
932
|
+
name: Kiribati Dollar
|
|
933
|
+
priority: 0
|
|
934
|
+
- code: KYD
|
|
935
|
+
country: CYM
|
|
936
|
+
subunit: 2
|
|
937
|
+
symbol: "$"
|
|
938
|
+
name: Cayman Islands Dollar
|
|
939
|
+
priority: 0
|
|
940
|
+
- code: LRD
|
|
941
|
+
country: LBR
|
|
942
|
+
subunit: 2
|
|
943
|
+
symbol: "$"
|
|
944
|
+
name: Liberian Dollar
|
|
945
|
+
priority: 0
|
|
946
|
+
- code: MGA
|
|
947
|
+
country: MDG
|
|
948
|
+
subunit: 2
|
|
949
|
+
symbol: Ar
|
|
950
|
+
name: Malagasy Ariary
|
|
951
|
+
priority: 0
|
|
952
|
+
- code: MNT
|
|
953
|
+
country: MNG
|
|
954
|
+
subunit: 2
|
|
955
|
+
symbol: "₮"
|
|
956
|
+
name: Mongolian Tögrög
|
|
957
|
+
priority: 0
|
|
958
|
+
- code: MRU
|
|
959
|
+
country: MRT
|
|
960
|
+
subunit: 2
|
|
961
|
+
symbol: UM
|
|
962
|
+
name: Mauritanian Ouguiya
|
|
963
|
+
priority: 0
|
|
964
|
+
- code: SDG
|
|
965
|
+
country: SDN
|
|
966
|
+
subunit: 2
|
|
967
|
+
symbol: "£"
|
|
968
|
+
name: Sudanese Pound
|
|
969
|
+
priority: 0
|
|
970
|
+
- code: SHP
|
|
971
|
+
country: SHN
|
|
972
|
+
subunit: 2
|
|
973
|
+
symbol: "£"
|
|
974
|
+
name: Saint Helena Pound
|
|
975
|
+
priority: 0
|
|
976
|
+
- code: SLE
|
|
977
|
+
country: SLE
|
|
978
|
+
subunit: 2
|
|
979
|
+
symbol: Le
|
|
980
|
+
name: Sierra Leonean Leone (re-denominated)
|
|
981
|
+
priority: 0
|
|
982
|
+
- code: TVD
|
|
983
|
+
country: TUV
|
|
984
|
+
subunit: 2
|
|
985
|
+
symbol: "$"
|
|
986
|
+
name: Tuvaluan Dollar
|
|
987
|
+
priority: 0
|
|
988
|
+
- code: XDR
|
|
989
|
+
country: null
|
|
990
|
+
subunit: 0
|
|
991
|
+
symbol: SDR
|
|
992
|
+
name: Special Drawing Rights
|
|
993
|
+
priority: 0
|
|
994
|
+
|
|
@@ -6,8 +6,8 @@ require 'yaml'
|
|
|
6
6
|
module Mint
|
|
7
7
|
# Internal currency registry
|
|
8
8
|
# Manages the registry cache and currency symbol lookups.
|
|
9
|
-
module
|
|
10
|
-
|
|
9
|
+
module CurrencyRegistry
|
|
10
|
+
extend self
|
|
11
11
|
|
|
12
12
|
# Returns the hash of all registered currencies.
|
|
13
13
|
#
|
|
@@ -30,6 +30,32 @@ module Mint
|
|
|
30
30
|
end.freeze
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# Registers a new currency, raising a KeyError if already registered.
|
|
34
|
+
#
|
|
35
|
+
# @param code [String] the unique currency code
|
|
36
|
+
# @param subunit [Integer] the decimal subunit precision, defaults to 0
|
|
37
|
+
# @param symbol [String] the display symbol
|
|
38
|
+
# @param priority [Integer] parser precedence priority
|
|
39
|
+
# @return [Currency] the newly registered Currency instance
|
|
40
|
+
# @raise [ArgumentError] if the code contains invalid characters
|
|
41
|
+
# @raise [KeyError] if the currency code is already registered
|
|
42
|
+
def register(code:, subunit: 0, symbol: '', priority: 0)
|
|
43
|
+
raise ArgumentError, 'Currency code must be String' unless code.is_a? String
|
|
44
|
+
unless code.match?(/^[A-Z_]+$/)
|
|
45
|
+
raise ArgumentError,
|
|
46
|
+
"Currency code must have only letters or '_' ('USD',, 'MY_COIN')"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
currencies = CurrencyRegistry.currencies
|
|
50
|
+
raise KeyError, "Currency: #{code} already registered" if currencies[code]
|
|
51
|
+
|
|
52
|
+
currency = currencies[code] = Currency.new(code:, subunit:, symbol:, priority:)
|
|
53
|
+
invalidate_symbols_cache
|
|
54
|
+
currency
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
33
59
|
# Clears and refreshes the currency symbol cache.
|
|
34
60
|
# Called when currencies are registered.
|
|
35
61
|
#
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Mint list of world currencies
|
|
3
4
|
module Mint
|
|
4
|
-
module_function
|
|
5
|
-
|
|
6
5
|
# Loads ISO world currencies from YAML file into the registry.
|
|
7
6
|
#
|
|
8
7
|
# @return [Hash{String => Currency}] ISO-4217 world currencies mapped by code
|
|
9
8
|
# @api private
|
|
10
|
-
def world_currencies
|
|
9
|
+
def self.world_currencies
|
|
11
10
|
@world_currencies ||= begin
|
|
12
|
-
path = File.join(File.expand_path('
|
|
11
|
+
path = File.join(File.expand_path('../../data', __dir__), 'world-currencies.yaml')
|
|
13
12
|
|
|
14
13
|
YAML.load_file(path).to_h { |entry| [entry['code'], Currency.new(**entry.transform_keys(&:to_sym))] }
|
|
15
14
|
end.freeze
|
data/lib/minting/mint/mint.rb
CHANGED
|
@@ -23,8 +23,21 @@ module Mint
|
|
|
23
23
|
case currency
|
|
24
24
|
when nil then nil
|
|
25
25
|
when Currency then currency
|
|
26
|
-
when String then
|
|
26
|
+
when String then CurrencyRegistry.currencies[currency]
|
|
27
27
|
else raise ArgumentError, "currency must be [Currency] ot [String] (#{currency})"
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
|
+
|
|
31
|
+
# Registers a new currency, raising a KeyError if already registered.
|
|
32
|
+
#
|
|
33
|
+
# @param code [String] the unique currency code
|
|
34
|
+
# @param subunit [Integer] the decimal subunit precision, defaults to 0
|
|
35
|
+
# @param symbol [String] the display symbol
|
|
36
|
+
# @param priority [Integer] parser precedence priority
|
|
37
|
+
# @return [Currency] the newly registered Currency instance
|
|
38
|
+
# @raise [ArgumentError] if the code contains invalid characters
|
|
39
|
+
# @raise [KeyError] if the currency code is already registered
|
|
40
|
+
def self.register_currency(code:, subunit: 0, symbol: '', priority: 0)
|
|
41
|
+
CurrencyRegistry.register(code:, subunit:, symbol:, priority:)
|
|
42
|
+
end
|
|
30
43
|
end
|
data/lib/minting/mint/parser.rb
CHANGED
|
@@ -69,7 +69,7 @@ module Mint
|
|
|
69
69
|
return currency if currency
|
|
70
70
|
|
|
71
71
|
# Fall back to registered symbols, longest first (HK$ before $).
|
|
72
|
-
|
|
72
|
+
CurrencyRegistry.currency_symbols.each do |symbol, currency|
|
|
73
73
|
return currency if input.include?(symbol)
|
|
74
74
|
end
|
|
75
75
|
end
|
data/lib/minting/mint.rb
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'minting/mint/currency'
|
|
4
|
-
require 'minting/mint/
|
|
3
|
+
require 'minting/mint/currency/currency'
|
|
4
|
+
require 'minting/mint/currency/currency_registry'
|
|
5
|
+
require 'minting/mint/currency/world_currencies'
|
|
5
6
|
require 'minting/mint/mint'
|
|
6
7
|
require 'minting/mint/parser'
|
|
7
|
-
require 'minting/mint/registry'
|
|
8
8
|
require 'minting/mint/refinements'
|
|
9
|
-
require 'minting/mint/world_currencies'
|
|
10
9
|
require 'minting/money/allocation'
|
|
11
10
|
require 'minting/money/arithmetics'
|
|
12
11
|
require 'minting/money/coercion'
|
|
@@ -91,9 +91,9 @@ module Mint
|
|
|
91
91
|
end
|
|
92
92
|
format ||= '%<symbol>s%<amount>f'
|
|
93
93
|
|
|
94
|
-
# Automatically adjust decimal places based on currency subunit
|
|
95
|
-
adjusted_format = format
|
|
96
|
-
|
|
94
|
+
# Automatically adjust decimal places based on currency subunit if missing
|
|
95
|
+
adjusted_format = format
|
|
96
|
+
.gsub(/%<amount>(\s*\+?\d*)f/, "%<amount>\\1.#{currency.subunit}f")
|
|
97
97
|
|
|
98
98
|
Kernel.format(adjusted_format,
|
|
99
99
|
amount: value,
|
data/lib/minting/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: minting
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.6.
|
|
4
|
+
version: 1.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gilson Ferraz
|
|
@@ -32,6 +32,7 @@ files:
|
|
|
32
32
|
- LICENSE
|
|
33
33
|
- README.md
|
|
34
34
|
- Rakefile
|
|
35
|
+
- bin/check-currencies
|
|
35
36
|
- bin/console
|
|
36
37
|
- bin/setup
|
|
37
38
|
- doc/agents/AGENTS.md
|
|
@@ -40,15 +41,14 @@ files:
|
|
|
40
41
|
- doc/agents/recommendations.md
|
|
41
42
|
- doc/agents/rubocop-issues.md
|
|
42
43
|
- lib/minting.rb
|
|
43
|
-
- lib/minting/data/currencies.yaml
|
|
44
|
+
- lib/minting/data/world-currencies.yaml
|
|
44
45
|
- lib/minting/mint.rb
|
|
45
|
-
- lib/minting/mint/currency.rb
|
|
46
|
-
- lib/minting/mint/
|
|
46
|
+
- lib/minting/mint/currency/currency.rb
|
|
47
|
+
- lib/minting/mint/currency/currency_registry.rb
|
|
48
|
+
- lib/minting/mint/currency/world_currencies.rb
|
|
47
49
|
- lib/minting/mint/mint.rb
|
|
48
50
|
- lib/minting/mint/parser.rb
|
|
49
51
|
- lib/minting/mint/refinements.rb
|
|
50
|
-
- lib/minting/mint/registry.rb
|
|
51
|
-
- lib/minting/mint/world_currencies.rb
|
|
52
52
|
- lib/minting/money/allocation.rb
|
|
53
53
|
- lib/minting/money/arithmetics.rb
|
|
54
54
|
- lib/minting/money/coercion.rb
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Mint currency registration and factory (public API)
|
|
4
|
-
module Mint
|
|
5
|
-
# Registers a new currency, raising a KeyError if already registered.
|
|
6
|
-
#
|
|
7
|
-
# @param code [String] the unique currency code
|
|
8
|
-
# @param subunit [Integer] the decimal subunit precision, defaults to 0
|
|
9
|
-
# @param symbol [String] the display symbol
|
|
10
|
-
# @param priority [Integer] parser precedence priority
|
|
11
|
-
# @return [Currency] the newly registered Currency instance
|
|
12
|
-
# @raise [ArgumentError] if the code contains invalid characters
|
|
13
|
-
# @raise [KeyError] if the currency code is already registered
|
|
14
|
-
def self.register_currency(code:, subunit: 0, symbol: '', priority: 0)
|
|
15
|
-
raise ArgumentError, 'Currency code must be String' unless code.is_a? String
|
|
16
|
-
unless code.match?(/^[A-Z_]+$/)
|
|
17
|
-
raise ArgumentError,
|
|
18
|
-
"Currency code must have only letters or '_' ('USD',, 'MY_COIN')"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
currencies = Registry.currencies
|
|
22
|
-
raise KeyError, "Currency: #{code} already registered" if currencies[code]
|
|
23
|
-
|
|
24
|
-
currency = currencies[code] = Currency.new(code:, subunit:, symbol:, priority:)
|
|
25
|
-
Registry.invalidate_symbols_cache
|
|
26
|
-
currency
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Registered symbols sorted for detection: longest match wins, then parser priority.
|
|
30
|
-
# Internal API - used by Money parser.
|
|
31
|
-
#
|
|
32
|
-
# @return [Array<Array<String, Currency>>] sorted symbol-to-currency mappings
|
|
33
|
-
# @api private
|
|
34
|
-
def self.currency_symbols
|
|
35
|
-
Registry.currency_symbols
|
|
36
|
-
end
|
|
37
|
-
end
|
|
File without changes
|