minting 1.7.3 → 1.8.1
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 +31 -24
- data/Rakefile +15 -4
- data/doc/Mint/Currency.html +535 -18
- data/doc/Mint/Money.html +659 -185
- data/doc/Mint/RangeStepPatch.html +1 -1
- data/doc/Mint/Registry.html +19 -2
- data/doc/Mint/Rounding.html +495 -0
- data/doc/Mint/UnknownCurrency.html +1 -1
- data/doc/Mint.html +187 -399
- data/doc/Minting.html +2 -2
- data/doc/_index.html +8 -1
- data/doc/agents/api_review-2026-06-15.md +0 -13
- data/doc/agents/copilot-instructions.md +70 -0
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +19 -9
- data/doc/index.html +19 -9
- data/doc/method_list.html +130 -42
- data/doc/top-level-namespace.html +1 -1
- data/lib/minting/currency/currency.rb +41 -2
- data/lib/minting/mint/dsl/numeric.rb +4 -4
- data/lib/minting/mint/dsl/range.rb +1 -0
- data/lib/minting/mint/dsl/string.rb +1 -1
- data/lib/minting/mint/mint.rb +10 -37
- data/lib/minting/mint/parser/parser.rb +50 -15
- data/lib/minting/mint/parser/separators.rb +10 -8
- data/lib/minting/mint/registry/zeros.rb +3 -1
- data/lib/minting/mint/rounding.rb +51 -0
- data/lib/minting/mint.rb +1 -0
- data/lib/minting/money/allocation/allocation.rb +1 -2
- data/lib/minting/money/allocation/split.rb +1 -1
- data/lib/minting/money/arithmetics/methods.rb +2 -2
- data/lib/minting/money/arithmetics/operators.rb +6 -6
- data/lib/minting/money/clamp.rb +1 -1
- data/lib/minting/money/coercion.rb +1 -1
- data/lib/minting/money/comparable.rb +6 -0
- data/lib/minting/money/constructors.rb +60 -12
- data/lib/minting/money/money.rb +0 -6
- data/lib/minting/version.rb +1 -1
- metadata +4 -1
data/doc/Mint.html
CHANGED
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
<dl>
|
|
92
92
|
<dt>Defined in:</dt>
|
|
93
93
|
<dd>lib/minting/mint/mint.rb<span class="defines">,<br>
|
|
94
|
-
lib/minting/money/clamp.rb,<br> lib/minting/money/money.rb,<br> lib/minting/mint/dsl/range.rb,<br> lib/minting/money/coercion.rb,<br> lib/minting/mint/dsl/string.rb,<br> lib/minting/mint/dsl/numeric.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/dsl/top_level.rb,<br> lib/minting/mint/parser/parser.rb,<br> lib/minting/money/constructors.rb,<br> lib/minting/mint/locale_backend.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>
|
|
94
|
+
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/mint/dsl/string.rb,<br> lib/minting/mint/dsl/numeric.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/dsl/top_level.rb,<br> lib/minting/mint/parser/parser.rb,<br> lib/minting/money/constructors.rb,<br> lib/minting/mint/locale_backend.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
95
|
|
|
96
96
|
</dd>
|
|
97
97
|
</dl>
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
<p class="children">
|
|
112
112
|
|
|
113
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>
|
|
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
115
|
|
|
116
116
|
|
|
117
117
|
|
|
@@ -167,50 +167,6 @@
|
|
|
167
167
|
<li class="public ">
|
|
168
168
|
<span class="summary_signature">
|
|
169
169
|
|
|
170
|
-
<a href="#currency_for_code-class_method" title="currency_for_code (class method)">.<strong>currency_for_code</strong>(code) ⇒ Currency<sup>?</sup> </a>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
</span>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
<span class="summary_desc"><div class='inline'><p>Looks up a registered currency by its alpha code.</p></div></span>
|
|
185
|
-
|
|
186
|
-
</li>
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
<li class="public ">
|
|
190
|
-
<span class="summary_signature">
|
|
191
|
-
|
|
192
|
-
<a href="#currency_for_symbol-class_method" title="currency_for_symbol (class method)">.<strong>currency_for_symbol</strong>(symbol) ⇒ Currency<sup>?</sup> </a>
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
</span>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
<span class="summary_desc"><div class='inline'><p>Looks up a currency by its display symbol.</p></div></span>
|
|
207
|
-
|
|
208
|
-
</li>
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
<li class="public ">
|
|
212
|
-
<span class="summary_signature">
|
|
213
|
-
|
|
214
170
|
<a href="#money-class_method" title="money (class method)">.<strong>money</strong>(amount, currency_code) ⇒ Money </a>
|
|
215
171
|
|
|
216
172
|
|
|
@@ -233,7 +189,7 @@
|
|
|
233
189
|
<li class="public ">
|
|
234
190
|
<span class="summary_signature">
|
|
235
191
|
|
|
236
|
-
<a href="#
|
|
192
|
+
<a href="#use_top_level_constants!-class_method" title="use_top_level_constants! (class method)">.<strong>use_top_level_constants!</strong> ⇒ Object </a>
|
|
237
193
|
|
|
238
194
|
|
|
239
195
|
|
|
@@ -247,7 +203,7 @@
|
|
|
247
203
|
|
|
248
204
|
|
|
249
205
|
|
|
250
|
-
<span class="summary_desc"><div class='inline'><p>Registers
|
|
206
|
+
<span class="summary_desc"><div class='inline'><p>Registers top-level ::Money and ::Currency constants as aliases for Mint's classes.</p></div></span>
|
|
251
207
|
|
|
252
208
|
</li>
|
|
253
209
|
|
|
@@ -255,7 +211,7 @@
|
|
|
255
211
|
<li class="public ">
|
|
256
212
|
<span class="summary_signature">
|
|
257
213
|
|
|
258
|
-
<a href="#
|
|
214
|
+
<a href="#with_rounding-class_method" title="with_rounding (class method)">.<strong>with_rounding</strong>(mode) { ... } ⇒ Object </a>
|
|
259
215
|
|
|
260
216
|
|
|
261
217
|
|
|
@@ -269,7 +225,7 @@
|
|
|
269
225
|
|
|
270
226
|
|
|
271
227
|
|
|
272
|
-
<span class="summary_desc"><div class='inline'><p>
|
|
228
|
+
<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>
|
|
273
229
|
|
|
274
230
|
</li>
|
|
275
231
|
|
|
@@ -296,10 +252,20 @@
|
|
|
296
252
|
</li>
|
|
297
253
|
|
|
298
254
|
|
|
255
|
+
</ul>
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
<h2>
|
|
259
|
+
Instance Method Summary
|
|
260
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
261
|
+
</h2>
|
|
262
|
+
|
|
263
|
+
<ul class="summary">
|
|
264
|
+
|
|
299
265
|
<li class="public ">
|
|
300
266
|
<span class="summary_signature">
|
|
301
267
|
|
|
302
|
-
<a href="#
|
|
268
|
+
<a href="#parse-instance_method" title="#parse (instance method)">#<strong>parse</strong>(input, currency = nil) ⇒ Money<sup>?</sup> </a>
|
|
303
269
|
|
|
304
270
|
|
|
305
271
|
|
|
@@ -313,25 +279,15 @@
|
|
|
313
279
|
|
|
314
280
|
|
|
315
281
|
|
|
316
|
-
<span class="summary_desc"><div class='inline'><p>
|
|
282
|
+
<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>
|
|
317
283
|
|
|
318
284
|
</li>
|
|
319
285
|
|
|
320
286
|
|
|
321
|
-
</ul>
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
<h2>
|
|
325
|
-
Instance Method Summary
|
|
326
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
327
|
-
</h2>
|
|
328
|
-
|
|
329
|
-
<ul class="summary">
|
|
330
|
-
|
|
331
287
|
<li class="public ">
|
|
332
288
|
<span class="summary_signature">
|
|
333
289
|
|
|
334
|
-
<a href="#parse
|
|
290
|
+
<a href="#parse!-instance_method" title="#parse! (instance method)">#<strong>parse!</strong>(input, currency = nil) ⇒ Money </a>
|
|
335
291
|
|
|
336
292
|
|
|
337
293
|
|
|
@@ -345,7 +301,7 @@
|
|
|
345
301
|
|
|
346
302
|
|
|
347
303
|
|
|
348
|
-
<span class="summary_desc"><div class='inline'><p>
|
|
304
|
+
<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>
|
|
349
305
|
|
|
350
306
|
</li>
|
|
351
307
|
|
|
@@ -444,9 +400,9 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
444
400
|
|
|
445
401
|
|
|
446
402
|
<div class="method_details first">
|
|
447
|
-
<h3 class="signature first" id="
|
|
403
|
+
<h3 class="signature first" id="money-class_method">
|
|
448
404
|
|
|
449
|
-
.<strong>
|
|
405
|
+
.<strong>money</strong>(amount, currency_code) ⇒ <tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>
|
|
450
406
|
|
|
451
407
|
|
|
452
408
|
|
|
@@ -454,8 +410,7 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
454
410
|
|
|
455
411
|
</h3><div class="docstring">
|
|
456
412
|
<div class="discussion">
|
|
457
|
-
<p>
|
|
458
|
-
<p>Unlike currency, this performs a direct hash lookup and only accepts strings.</p>
|
|
413
|
+
<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>
|
|
459
414
|
|
|
460
415
|
</div>
|
|
461
416
|
</div>
|
|
@@ -465,105 +420,62 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
465
420
|
|
|
466
421
|
<li>
|
|
467
422
|
|
|
468
|
-
<span class='name'>
|
|
423
|
+
<span class='name'>amount</span>
|
|
469
424
|
|
|
470
425
|
|
|
471
|
-
<span class='type'>(<tt>
|
|
426
|
+
<span class='type'>(<tt>Numeric</tt>)</span>
|
|
472
427
|
|
|
473
428
|
|
|
474
429
|
|
|
475
430
|
—
|
|
476
|
-
<div class='inline'><p>the
|
|
431
|
+
<div class='inline'><p>the financial value</p></div>
|
|
477
432
|
|
|
478
433
|
</li>
|
|
479
434
|
|
|
480
|
-
</ul>
|
|
481
|
-
|
|
482
|
-
<p class="tag_title">Returns:</p>
|
|
483
|
-
<ul class="return">
|
|
484
|
-
|
|
485
435
|
<li>
|
|
486
436
|
|
|
437
|
+
<span class='name'>currency_code</span>
|
|
438
|
+
|
|
487
439
|
|
|
488
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>
|
|
440
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>String</tt>)</span>
|
|
489
441
|
|
|
490
442
|
|
|
491
443
|
|
|
492
444
|
—
|
|
493
|
-
<div class='inline'><p>
|
|
445
|
+
<div class='inline'><p>Currency code</p></div>
|
|
494
446
|
|
|
495
447
|
</li>
|
|
496
448
|
|
|
497
449
|
</ul>
|
|
498
450
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
<td>
|
|
502
|
-
<pre class="lines">
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
27
|
|
506
|
-
28
|
|
507
|
-
29</pre>
|
|
508
|
-
</td>
|
|
509
|
-
<td>
|
|
510
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 27</span>
|
|
511
|
-
|
|
512
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_currency_for_code'>currency_for_code</span><span class='lparen'>(</span><span class='id identifier rubyid_code'>code</span><span class='rparen'>)</span>
|
|
513
|
-
<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_currencies'><span class='object_link'><a href="Mint/Registry.html#currencies-class_method" title="Mint::Registry.currencies (method)">currencies</a></span></span><span class='lbracket'>[</span><span class='id identifier rubyid_code'>code</span><span class='rbracket'>]</span>
|
|
514
|
-
<span class='kw'>end</span></pre>
|
|
515
|
-
</td>
|
|
516
|
-
</tr>
|
|
517
|
-
</table>
|
|
518
|
-
</div>
|
|
519
|
-
|
|
520
|
-
<div class="method_details ">
|
|
521
|
-
<h3 class="signature " id="currency_for_symbol-class_method">
|
|
522
|
-
|
|
523
|
-
.<strong>currency_for_symbol</strong>(symbol) ⇒ <tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt><sup>?</sup>
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
</h3><div class="docstring">
|
|
530
|
-
<div class="discussion">
|
|
531
|
-
<p>Looks up a currency by its display symbol.</p>
|
|
532
|
-
|
|
533
|
-
</div>
|
|
534
|
-
</div>
|
|
535
|
-
<div class="tags">
|
|
536
|
-
<p class="tag_title">Parameters:</p>
|
|
537
|
-
<ul class="param">
|
|
451
|
+
<p class="tag_title">Returns:</p>
|
|
452
|
+
<ul class="return">
|
|
538
453
|
|
|
539
454
|
<li>
|
|
540
455
|
|
|
541
|
-
<span class='name'>symbol</span>
|
|
542
|
-
|
|
543
456
|
|
|
544
|
-
<span class='type'>(<tt>
|
|
457
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
545
458
|
|
|
546
459
|
|
|
547
460
|
|
|
548
461
|
—
|
|
549
|
-
<div class='inline'><p>the
|
|
462
|
+
<div class='inline'><p>the instantiated Money object</p></div>
|
|
550
463
|
|
|
551
464
|
</li>
|
|
552
465
|
|
|
553
466
|
</ul>
|
|
554
|
-
|
|
555
|
-
<
|
|
556
|
-
<ul class="return">
|
|
467
|
+
<p class="tag_title">Raises:</p>
|
|
468
|
+
<ul class="raise">
|
|
557
469
|
|
|
558
470
|
<li>
|
|
559
471
|
|
|
560
472
|
|
|
561
|
-
<span class='type'>(<tt
|
|
473
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
562
474
|
|
|
563
475
|
|
|
564
476
|
|
|
565
477
|
—
|
|
566
|
-
<div class='inline'><p>the
|
|
478
|
+
<div class='inline'><p>if the currency code is not registered</p></div>
|
|
567
479
|
|
|
568
480
|
</li>
|
|
569
481
|
|
|
@@ -575,25 +487,21 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
575
487
|
<pre class="lines">
|
|
576
488
|
|
|
577
489
|
|
|
578
|
-
|
|
579
|
-
36
|
|
580
|
-
37</pre>
|
|
490
|
+
15</pre>
|
|
581
491
|
</td>
|
|
582
492
|
<td>
|
|
583
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line
|
|
493
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 15</span>
|
|
584
494
|
|
|
585
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
|
586
|
-
<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_currency_for_symbol'><span class='object_link'><a href="Mint/Registry.html#currency_for_symbol-instance_method" title="Mint::Registry#currency_for_symbol (method)">currency_for_symbol</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_symbol'>symbol</span><span class='rparen'>)</span>
|
|
587
|
-
<span class='kw'>end</span></pre>
|
|
495
|
+
<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>
|
|
588
496
|
</td>
|
|
589
497
|
</tr>
|
|
590
498
|
</table>
|
|
591
499
|
</div>
|
|
592
500
|
|
|
593
501
|
<div class="method_details ">
|
|
594
|
-
<h3 class="signature " id="
|
|
502
|
+
<h3 class="signature " id="use_top_level_constants!-class_method">
|
|
595
503
|
|
|
596
|
-
.<strong>
|
|
504
|
+
.<strong>use_top_level_constants!</strong> ⇒ <tt>Object</tt>
|
|
597
505
|
|
|
598
506
|
|
|
599
507
|
|
|
@@ -601,72 +509,24 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
601
509
|
|
|
602
510
|
</h3><div class="docstring">
|
|
603
511
|
<div class="discussion">
|
|
604
|
-
<p>
|
|
512
|
+
<p>Registers top-level ::Money and ::Currency constants as aliases for Mint's classes.</p>
|
|
605
513
|
|
|
606
514
|
</div>
|
|
607
515
|
</div>
|
|
608
516
|
<div class="tags">
|
|
609
|
-
<p class="tag_title">Parameters:</p>
|
|
610
|
-
<ul class="param">
|
|
611
|
-
|
|
612
|
-
<li>
|
|
613
|
-
|
|
614
|
-
<span class='name'>amount</span>
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
<span class='type'>(<tt>Numeric</tt>)</span>
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
—
|
|
622
|
-
<div class='inline'><p>the financial value</p></div>
|
|
623
|
-
|
|
624
|
-
</li>
|
|
625
|
-
|
|
626
|
-
<li>
|
|
627
|
-
|
|
628
|
-
<span class='name'>currency_code</span>
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>String</tt>)</span>
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
—
|
|
636
|
-
<div class='inline'><p>Currency code</p></div>
|
|
637
|
-
|
|
638
|
-
</li>
|
|
639
|
-
|
|
640
|
-
</ul>
|
|
641
|
-
|
|
642
|
-
<p class="tag_title">Returns:</p>
|
|
643
|
-
<ul class="return">
|
|
644
517
|
|
|
645
|
-
<li>
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
—
|
|
653
|
-
<div class='inline'><p>the instantiated Money object</p></div>
|
|
654
|
-
|
|
655
|
-
</li>
|
|
656
|
-
|
|
657
|
-
</ul>
|
|
658
518
|
<p class="tag_title">Raises:</p>
|
|
659
519
|
<ul class="raise">
|
|
660
520
|
|
|
661
521
|
<li>
|
|
662
522
|
|
|
663
523
|
|
|
664
|
-
<span class='type'>(<tt>
|
|
524
|
+
<span class='type'>(<tt>NameError</tt>)</span>
|
|
665
525
|
|
|
666
526
|
|
|
667
527
|
|
|
668
528
|
—
|
|
669
|
-
<div class='inline'><p>if
|
|
529
|
+
<div class='inline'><p>if ::Money or ::Currency are already defined and differ</p></div>
|
|
670
530
|
|
|
671
531
|
</li>
|
|
672
532
|
|
|
@@ -678,21 +538,37 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
678
538
|
<pre class="lines">
|
|
679
539
|
|
|
680
540
|
|
|
681
|
-
|
|
541
|
+
8
|
|
542
|
+
9
|
|
543
|
+
10
|
|
544
|
+
11
|
|
545
|
+
12
|
|
546
|
+
13
|
|
547
|
+
14
|
|
548
|
+
15
|
|
549
|
+
16</pre>
|
|
682
550
|
</td>
|
|
683
551
|
<td>
|
|
684
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/
|
|
552
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/dsl/top_level.rb', line 8</span>
|
|
685
553
|
|
|
686
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
|
554
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_use_top_level_constants!'>use_top_level_constants!</span>
|
|
555
|
+
<span class='kw'>if</span> <span class='op'>!</span><span class='kw'>defined?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="top-level-namespace.html#Money-constant" title="Money (constant)">Money</a></span></span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='op'>!</span><span class='kw'>defined?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="top-level-namespace.html#Currency-constant" title="Currency (constant)">Currency</a></span></span><span class='rparen'>)</span>
|
|
556
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>minting/mint/aliases</span><span class='tstring_end'>'</span></span>
|
|
557
|
+
<span class='kw'>elsif</span> <span class='op'>::</span><span class='const'><span class='object_link'><a href="top-level-namespace.html#Money-constant" title="Money (constant)">Money</a></span></span> <span class='op'>==</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/Money.html" title="Mint::Money (class)">Money</a></span></span> <span class='op'>&&</span> <span class='op'>::</span><span class='const'><span class='object_link'><a href="top-level-namespace.html#Currency-constant" title="Currency (constant)">Currency</a></span></span> <span class='op'>==</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/Currency.html" title="Mint::Currency (class)">Currency</a></span></span>
|
|
558
|
+
<span class='id identifier rubyid_warn'>warn</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Warning: Money and Currency already defined as Mint aliases, skipping</span><span class='tstring_end'>'</span></span>
|
|
559
|
+
<span class='kw'>else</span>
|
|
560
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NameError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Cannot define top-level Money or Currency constants: already defined</span><span class='tstring_end'>'</span></span>
|
|
561
|
+
<span class='kw'>end</span>
|
|
562
|
+
<span class='kw'>end</span></pre>
|
|
687
563
|
</td>
|
|
688
564
|
</tr>
|
|
689
565
|
</table>
|
|
690
566
|
</div>
|
|
691
567
|
|
|
692
568
|
<div class="method_details ">
|
|
693
|
-
<h3 class="signature " id="
|
|
569
|
+
<h3 class="signature " id="with_rounding-class_method">
|
|
694
570
|
|
|
695
|
-
.<strong>
|
|
571
|
+
.<strong>with_rounding</strong>(mode) { ... } ⇒ <tt>Object</tt>
|
|
696
572
|
|
|
697
573
|
|
|
698
574
|
|
|
@@ -700,7 +576,10 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
700
576
|
|
|
701
577
|
</h3><div class="docstring">
|
|
702
578
|
<div class="discussion">
|
|
703
|
-
<p>
|
|
579
|
+
<p>Executes a block with a specific rounding mode applied to all money
|
|
580
|
+
construction, parsing, change, allocation, and split operations.</p>
|
|
581
|
+
<p>Restores the previous mode (or default) when the block exits, even on
|
|
582
|
+
exception.</p>
|
|
704
583
|
|
|
705
584
|
</div>
|
|
706
585
|
</div>
|
|
@@ -710,80 +589,33 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
710
589
|
|
|
711
590
|
<li>
|
|
712
591
|
|
|
713
|
-
<span class='name'>
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
<span class='type'>(<tt>String</tt>)</span>
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
—
|
|
721
|
-
<div class='inline'><p>the unique currency code</p></div>
|
|
722
|
-
|
|
723
|
-
</li>
|
|
724
|
-
|
|
725
|
-
<li>
|
|
726
|
-
|
|
727
|
-
<span class='name'>subunit</span>
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
<span class='type'>(<tt>Integer</tt>)</span>
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
<em class="default">(defaults to: <tt>0</tt>)</em>
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
—
|
|
737
|
-
<div class='inline'><p>the decimal subunit precision, defaults to 0</p></div>
|
|
738
|
-
|
|
739
|
-
</li>
|
|
740
|
-
|
|
741
|
-
<li>
|
|
742
|
-
|
|
743
|
-
<span class='name'>symbol</span>
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
<span class='type'>(<tt>String</tt>)</span>
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
<em class="default">(defaults to: <tt>''</tt>)</em>
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
—
|
|
753
|
-
<div class='inline'><p>the display symbol</p></div>
|
|
754
|
-
|
|
755
|
-
</li>
|
|
756
|
-
|
|
757
|
-
<li>
|
|
758
|
-
|
|
759
|
-
<span class='name'>priority</span>
|
|
760
|
-
|
|
592
|
+
<span class='name'>mode</span>
|
|
761
593
|
|
|
762
|
-
<span class='type'>(<tt>Integer</tt>)</span>
|
|
763
594
|
|
|
595
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
|
764
596
|
|
|
765
|
-
<em class="default">(defaults to: <tt>0</tt>)</em>
|
|
766
597
|
|
|
767
598
|
|
|
768
599
|
—
|
|
769
|
-
<div class='inline'><p>
|
|
600
|
+
<div class='inline'><p>one of: <code>:half_up</code>, <code>:half_down</code>, <code>:floor</code>,
|
|
601
|
+
<code>:ceil</code>, <code>:truncate</code>, <code>:down</code></p></div>
|
|
770
602
|
|
|
771
603
|
</li>
|
|
772
604
|
|
|
773
605
|
</ul>
|
|
774
606
|
|
|
775
|
-
<p class="tag_title">
|
|
776
|
-
<ul class="
|
|
607
|
+
<p class="tag_title">Yields:</p>
|
|
608
|
+
<ul class="yield">
|
|
777
609
|
|
|
778
610
|
<li>
|
|
779
611
|
|
|
780
612
|
|
|
781
|
-
<span class='type'
|
|
613
|
+
<span class='type'></span>
|
|
782
614
|
|
|
783
615
|
|
|
784
616
|
|
|
785
|
-
|
|
786
|
-
<div class='inline'><p>the
|
|
617
|
+
|
|
618
|
+
<div class='inline'><p>block to execute with the rounding mode active</p></div>
|
|
787
619
|
|
|
788
620
|
</li>
|
|
789
621
|
|
|
@@ -799,74 +631,7 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
799
631
|
|
|
800
632
|
|
|
801
633
|
—
|
|
802
|
-
<div class='inline'><p>if
|
|
803
|
-
|
|
804
|
-
</li>
|
|
805
|
-
|
|
806
|
-
<li>
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
<span class='type'>(<tt>KeyError</tt>)</span>
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
—
|
|
814
|
-
<div class='inline'><p>if the currency code is already registered</p></div>
|
|
815
|
-
|
|
816
|
-
</li>
|
|
817
|
-
|
|
818
|
-
</ul>
|
|
819
|
-
|
|
820
|
-
</div><table class="source_code">
|
|
821
|
-
<tr>
|
|
822
|
-
<td>
|
|
823
|
-
<pre class="lines">
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
56
|
|
827
|
-
57
|
|
828
|
-
58</pre>
|
|
829
|
-
</td>
|
|
830
|
-
<td>
|
|
831
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 56</span>
|
|
832
|
-
|
|
833
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_register_currency'>register_currency</span><span class='lparen'>(</span><span class='label'>code:</span><span class='comma'>,</span> <span class='label'>subunit:</span> <span class='int'>0</span><span class='comma'>,</span> <span class='label'>symbol:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>priority:</span> <span class='int'>0</span><span class='rparen'>)</span>
|
|
834
|
-
<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_register'><span class='object_link'><a href="Mint/Registry.html#register-class_method" title="Mint::Registry.register (method)">register</a></span></span><span class='lparen'>(</span><span class='label'>code:</span><span class='comma'>,</span> <span class='label'>subunit:</span><span class='comma'>,</span> <span class='label'>symbol:</span><span class='comma'>,</span> <span class='label'>priority:</span><span class='rparen'>)</span>
|
|
835
|
-
<span class='kw'>end</span></pre>
|
|
836
|
-
</td>
|
|
837
|
-
</tr>
|
|
838
|
-
</table>
|
|
839
|
-
</div>
|
|
840
|
-
|
|
841
|
-
<div class="method_details ">
|
|
842
|
-
<h3 class="signature " id="use_top_level_constants!-class_method">
|
|
843
|
-
|
|
844
|
-
.<strong>use_top_level_constants!</strong> ⇒ <tt>Object</tt>
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
</h3><div class="docstring">
|
|
851
|
-
<div class="discussion">
|
|
852
|
-
<p>Registers top-level ::Money and ::Currency constants as aliases for Mint's classes.</p>
|
|
853
|
-
|
|
854
|
-
</div>
|
|
855
|
-
</div>
|
|
856
|
-
<div class="tags">
|
|
857
|
-
|
|
858
|
-
<p class="tag_title">Raises:</p>
|
|
859
|
-
<ul class="raise">
|
|
860
|
-
|
|
861
|
-
<li>
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
<span class='type'>(<tt>NameError</tt>)</span>
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
—
|
|
869
|
-
<div class='inline'><p>if ::Money or ::Currency are already defined and differ</p></div>
|
|
634
|
+
<div class='inline'><p>if <code>mode</code> is not a recognised rounding mode</p></div>
|
|
870
635
|
|
|
871
636
|
</li>
|
|
872
637
|
|
|
@@ -878,28 +643,12 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
878
643
|
<pre class="lines">
|
|
879
644
|
|
|
880
645
|
|
|
881
|
-
|
|
882
|
-
9
|
|
883
|
-
10
|
|
884
|
-
11
|
|
885
|
-
12
|
|
886
|
-
13
|
|
887
|
-
14
|
|
888
|
-
15
|
|
889
|
-
16</pre>
|
|
646
|
+
31</pre>
|
|
890
647
|
</td>
|
|
891
648
|
<td>
|
|
892
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/
|
|
649
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 31</span>
|
|
893
650
|
|
|
894
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
|
895
|
-
<span class='kw'>if</span> <span class='op'>!</span><span class='kw'>defined?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="top-level-namespace.html#Money-constant" title="Money (constant)">Money</a></span></span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='op'>!</span><span class='kw'>defined?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="top-level-namespace.html#Currency-constant" title="Currency (constant)">Currency</a></span></span><span class='rparen'>)</span>
|
|
896
|
-
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>minting/mint/aliases</span><span class='tstring_end'>'</span></span>
|
|
897
|
-
<span class='kw'>elsif</span> <span class='op'>::</span><span class='const'><span class='object_link'><a href="top-level-namespace.html#Money-constant" title="Money (constant)">Money</a></span></span> <span class='op'>==</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/Money.html" title="Mint::Money (class)">Money</a></span></span> <span class='op'>&&</span> <span class='op'>::</span><span class='const'><span class='object_link'><a href="top-level-namespace.html#Currency-constant" title="Currency (constant)">Currency</a></span></span> <span class='op'>==</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/Currency.html" title="Mint::Currency (class)">Currency</a></span></span>
|
|
898
|
-
<span class='id identifier rubyid_warn'>warn</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Warning: Money and Currency already defined as Mint aliases, skipping</span><span class='tstring_end'>'</span></span>
|
|
899
|
-
<span class='kw'>else</span>
|
|
900
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>NameError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Cannot define top-level Money or Currency constants: already defined</span><span class='tstring_end'>'</span></span>
|
|
901
|
-
<span class='kw'>end</span>
|
|
902
|
-
<span class='kw'>end</span></pre>
|
|
651
|
+
<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'>&</span><span class='rparen'>)</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='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'>&</span><span class='rparen'>)</span></pre>
|
|
903
652
|
</td>
|
|
904
653
|
</tr>
|
|
905
654
|
</table>
|
|
@@ -960,10 +709,16 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
960
709
|
</table>
|
|
961
710
|
</div>
|
|
962
711
|
|
|
963
|
-
|
|
964
|
-
|
|
712
|
+
</div>
|
|
713
|
+
|
|
714
|
+
<div id="instance_method_details" class="method_details_list">
|
|
715
|
+
<h2>Instance Method Details</h2>
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
<div class="method_details first">
|
|
719
|
+
<h3 class="signature first" id="parse-instance_method">
|
|
965
720
|
|
|
966
|
-
|
|
721
|
+
#<strong>parse</strong>(input, currency = nil) ⇒ <tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt><sup>?</sup>
|
|
967
722
|
|
|
968
723
|
|
|
969
724
|
|
|
@@ -971,59 +726,73 @@ corresponding parameter is not explicitly provided.</p>
|
|
|
971
726
|
|
|
972
727
|
</h3><div class="docstring">
|
|
973
728
|
<div class="discussion">
|
|
974
|
-
<p>
|
|
975
|
-
|
|
729
|
+
<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>
|
|
730
|
+
<p>Returns <code>nil</code> when the input is invalid or currency cannot be determined.</p>
|
|
976
731
|
|
|
977
732
|
</div>
|
|
978
733
|
</div>
|
|
979
734
|
<div class="tags">
|
|
980
|
-
|
|
735
|
+
|
|
736
|
+
<div class="examples">
|
|
737
|
+
<h4 class="tag_title">Examples:</h4>
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
<h5 class="example_title"><div class='inline'><p>With explicit currency</p></div></h5>
|
|
741
|
+
|
|
742
|
+
<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'>'</span><span class='tstring_content'>19.99</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 19.99]
|
|
743
|
+
</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'>'</span><span class='tstring_content'>garbage</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> nil</span></code></pre>
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
<h5 class="example_title"><div class='inline'><p>With symbol or code in the string</p></div></h5>
|
|
747
|
+
|
|
748
|
+
<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'>'</span><span class='tstring_content'>$19.99</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 19.99]
|
|
749
|
+
</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'>'</span><span class='tstring_content'>USD 1,234.56</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 1234.56]</span></code></pre>
|
|
750
|
+
|
|
751
|
+
</div>
|
|
752
|
+
<p class="tag_title">Parameters:</p>
|
|
981
753
|
<ul class="param">
|
|
982
754
|
|
|
983
755
|
<li>
|
|
984
756
|
|
|
985
|
-
<span class='name'>
|
|
757
|
+
<span class='name'>input</span>
|
|
986
758
|
|
|
987
759
|
|
|
988
|
-
<span class='type'>(<tt>String</tt
|
|
760
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
989
761
|
|
|
990
762
|
|
|
991
763
|
|
|
992
764
|
—
|
|
993
|
-
<div class='inline'><p>a currency
|
|
765
|
+
<div class='inline'><p>Amount input, optionally including a currency symbol or code</p></div>
|
|
994
766
|
|
|
995
767
|
</li>
|
|
996
768
|
|
|
997
|
-
</ul>
|
|
998
|
-
|
|
999
|
-
<p class="tag_title">Returns:</p>
|
|
1000
|
-
<ul class="return">
|
|
1001
|
-
|
|
1002
769
|
<li>
|
|
1003
770
|
|
|
771
|
+
<span class='name'>currency</span>
|
|
1004
772
|
|
|
1005
|
-
|
|
773
|
+
|
|
774
|
+
<span class='type'>(<tt>String</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>
|
|
1006
775
|
|
|
1007
776
|
|
|
777
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
778
|
+
|
|
1008
779
|
|
|
1009
780
|
—
|
|
1010
|
-
<div class='inline'><p>
|
|
781
|
+
<div class='inline'><p>ISO code when not present in <code>input</code></p></div>
|
|
1011
782
|
|
|
1012
783
|
</li>
|
|
1013
784
|
|
|
1014
785
|
</ul>
|
|
1015
|
-
|
|
1016
|
-
<
|
|
786
|
+
|
|
787
|
+
<p class="tag_title">Returns:</p>
|
|
788
|
+
<ul class="return">
|
|
1017
789
|
|
|
1018
790
|
<li>
|
|
1019
791
|
|
|
1020
792
|
|
|
1021
|
-
<span class='type'>(<tt>
|
|
1022
|
-
|
|
793
|
+
<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>
|
|
1023
794
|
|
|
1024
795
|
|
|
1025
|
-
—
|
|
1026
|
-
<div class='inline'><p>if the currency can't be resolved</p></div>
|
|
1027
796
|
|
|
1028
797
|
</li>
|
|
1029
798
|
|
|
@@ -1035,27 +804,49 @@ for discounts, totals, or placeholders.</p>
|
|
|
1035
804
|
<pre class="lines">
|
|
1036
805
|
|
|
1037
806
|
|
|
1038
|
-
|
|
807
|
+
22
|
|
808
|
+
23
|
|
809
|
+
24
|
|
810
|
+
25
|
|
811
|
+
26
|
|
812
|
+
27
|
|
813
|
+
28
|
|
814
|
+
29
|
|
815
|
+
30
|
|
816
|
+
31
|
|
817
|
+
32
|
|
818
|
+
33
|
|
819
|
+
34
|
|
820
|
+
35
|
|
821
|
+
36</pre>
|
|
1039
822
|
</td>
|
|
1040
823
|
<td>
|
|
1041
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/
|
|
824
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/parser/parser.rb', line 22</span>
|
|
1042
825
|
|
|
1043
|
-
<span class='kw'>def</span> <span class='
|
|
826
|
+
<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>
|
|
827
|
+
<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'>String</span><span class='rparen'>)</span>
|
|
828
|
+
|
|
829
|
+
<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>
|
|
830
|
+
<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>
|
|
831
|
+
|
|
832
|
+
<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>
|
|
833
|
+
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_currency'>currency</span>
|
|
834
|
+
|
|
835
|
+
<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>
|
|
836
|
+
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_amount'>amount</span>
|
|
837
|
+
|
|
838
|
+
<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>
|
|
839
|
+
<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>
|
|
840
|
+
<span class='kw'>end</span></pre>
|
|
1044
841
|
</td>
|
|
1045
842
|
</tr>
|
|
1046
843
|
</table>
|
|
1047
844
|
</div>
|
|
1048
845
|
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
<div id="instance_method_details" class="method_details_list">
|
|
1052
|
-
<h2>Instance Method Details</h2>
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
<div class="method_details first">
|
|
1056
|
-
<h3 class="signature first" id="parse-instance_method">
|
|
846
|
+
<div class="method_details ">
|
|
847
|
+
<h3 class="signature " id="parse!-instance_method">
|
|
1057
848
|
|
|
1058
|
-
#<strong>parse
|
|
849
|
+
#<strong>parse!</strong>(input, currency = nil) ⇒ <tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>
|
|
1059
850
|
|
|
1060
851
|
|
|
1061
852
|
|
|
@@ -1063,7 +854,7 @@ for discounts, totals, or placeholders.</p>
|
|
|
1063
854
|
|
|
1064
855
|
</h3><div class="docstring">
|
|
1065
856
|
<div class="discussion">
|
|
1066
|
-
<p>
|
|
857
|
+
<p>Like <span class='object_link'><a href="#parse-instance_method" title="Mint#parse (method)">#parse</a></span> but raises on failure.</p>
|
|
1067
858
|
|
|
1068
859
|
</div>
|
|
1069
860
|
</div>
|
|
@@ -1073,17 +864,8 @@ for discounts, totals, or placeholders.</p>
|
|
|
1073
864
|
<h4 class="tag_title">Examples:</h4>
|
|
1074
865
|
|
|
1075
866
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
<pre class="example code"><code><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_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>19.99</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 19.99]
|
|
1079
|
-
</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_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1.234,56</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>EUR</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [EUR 1234.56]</span></code></pre>
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
<h5 class="example_title"><div class='inline'><p>With symbol or code in the string</p></div></h5>
|
|
1083
|
-
|
|
1084
|
-
<pre class="example code"><code><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_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>$19.99</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 19.99]
|
|
1085
|
-
</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_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>19,99 €</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [EUR 19.99]
|
|
1086
|
-
</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_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD 1,234.56</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 1234.56]</span></code></pre>
|
|
867
|
+
<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'>'</span><span class='tstring_content'>19.99</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 19.99]
|
|
868
|
+
</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'>'</span><span class='tstring_content'>garbage</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> ArgumentError</span></code></pre>
|
|
1087
869
|
|
|
1088
870
|
</div>
|
|
1089
871
|
<p class="tag_title">Parameters:</p>
|
|
@@ -1157,32 +939,38 @@ for discounts, totals, or placeholders.</p>
|
|
|
1157
939
|
<pre class="lines">
|
|
1158
940
|
|
|
1159
941
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
942
|
+
48
|
|
943
|
+
49
|
|
944
|
+
50
|
|
945
|
+
51
|
|
946
|
+
52
|
|
947
|
+
53
|
|
948
|
+
54
|
|
949
|
+
55
|
|
950
|
+
56
|
|
951
|
+
57
|
|
952
|
+
58
|
|
953
|
+
59
|
|
954
|
+
60
|
|
955
|
+
61
|
|
956
|
+
62</pre>
|
|
1172
957
|
</td>
|
|
1173
958
|
<td>
|
|
1174
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/parser/parser.rb', line
|
|
959
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/parser/parser.rb', line 48</span>
|
|
1175
960
|
|
|
1176
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_parse'>parse
|
|
961
|
+
<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>
|
|
1177
962
|
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>input must be a String</span><span class='tstring_end'>'</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'>String</span><span class='rparen'>)</span>
|
|
1178
963
|
|
|
1179
964
|
<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>
|
|
1180
965
|
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>input cannot be empty</span><span class='tstring_end'>'</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>
|
|
1181
966
|
|
|
1182
|
-
<span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='
|
|
1183
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</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
|
|
967
|
+
<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>
|
|
968
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</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'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_currency'>currency</span>
|
|
969
|
+
|
|
970
|
+
<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>
|
|
971
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</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'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_amount'>amount</span>
|
|
1184
972
|
|
|
1185
|
-
<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
|
|
973
|
+
<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>
|
|
1186
974
|
<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>
|
|
1187
975
|
<span class='kw'>end</span></pre>
|
|
1188
976
|
</td>
|
|
@@ -1195,7 +983,7 @@ for discounts, totals, or placeholders.</p>
|
|
|
1195
983
|
</div>
|
|
1196
984
|
|
|
1197
985
|
<div id="footer">
|
|
1198
|
-
Generated on
|
|
986
|
+
Generated on Tue Jun 16 20:22:19 2026 by
|
|
1199
987
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
1200
988
|
0.9.44 (ruby-4.0.5).
|
|
1201
989
|
</div>
|