minting 1.9.7 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +234 -116
  3. data/Rakefile +2 -7
  4. data/doc/agents/api_review-2026-06-15.md +1 -1
  5. data/doc/agents/copilot-instructions.md +2 -2
  6. data/doc/agents/expired/copilot-instructions.md +2 -2
  7. data/doc/agents/expired/gemini_gem_evaluation.md +2 -2
  8. data/lib/minting/aliases.rb +22 -0
  9. data/lib/minting/currency/currency.rb +81 -9
  10. data/lib/minting/data/crypto-currencies.yaml +126 -0
  11. data/lib/minting/mint/i18n.rb +79 -29
  12. data/lib/minting/mint/mint.rb +1 -26
  13. data/lib/minting/mint/registry/crypto.rb +59 -0
  14. data/lib/minting/mint/registry/registration.rb +1 -2
  15. data/lib/minting/mint/registry/symbols.rb +37 -30
  16. data/lib/minting/mint/rounding.rb +9 -7
  17. data/lib/minting/mint.rb +1 -2
  18. data/lib/minting/money/allocation/allocation.rb +2 -2
  19. data/lib/minting/money/allocation/split.rb +1 -1
  20. data/lib/minting/money/arithmetics/operators.rb +10 -13
  21. data/lib/minting/money/clamp.rb +6 -6
  22. data/lib/minting/money/coercion.rb +1 -1
  23. data/lib/minting/money/comparable.rb +3 -3
  24. data/lib/minting/money/constructors.rb +3 -42
  25. data/lib/minting/money/conversion.rb +22 -18
  26. data/lib/minting/money/format/format.rb +100 -0
  27. data/lib/minting/money/format/formatter.rb +102 -0
  28. data/lib/minting/money/format/to_s.rb +20 -102
  29. data/lib/minting/money/format/validator.rb +34 -0
  30. data/lib/minting/money/money.rb +25 -9
  31. data/lib/minting/money/parse.rb +127 -0
  32. data/lib/minting/money/rounding.rb +27 -0
  33. data/lib/minting/version.rb +1 -1
  34. data/lib/minting.rb +17 -8
  35. metadata +9 -29
  36. data/doc/Mint/Currency.html +0 -2032
  37. data/doc/Mint/Money.html +0 -5139
  38. data/doc/Mint/RangeStepPatch.html +0 -277
  39. data/doc/Mint/Registry.html +0 -863
  40. data/doc/Mint/Rounding.html +0 -506
  41. data/doc/Mint/UnknownCurrency.html +0 -138
  42. data/doc/Mint.html +0 -931
  43. data/doc/Minting.html +0 -142
  44. data/doc/Numeric.html +0 -479
  45. data/doc/String.html +0 -241
  46. data/doc/_index.html +0 -206
  47. data/doc/class_list.html +0 -54
  48. data/doc/css/common.css +0 -1
  49. data/doc/css/full_list.css +0 -206
  50. data/doc/css/style.css +0 -1089
  51. data/doc/file.README.html +0 -291
  52. data/doc/file_list.html +0 -59
  53. data/doc/frames.html +0 -22
  54. data/doc/index.html +0 -291
  55. data/doc/js/app.js +0 -801
  56. data/doc/js/full_list.js +0 -334
  57. data/doc/js/jquery.js +0 -4
  58. data/doc/method_list.html +0 -758
  59. data/doc/top-level-namespace.html +0 -135
  60. data/lib/minting/mint/aliases.rb +0 -16
  61. data/lib/minting/mint/parser/parser.rb +0 -97
  62. data/lib/minting/mint/parser/separators.rb +0 -41
  63. data/lib/minting/money/format/formatting.rb +0 -130
data/doc/Mint.html DELETED
@@ -1,931 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Module: Mint
8
-
9
- &mdash; Documentation by YARD 0.9.44
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css">
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css">
16
-
17
- <script type="text/javascript">
18
- pathId = "Mint";
19
- relpath = '';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div id="main_progress" aria-hidden="true"></div>
31
-
32
- <div class="nav_wrap">
33
- <iframe id="nav" src="class_list.html?1"></iframe>
34
- <div id="resizer"></div>
35
- </div>
36
-
37
- <div id="main" tabindex="-1">
38
- <div id="header">
39
- <div id="menu">
40
-
41
- <a href="_index.html">Index (M)</a> &raquo;
42
-
43
-
44
- <span class="title">Mint</span>
45
-
46
- </div>
47
-
48
- <div id="search">
49
-
50
- <a class="full_list_link" id="class_list_link"
51
- href="class_list.html">
52
-
53
- <svg width="24" height="24">
54
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
55
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
56
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
57
- </svg>
58
- </a>
59
-
60
- </div>
61
- <div class="clear"></div>
62
- </div>
63
-
64
- <div id="content"><h1>Module: Mint
65
-
66
-
67
-
68
- </h1>
69
- <div class="box_info">
70
-
71
-
72
-
73
-
74
- <dl>
75
- <dt>Extended by:</dt>
76
- <dd><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></dd>
77
- </dl>
78
-
79
-
80
-
81
-
82
-
83
-
84
- <dl>
85
- <dt>Included in:</dt>
86
- <dd><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></dd>
87
- </dl>
88
-
89
-
90
-
91
- <dl>
92
- <dt>Defined in:</dt>
93
- <dd>lib/minting/mint/i18n.rb<span class="defines">,<br>
94
- lib/minting/mint/mint.rb,<br> lib/minting/money/clamp.rb,<br> lib/minting/money/money.rb,<br> lib/minting/mint/rounding.rb,<br> lib/minting/mint/dsl/range.rb,<br> lib/minting/money/coercion.rb,<br> lib/minting/money/comparable.rb,<br> lib/minting/money/conversion.rb,<br> lib/minting/currency/currency.rb,<br> lib/minting/money/format/to_s.rb,<br> lib/minting/mint/parser/parser.rb,<br> lib/minting/money/constructors.rb,<br> lib/minting/mint/registry/zeros.rb,<br> lib/minting/mint/registry/symbols.rb,<br> lib/minting/mint/parser/separators.rb,<br> lib/minting/mint/registry/registry.rb,<br> lib/minting/money/allocation/split.rb,<br> lib/minting/money/format/formatting.rb,<br> lib/minting/money/arithmetics/methods.rb,<br> lib/minting/mint/registry/registration.rb,<br> lib/minting/money/allocation/allocation.rb,<br> lib/minting/money/arithmetics/operators.rb</span>
95
-
96
- </dd>
97
- </dl>
98
-
99
- </div>
100
-
101
- <h2>Overview</h2><div class="docstring">
102
- <div class="discussion">
103
- <p>Mint registry: manages all cached state</p>
104
-
105
- </div>
106
- </div>
107
- <div class="tags">
108
-
109
-
110
- </div><h2>Defined Under Namespace</h2>
111
- <p class="children">
112
-
113
-
114
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="Mint/RangeStepPatch.html" title="Mint::RangeStepPatch (module)">RangeStepPatch</a></span>, <span class='object_link'><a href="Mint/Registry.html" title="Mint::Registry (module)">Registry</a></span>, <span class='object_link'><a href="Mint/Rounding.html" title="Mint::Rounding (module)">Rounding</a></span>
115
-
116
-
117
-
118
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>, <span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span>, <span class='object_link'><a href="Mint/UnknownCurrency.html" title="Mint::UnknownCurrency (class)">UnknownCurrency</a></span>
119
-
120
-
121
- </p>
122
-
123
-
124
-
125
-
126
- <h2>Class Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
127
- <ul class="summary">
128
-
129
- <li class="public ">
130
- <span class="summary_signature">
131
-
132
- <a href="#locale_backend-class_method" title="locale_backend (class method)">.<strong>locale_backend</strong> &#x21d2; Proc, ... </a>
133
-
134
-
135
-
136
- </span>
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
- <span class="summary_desc"><div class='inline'><p>Optional callable that returns a Hash with locale-aware formatting defaults.</p></div></span>
150
-
151
- </li>
152
-
153
-
154
- </ul>
155
-
156
-
157
-
158
-
159
-
160
- <h2>
161
- Class Method Summary
162
- <small><a href="#" class="summary_toggle">collapse</a></small>
163
- </h2>
164
-
165
- <ul class="summary">
166
-
167
- <li class="public ">
168
- <span class="summary_signature">
169
-
170
- <a href="#money-class_method" title="money (class method)">.<strong>money</strong>(amount, currency_code) &#x21d2; Money </a>
171
-
172
-
173
-
174
- </span>
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
- <span class="summary_desc"><div class='inline'><p>Creates a new <span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span> instance with the given amount and currency code.</p></div></span>
185
-
186
- </li>
187
-
188
-
189
- <li class="public ">
190
- <span class="summary_signature">
191
-
192
- <a href="#with_rounding-class_method" title="with_rounding (class method)">.<strong>with_rounding</strong>(mode) { ... } &#x21d2; Object </a>
193
-
194
-
195
-
196
- </span>
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
- <span class="summary_desc"><div class='inline'><p>Executes a block with a specific rounding mode applied to all money construction, parsing, change, allocation, and split operations.</p></div></span>
207
-
208
- </li>
209
-
210
-
211
- <li class="public ">
212
- <span class="summary_signature">
213
-
214
- <a href="#world_currencies-class_method" title="world_currencies (class method)">.<strong>world_currencies</strong> &#x21d2; Hash{String =&gt; Currency} </a>
215
-
216
-
217
-
218
- </span>
219
-
220
-
221
-
222
-
223
-
224
-
225
- <span class="private note title">private</span>
226
-
227
-
228
- <span class="summary_desc"><div class='inline'><p>The frozen world-currencies hash.</p></div></span>
229
-
230
- </li>
231
-
232
-
233
- </ul>
234
-
235
-
236
- <h2>
237
- Instance Method Summary
238
- <small><a href="#" class="summary_toggle">collapse</a></small>
239
- </h2>
240
-
241
- <ul class="summary">
242
-
243
- <li class="public ">
244
- <span class="summary_signature">
245
-
246
- <a href="#parse-instance_method" title="#parse (instance method)">#<strong>parse</strong>(input, currency = nil) &#x21d2; Money<sup>?</sup> </a>
247
-
248
-
249
-
250
- </span>
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
- <span class="summary_desc"><div class='inline'><p>Parses a human-readable money string into a <span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span> object.</p></div></span>
261
-
262
- </li>
263
-
264
-
265
- <li class="public ">
266
- <span class="summary_signature">
267
-
268
- <a href="#parse!-instance_method" title="#parse! (instance method)">#<strong>parse!</strong>(input, currency = nil) &#x21d2; Money </a>
269
-
270
-
271
-
272
- </span>
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
- <span class="summary_desc"><div class='inline'><p>Like <span class='object_link'><a href="#parse-instance_method" title="Mint#parse (method)">#parse</a></span> but raises on failure.</p></div></span>
283
-
284
- </li>
285
-
286
-
287
- </ul>
288
-
289
-
290
-
291
-
292
- <div id="class_attr_details" class="attr_details">
293
- <h2>Class Attribute Details</h2>
294
-
295
-
296
- <span id="locale_backend=-class_method"></span>
297
- <div class="method_details first">
298
- <h3 class="signature first" id="locale_backend-class_method">
299
-
300
- .<strong>locale_backend</strong> &#x21d2; <tt>Proc</tt>, ...
301
-
302
-
303
-
304
-
305
-
306
- </h3><div class="docstring">
307
- <div class="discussion">
308
- <p>Optional callable that returns a Hash with locale-aware formatting defaults.</p>
309
- <p>The callable receives no arguments and returns a Hash with these keys:</p>
310
- <pre class="code ruby"><code class="ruby">[+:decimal+] Decimal separator (e.g. +&quot;,&quot;+)
311
- [+:thousand+] Thousands delimiter (e.g. +&quot;.&quot;+)
312
- [+:format+] Format template string (e.g. +&quot;%&lt;amount&gt;f %&lt;symbol&gt;s&quot;+)
313
- </code></pre>
314
- <p>When set, <code>#to_formatted_s</code> and <code>#format</code> use these values as fallbacks when the
315
- corresponding parameter is not explicitly provided.</p>
316
-
317
- </div>
318
- </div>
319
- <div class="tags">
320
-
321
- <div class="examples">
322
- <h4 class="tag_title">Examples:</h4>
323
-
324
-
325
- <h5 class="example_title"><div class='inline'><p>Rails I18n integration (in attribute-money railtie)</p></div></h5>
326
-
327
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_locale_backend'>locale_backend</span> <span class='op'>=</span> <span class='tlambda'>-&gt;</span> <span class='tlambeg'>{</span>
328
- <span class='id identifier rubyid_fmt'>fmt</span> <span class='op'>=</span> <span class='const'>I18n</span><span class='period'>.</span><span class='id identifier rubyid_t'>t</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>number.currency.format</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
329
- <span class='lbrace'>{</span>
330
- <span class='label'>decimal:</span> <span class='id identifier rubyid_fmt'>fmt</span><span class='lbracket'>[</span><span class='symbol'>:separator</span><span class='rbracket'>]</span><span class='comma'>,</span>
331
- <span class='label'>thousand:</span> <span class='id identifier rubyid_fmt'>fmt</span><span class='lbracket'>[</span><span class='symbol'>:delimiter</span><span class='rbracket'>]</span><span class='comma'>,</span>
332
- <span class='label'>format:</span> <span class='id identifier rubyid_fmt'>fmt</span><span class='lbracket'>[</span><span class='symbol'>:format</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>%n %u</span><span class='tstring_end'>&#39;</span></span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>%&lt;amount&gt;f %&lt;symbol&gt;s</span><span class='tstring_end'>&#39;</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>%&lt;symbol&gt;s%&lt;amount&gt;f</span><span class='tstring_end'>&#39;</span></span>
333
- <span class='rbrace'>}</span>
334
- <span class='rbrace'>}</span></code></pre>
335
-
336
- </div>
337
-
338
- <p class="tag_title">Returns:</p>
339
- <ul class="return">
340
-
341
- <li>
342
-
343
-
344
- <span class='type'>(<tt>Proc</tt>, <tt>#call</tt>, <tt>nil</tt>)</span>
345
-
346
-
347
-
348
- </li>
349
-
350
- </ul>
351
-
352
- </div><table class="source_code">
353
- <tr>
354
- <td>
355
- <pre class="lines">
356
-
357
-
358
- 27
359
- 28
360
- 29</pre>
361
- </td>
362
- <td>
363
- <pre class="code"><span class="info file"># File 'lib/minting/mint/i18n.rb', line 27</span>
364
-
365
- <span class='kw'>def</span> <span class='id identifier rubyid_locale_backend'>locale_backend</span>
366
- <span class='ivar'>@locale_backend</span>
367
- <span class='kw'>end</span></pre>
368
- </td>
369
- </tr>
370
- </table>
371
- </div>
372
-
373
- </div>
374
-
375
-
376
- <div id="class_method_details" class="method_details_list">
377
- <h2>Class Method Details</h2>
378
-
379
-
380
- <div class="method_details first">
381
- <h3 class="signature first" id="money-class_method">
382
-
383
- .<strong>money</strong>(amount, currency_code) &#x21d2; <tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>
384
-
385
-
386
-
387
-
388
-
389
- </h3><div class="docstring">
390
- <div class="discussion">
391
- <p>Creates a new <span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span> instance with the given amount and currency code.</p>
392
-
393
- </div>
394
- </div>
395
- <div class="tags">
396
- <p class="tag_title">Parameters:</p>
397
- <ul class="param">
398
-
399
- <li>
400
-
401
- <span class='name'>amount</span>
402
-
403
-
404
- <span class='type'>(<tt><span class='object_link'><a href="Numeric.html" title="Numeric (class)">Numeric</a></span></tt>)</span>
405
-
406
-
407
-
408
- &mdash;
409
- <div class='inline'><p>the financial value</p></div>
410
-
411
- </li>
412
-
413
- <li>
414
-
415
- <span class='name'>currency_code</span>
416
-
417
-
418
- <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>, <tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>, <tt>nil</tt>)</span>
419
-
420
-
421
-
422
- &mdash;
423
- <div class='inline'><p>Currency code, object,
424
- Money whose currency to reuse, or <code>nil</code>. Passed through
425
- <span class='object_link'><a href="Mint/Currency.html#resolve!-class_method" title="Mint::Currency.resolve! (method)">Mint::Currency.resolve!</a></span> so all accepted types resolve to a registered
426
- currency.</p></div>
427
-
428
- </li>
429
-
430
- </ul>
431
-
432
- <p class="tag_title">Returns:</p>
433
- <ul class="return">
434
-
435
- <li>
436
-
437
-
438
- <span class='type'>(<tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>)</span>
439
-
440
-
441
-
442
- &mdash;
443
- <div class='inline'><p>the instantiated Money object</p></div>
444
-
445
- </li>
446
-
447
- </ul>
448
- <p class="tag_title">Raises:</p>
449
- <ul class="raise">
450
-
451
- <li>
452
-
453
-
454
- <span class='type'>(<tt>ArgumentError</tt>)</span>
455
-
456
-
457
-
458
- &mdash;
459
- <div class='inline'><p>if the amount is not a Numeric</p></div>
460
-
461
- </li>
462
-
463
- <li>
464
-
465
-
466
- <span class='type'>(<tt><span class='object_link'><a href="Mint/UnknownCurrency.html" title="Mint::UnknownCurrency (class)">Mint::UnknownCurrency</a></span></tt>)</span>
467
-
468
-
469
-
470
- &mdash;
471
- <div class='inline'><p>if the currency code is not registered.
472
- <code>Mint::UnknownCurrency</code> inherits from <code>ArgumentError</code>.</p></div>
473
-
474
- </li>
475
-
476
- </ul>
477
-
478
- </div><table class="source_code">
479
- <tr>
480
- <td>
481
- <pre class="lines">
482
-
483
-
484
- 23</pre>
485
- </td>
486
- <td>
487
- <pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 23</span>
488
-
489
- <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_money'>money</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='comma'>,</span> <span class='id identifier rubyid_currency_code'>currency_code</span><span class='rparen'>)</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from'><span class='object_link'><a href="Mint/Money.html#from-class_method" title="Mint::Money.from (method)">from</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='comma'>,</span> <span class='id identifier rubyid_currency_code'>currency_code</span><span class='rparen'>)</span></pre>
490
- </td>
491
- </tr>
492
- </table>
493
- </div>
494
-
495
- <div class="method_details ">
496
- <h3 class="signature " id="with_rounding-class_method">
497
-
498
- .<strong>with_rounding</strong>(mode) { ... } &#x21d2; <tt>Object</tt>
499
-
500
-
501
-
502
-
503
-
504
- </h3><div class="docstring">
505
- <div class="discussion">
506
- <p>Executes a block with a specific rounding mode applied to all money
507
- construction, parsing, change, allocation, and split operations.</p>
508
- <p>Restores the previous mode (or default) when the block exits, even on
509
- exception.</p>
510
- <p>Rounding-mode support is loaded lazily on first call. Once loaded,
511
- <code>Currency#normalize_amount</code> is patched to dispatch through the
512
- rounding module, adding ~10–35&amp;ns of overhead to every money creation
513
- or mutation. When rounding modes are never used (the common case),
514
- the fast path incurs zero overhead.</p>
515
-
516
- </div>
517
- </div>
518
- <div class="tags">
519
- <p class="tag_title">Parameters:</p>
520
- <ul class="param">
521
-
522
- <li>
523
-
524
- <span class='name'>mode</span>
525
-
526
-
527
- <span class='type'>(<tt>Symbol</tt>)</span>
528
-
529
-
530
-
531
- &mdash;
532
- <div class='inline'><p>one of: <code>:half_up</code>, <code>:half_down</code>, <code>:floor</code>,
533
- <code>:ceil</code>, <code>:truncate</code>, <code>:down</code></p></div>
534
-
535
- </li>
536
-
537
- </ul>
538
-
539
- <p class="tag_title">Yields:</p>
540
- <ul class="yield">
541
-
542
- <li>
543
-
544
-
545
- <span class='type'></span>
546
-
547
-
548
-
549
-
550
- <div class='inline'><p>block to execute with the rounding mode active</p></div>
551
-
552
- </li>
553
-
554
- </ul>
555
- <p class="tag_title">Raises:</p>
556
- <ul class="raise">
557
-
558
- <li>
559
-
560
-
561
- <span class='type'>(<tt>ArgumentError</tt>)</span>
562
-
563
-
564
-
565
- &mdash;
566
- <div class='inline'><p>if <code>mode</code> is not a recognised rounding mode</p></div>
567
-
568
- </li>
569
-
570
- </ul>
571
-
572
- </div><table class="source_code">
573
- <tr>
574
- <td>
575
- <pre class="lines">
576
-
577
-
578
- 45
579
- 46
580
- 47
581
- 48</pre>
582
- </td>
583
- <td>
584
- <pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 45</span>
585
-
586
- <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_with_rounding'>with_rounding</span><span class='lparen'>(</span><span class='id identifier rubyid_mode'>mode</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='rparen'>)</span>
587
- <span class='id identifier rubyid_require_relative'>require_relative</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>rounding</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mint/Rounding.html" title="Mint::Rounding (module)">Rounding</a></span></span><span class='rparen'>)</span>
588
- <span class='const'><span class='object_link'><a href="Mint/Rounding.html" title="Mint::Rounding (module)">Rounding</a></span></span><span class='period'>.</span><span class='id identifier rubyid_with_mode'><span class='object_link'><a href="Mint/Rounding.html#with_mode-class_method" title="Mint::Rounding.with_mode (method)">with_mode</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_mode'>mode</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='rparen'>)</span>
589
- <span class='kw'>end</span></pre>
590
- </td>
591
- </tr>
592
- </table>
593
- </div>
594
-
595
- <div class="method_details ">
596
- <h3 class="signature " id="world_currencies-class_method">
597
-
598
- .<strong>world_currencies</strong> &#x21d2; <tt>Hash{<span class='object_link'><a href="String.html" title="String (class)">String</a></span> =&gt; <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>}</tt>
599
-
600
-
601
-
602
-
603
-
604
- </h3><div class="docstring">
605
- <div class="discussion">
606
- <p class="note private">
607
- <strong>This method is part of a private API.</strong>
608
- You should avoid using this method if possible, as it may be removed or be changed in the future.
609
- </p>
610
- <p>Returns the frozen world-currencies hash.</p>
611
-
612
- </div>
613
- </div>
614
- <div class="tags">
615
-
616
- <p class="tag_title">Returns:</p>
617
- <ul class="return">
618
-
619
- <li>
620
-
621
-
622
- <span class='type'>(<tt>Hash{<span class='object_link'><a href="String.html" title="String (class)">String</a></span> =&gt; <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>}</tt>)</span>
623
-
624
-
625
-
626
- &mdash;
627
- <div class='inline'><p>the frozen world-currencies hash</p></div>
628
-
629
- </li>
630
-
631
- </ul>
632
-
633
- </div><table class="source_code">
634
- <tr>
635
- <td>
636
- <pre class="lines">
637
-
638
-
639
- 27</pre>
640
- </td>
641
- <td>
642
- <pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 27</span>
643
-
644
- <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_world_currencies'>world_currencies</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Mint/Registry.html" title="Mint::Registry (module)">Registry</a></span></span><span class='period'>.</span><span class='id identifier rubyid_world_currencies'><span class='object_link'><a href="Mint/Registry.html#world_currencies-class_method" title="Mint::Registry.world_currencies (method)">world_currencies</a></span></span></pre>
645
- </td>
646
- </tr>
647
- </table>
648
- </div>
649
-
650
- </div>
651
-
652
- <div id="instance_method_details" class="method_details_list">
653
- <h2>Instance Method Details</h2>
654
-
655
-
656
- <div class="method_details first">
657
- <h3 class="signature first" id="parse-instance_method">
658
-
659
- #<strong>parse</strong>(input, currency = nil) &#x21d2; <tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt><sup>?</sup>
660
-
661
-
662
-
663
-
664
-
665
- </h3><div class="docstring">
666
- <div class="discussion">
667
- <p>Parses a human-readable money string into a <span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span> object.</p>
668
- <p>Returns <code>nil</code> when the input is invalid or currency cannot be determined.</p>
669
-
670
- </div>
671
- </div>
672
- <div class="tags">
673
-
674
- <div class="examples">
675
- <h4 class="tag_title">Examples:</h4>
676
-
677
-
678
- <h5 class="example_title"><div class='inline'><p>With explicit currency</p></div></h5>
679
-
680
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>19.99</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>USD</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; [USD 19.99]
681
- </span><span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>garbage</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>USD</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; nil</span></code></pre>
682
-
683
-
684
- <h5 class="example_title"><div class='inline'><p>With symbol or code in the string</p></div></h5>
685
-
686
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>$19.99</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; [USD 19.99]
687
- </span><span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>USD 1,234.56</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; [USD 1234.56]</span></code></pre>
688
-
689
- </div>
690
- <p class="tag_title">Parameters:</p>
691
- <ul class="param">
692
-
693
- <li>
694
-
695
- <span class='name'>input</span>
696
-
697
-
698
- <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span>
699
-
700
-
701
-
702
- &mdash;
703
- <div class='inline'><p>Amount input, optionally including a currency symbol or code</p></div>
704
-
705
- </li>
706
-
707
- <li>
708
-
709
- <span class='name'>currency</span>
710
-
711
-
712
- <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>, <tt>Symbol</tt>, <tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>nil</tt>)</span>
713
-
714
-
715
- <em class="default">(defaults to: <tt>nil</tt>)</em>
716
-
717
-
718
- &mdash;
719
- <div class='inline'><p>ISO code when not present in <code>input</code></p></div>
720
-
721
- </li>
722
-
723
- </ul>
724
-
725
- <p class="tag_title">Returns:</p>
726
- <ul class="return">
727
-
728
- <li>
729
-
730
-
731
- <span class='type'>(<tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>, <tt>nil</tt>)</span>
732
-
733
-
734
-
735
- </li>
736
-
737
- </ul>
738
-
739
- </div><table class="source_code">
740
- <tr>
741
- <td>
742
- <pre class="lines">
743
-
744
-
745
- 22
746
- 23
747
- 24
748
- 25
749
- 26
750
- 27
751
- 28
752
- 29
753
- 30
754
- 31
755
- 32
756
- 33
757
- 34
758
- 35
759
- 36</pre>
760
- </td>
761
- <td>
762
- <pre class="code"><span class="info file"># File 'lib/minting/mint/parser/parser.rb', line 22</span>
763
-
764
- <span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
765
- <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="String.html" title="String (class)">String</a></span></span><span class='rparen'>)</span>
766
-
767
- <span class='id identifier rubyid_input'>input</span> <span class='op'>=</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span>
768
- <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
769
-
770
- <span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_currency'>parse_currency</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
771
- <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_currency'>currency</span>
772
-
773
- <span class='id identifier rubyid_amount'>amount</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_amount'>parse_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
774
- <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_amount'>amount</span>
775
-
776
- <span class='id identifier rubyid_amount'>amount</span> <span class='op'>=</span> <span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_normalize_amount'>normalize_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='rparen'>)</span>
777
- <span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
778
- <span class='kw'>end</span></pre>
779
- </td>
780
- </tr>
781
- </table>
782
- </div>
783
-
784
- <div class="method_details ">
785
- <h3 class="signature " id="parse!-instance_method">
786
-
787
- #<strong>parse!</strong>(input, currency = nil) &#x21d2; <tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>
788
-
789
-
790
-
791
-
792
-
793
- </h3><div class="docstring">
794
- <div class="discussion">
795
- <p>Like <span class='object_link'><a href="#parse-instance_method" title="Mint#parse (method)">#parse</a></span> but raises on failure.</p>
796
-
797
- </div>
798
- </div>
799
- <div class="tags">
800
-
801
- <div class="examples">
802
- <h4 class="tag_title">Examples:</h4>
803
-
804
-
805
- <pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse!'>parse!</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>19.99</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>USD</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; [USD 19.99]
806
- </span><span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse!'>parse!</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>garbage</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>USD</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; ArgumentError</span></code></pre>
807
-
808
- </div>
809
- <p class="tag_title">Parameters:</p>
810
- <ul class="param">
811
-
812
- <li>
813
-
814
- <span class='name'>input</span>
815
-
816
-
817
- <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span>
818
-
819
-
820
-
821
- &mdash;
822
- <div class='inline'><p>Amount input, optionally including a currency symbol or code</p></div>
823
-
824
- </li>
825
-
826
- <li>
827
-
828
- <span class='name'>currency</span>
829
-
830
-
831
- <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>, <tt>Symbol</tt>, <tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>nil</tt>)</span>
832
-
833
-
834
- <em class="default">(defaults to: <tt>nil</tt>)</em>
835
-
836
-
837
- &mdash;
838
- <div class='inline'><p>ISO code when not present in <code>input</code></p></div>
839
-
840
- </li>
841
-
842
- </ul>
843
-
844
- <p class="tag_title">Returns:</p>
845
- <ul class="return">
846
-
847
- <li>
848
-
849
-
850
- <span class='type'>(<tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>)</span>
851
-
852
-
853
-
854
- </li>
855
-
856
- </ul>
857
- <p class="tag_title">Raises:</p>
858
- <ul class="raise">
859
-
860
- <li>
861
-
862
-
863
- <span class='type'>(<tt>ArgumentError</tt>)</span>
864
-
865
-
866
-
867
- &mdash;
868
- <div class='inline'><p>when <code>input</code> is invalid or currency cannot be determined</p></div>
869
-
870
- </li>
871
-
872
- </ul>
873
-
874
- </div><table class="source_code">
875
- <tr>
876
- <td>
877
- <pre class="lines">
878
-
879
-
880
- 48
881
- 49
882
- 50
883
- 51
884
- 52
885
- 53
886
- 54
887
- 55
888
- 56
889
- 57
890
- 58
891
- 59
892
- 60
893
- 61
894
- 62</pre>
895
- </td>
896
- <td>
897
- <pre class="code"><span class="info file"># File 'lib/minting/mint/parser/parser.rb', line 48</span>
898
-
899
- <span class='kw'>def</span> <span class='id identifier rubyid_parse!'>parse!</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
900
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>input must be a String</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="String.html" title="String (class)">String</a></span></span><span class='rparen'>)</span>
901
-
902
- <span class='id identifier rubyid_input'>input</span> <span class='op'>=</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span>
903
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>input cannot be empty</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
904
-
905
- <span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_currency'>parse_currency</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
906
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Currency [</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_currency'>currency</span><span class='embexpr_end'>}</span><span class='tstring_content'>] not found</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_currency'>currency</span>
907
-
908
- <span class='id identifier rubyid_amount'>amount</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_amount'>parse_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
909
- <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Could not parse [</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_input'>input</span><span class='embexpr_end'>}</span><span class='tstring_content'>]</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_amount'>amount</span>
910
-
911
- <span class='id identifier rubyid_amount'>amount</span> <span class='op'>=</span> <span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_normalize_amount'>normalize_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='rparen'>)</span>
912
- <span class='const'><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
913
- <span class='kw'>end</span></pre>
914
- </td>
915
- </tr>
916
- </table>
917
- </div>
918
-
919
- </div>
920
-
921
- </div>
922
-
923
- <div id="footer">
924
- Generated on Wed Jul 1 01:11:52 2026 by
925
- <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
926
- 0.9.44 (ruby-4.0.5).
927
- </div>
928
-
929
- </div>
930
- </body>
931
- </html>