minting 1.7.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +35 -3
- data/doc/Mint/Currency.html +826 -55
- data/doc/Mint/Money.html +715 -218
- data/doc/Mint/RangeStepPatch.html +1 -1
- data/doc/Mint/Registry.html +859 -0
- data/doc/Mint/Rounding.html +495 -0
- data/doc/Mint/UnknownCurrency.html +1 -1
- data/doc/Mint.html +307 -225
- data/doc/Minting.html +2 -2
- data/doc/_index.html +15 -8
- data/doc/agents/api_review-2026-06-15.md +329 -0
- data/doc/agents/copilot-instructions.md +0 -5
- data/doc/agents/expired/copilot-instructions.md +75 -0
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +25 -4
- data/doc/index.html +25 -4
- data/doc/method_list.html +177 -25
- data/doc/top-level-namespace.html +1 -1
- data/lib/minting/currency/currency.rb +71 -1
- data/lib/minting/mint/dsl/range.rb +1 -0
- data/lib/minting/mint/locale_backend.rb +29 -0
- data/lib/minting/mint/mint.rb +13 -38
- data/lib/minting/mint/parser/parser.rb +50 -19
- data/lib/minting/mint/parser/separators.rb +10 -8
- data/lib/minting/mint/registry/registration.rb +33 -0
- data/lib/minting/mint/registry/registry.rb +38 -0
- data/lib/minting/mint/registry/symbols.rb +49 -0
- data/lib/minting/mint/registry/zeros.rb +20 -0
- data/lib/minting/mint/rounding.rb +51 -0
- data/lib/minting/mint.rb +12 -23
- 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 +63 -20
- data/lib/minting/money/format/formatting.rb +16 -0
- data/lib/minting/money/format/to_s.rb +13 -4
- data/lib/minting/money/money.rb +12 -6
- data/lib/minting/version.rb +1 -1
- metadata +15 -7
- data/lib/minting/currency/currency_registry.rb +0 -67
- data/lib/minting/currency/world_currencies.rb +0 -16
- /data/doc/agents/{AGENTS.md → expired/AGENTS.md} +0 -0
- /data/doc/agents/{gemini_gem_evaluation.md → expired/gemini_gem_evaluation.md} +0 -0
- /data/doc/agents/{recommendations.md → expired/recommendations.md} +0 -0
- /data/doc/agents/{rubocop-issues.md → expired/rubocop-issues.md} +0 -0
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/parser/separators.rb,<br> lib/minting/
|
|
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>
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
|
|
101
101
|
<h2>Overview</h2><div class="docstring">
|
|
102
102
|
<div class="discussion">
|
|
103
|
-
<p>Mint
|
|
103
|
+
<p>Mint registry: manages all cached state</p>
|
|
104
104
|
|
|
105
105
|
</div>
|
|
106
106
|
</div>
|
|
@@ -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/
|
|
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
|
|
|
@@ -123,21 +123,13 @@
|
|
|
123
123
|
|
|
124
124
|
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
<h2>
|
|
131
|
-
Class Method Summary
|
|
132
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
133
|
-
</h2>
|
|
134
|
-
|
|
135
|
-
<ul class="summary">
|
|
136
|
-
|
|
137
|
-
<li class="public ">
|
|
126
|
+
<h2>Class Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
|
|
127
|
+
<ul class="summary">
|
|
128
|
+
|
|
129
|
+
<li class="public ">
|
|
138
130
|
<span class="summary_signature">
|
|
139
131
|
|
|
140
|
-
<a href="#
|
|
132
|
+
<a href="#locale_backend-class_method" title="locale_backend (class method)">.<strong>locale_backend</strong> ⇒ Proc, ... </a>
|
|
141
133
|
|
|
142
134
|
|
|
143
135
|
|
|
@@ -145,16 +137,32 @@
|
|
|
145
137
|
|
|
146
138
|
|
|
147
139
|
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
148
143
|
|
|
149
144
|
|
|
150
145
|
|
|
151
146
|
|
|
152
147
|
|
|
153
148
|
|
|
154
|
-
<span class="summary_desc"><div class='inline'><p>
|
|
149
|
+
<span class="summary_desc"><div class='inline'><p>Optional callable that returns a Hash with locale-aware formatting defaults.</p></div></span>
|
|
155
150
|
|
|
156
151
|
</li>
|
|
157
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">
|
|
158
166
|
|
|
159
167
|
<li class="public ">
|
|
160
168
|
<span class="summary_signature">
|
|
@@ -181,7 +189,7 @@
|
|
|
181
189
|
<li class="public ">
|
|
182
190
|
<span class="summary_signature">
|
|
183
191
|
|
|
184
|
-
<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>
|
|
185
193
|
|
|
186
194
|
|
|
187
195
|
|
|
@@ -195,7 +203,7 @@
|
|
|
195
203
|
|
|
196
204
|
|
|
197
205
|
|
|
198
|
-
<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>
|
|
199
207
|
|
|
200
208
|
</li>
|
|
201
209
|
|
|
@@ -203,7 +211,7 @@
|
|
|
203
211
|
<li class="public ">
|
|
204
212
|
<span class="summary_signature">
|
|
205
213
|
|
|
206
|
-
<a href="#
|
|
214
|
+
<a href="#with_rounding-class_method" title="with_rounding (class method)">.<strong>with_rounding</strong>(mode) { ... } ⇒ Object </a>
|
|
207
215
|
|
|
208
216
|
|
|
209
217
|
|
|
@@ -217,7 +225,7 @@
|
|
|
217
225
|
|
|
218
226
|
|
|
219
227
|
|
|
220
|
-
<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>
|
|
221
229
|
|
|
222
230
|
</li>
|
|
223
231
|
|
|
@@ -239,7 +247,7 @@
|
|
|
239
247
|
<span class="private note title">private</span>
|
|
240
248
|
|
|
241
249
|
|
|
242
|
-
<span class="summary_desc"><div class='inline'><p>
|
|
250
|
+
<span class="summary_desc"><div class='inline'><p>The frozen world-currencies hash.</p></div></span>
|
|
243
251
|
|
|
244
252
|
</li>
|
|
245
253
|
|
|
@@ -257,7 +265,7 @@
|
|
|
257
265
|
<li class="public ">
|
|
258
266
|
<span class="summary_signature">
|
|
259
267
|
|
|
260
|
-
<a href="#parse-instance_method" title="#parse (instance method)">#<strong>parse</strong>(input, currency = nil) ⇒ Money </a>
|
|
268
|
+
<a href="#parse-instance_method" title="#parse (instance method)">#<strong>parse</strong>(input, currency = nil) ⇒ Money<sup>?</sup> </a>
|
|
261
269
|
|
|
262
270
|
|
|
263
271
|
|
|
@@ -276,20 +284,42 @@
|
|
|
276
284
|
</li>
|
|
277
285
|
|
|
278
286
|
|
|
279
|
-
|
|
287
|
+
<li class="public ">
|
|
288
|
+
<span class="summary_signature">
|
|
289
|
+
|
|
290
|
+
<a href="#parse!-instance_method" title="#parse! (instance method)">#<strong>parse!</strong>(input, currency = nil) ⇒ Money </a>
|
|
280
291
|
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
</span>
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
281
301
|
|
|
282
302
|
|
|
303
|
+
|
|
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>
|
|
305
|
+
|
|
306
|
+
</li>
|
|
283
307
|
|
|
308
|
+
|
|
309
|
+
</ul>
|
|
310
|
+
|
|
311
|
+
|
|
284
312
|
|
|
285
|
-
<div id="class_method_details" class="method_details_list">
|
|
286
|
-
<h2>Class Method Details</h2>
|
|
287
313
|
|
|
314
|
+
<div id="class_attr_details" class="attr_details">
|
|
315
|
+
<h2>Class Attribute Details</h2>
|
|
288
316
|
|
|
317
|
+
|
|
318
|
+
<span id="locale_backend=-class_method"></span>
|
|
289
319
|
<div class="method_details first">
|
|
290
|
-
<h3 class="signature first" id="
|
|
320
|
+
<h3 class="signature first" id="locale_backend-class_method">
|
|
291
321
|
|
|
292
|
-
.<strong>
|
|
322
|
+
.<strong>locale_backend</strong> ⇒ <tt>Proc</tt>, ...
|
|
293
323
|
|
|
294
324
|
|
|
295
325
|
|
|
@@ -297,30 +327,35 @@
|
|
|
297
327
|
|
|
298
328
|
</h3><div class="docstring">
|
|
299
329
|
<div class="discussion">
|
|
300
|
-
<p>
|
|
301
|
-
|
|
330
|
+
<p>Optional callable that returns a Hash with locale-aware formatting defaults.</p>
|
|
331
|
+
<p>The callable receives no arguments and returns a Hash with these keys:</p>
|
|
332
|
+
<pre class="code ruby"><code class="ruby">[+:decimal+] Decimal separator (e.g. +","+)
|
|
333
|
+
[+:thousand+] Thousands delimiter (e.g. +"."+)
|
|
334
|
+
[+:format+] Format template string (e.g. +"%<amount>f %<symbol>s"+)
|
|
335
|
+
</code></pre>
|
|
336
|
+
<p>When set, <code>#to_s</code> and <code>#format</code> use these values as fallbacks when the
|
|
337
|
+
corresponding parameter is not explicitly provided.</p>
|
|
302
338
|
|
|
303
339
|
</div>
|
|
304
340
|
</div>
|
|
305
341
|
<div class="tags">
|
|
306
|
-
<p class="tag_title">Parameters:</p>
|
|
307
|
-
<ul class="param">
|
|
308
342
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
<span class='type'>(<tt>String</tt>, <tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>)</span>
|
|
315
|
-
|
|
316
|
-
|
|
343
|
+
<div class="examples">
|
|
344
|
+
<h4 class="tag_title">Examples:</h4>
|
|
345
|
+
|
|
317
346
|
|
|
318
|
-
|
|
319
|
-
<div class='inline'><p>the currency identifier or object</p></div>
|
|
347
|
+
<h5 class="example_title"><div class='inline'><p>Rails I18n integration (in minting-rails railtie)</p></div></h5>
|
|
320
348
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
</
|
|
349
|
+
<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'>-></span> <span class='tlambeg'>{</span>
|
|
350
|
+
<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'>'</span><span class='tstring_content'>number.currency.format</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
351
|
+
<span class='lbrace'>{</span>
|
|
352
|
+
<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>
|
|
353
|
+
<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>
|
|
354
|
+
<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'>'</span><span class='tstring_content'>%n %u</span><span class='tstring_end'>'</span></span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<amount>f %<symbol>s</span><span class='tstring_end'>'</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<symbol>s%<amount>f</span><span class='tstring_end'>'</span></span>
|
|
355
|
+
<span class='rbrace'>}</span>
|
|
356
|
+
<span class='rbrace'>}</span></code></pre>
|
|
357
|
+
|
|
358
|
+
</div>
|
|
324
359
|
|
|
325
360
|
<p class="tag_title">Returns:</p>
|
|
326
361
|
<ul class="return">
|
|
@@ -328,12 +363,9 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
328
363
|
<li>
|
|
329
364
|
|
|
330
365
|
|
|
331
|
-
<span class='type'>(<tt
|
|
332
|
-
|
|
366
|
+
<span class='type'>(<tt>Proc</tt>, <tt>#call</tt>, <tt>nil</tt>)</span>
|
|
333
367
|
|
|
334
368
|
|
|
335
|
-
—
|
|
336
|
-
<div class='inline'><p>the registered Currency instance or nil if not found</p></div>
|
|
337
369
|
|
|
338
370
|
</li>
|
|
339
371
|
|
|
@@ -345,33 +377,30 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
345
377
|
<pre class="lines">
|
|
346
378
|
|
|
347
379
|
|
|
348
|
-
22
|
|
349
|
-
23
|
|
350
|
-
24
|
|
351
|
-
25
|
|
352
|
-
26
|
|
353
380
|
27
|
|
354
381
|
28
|
|
355
382
|
29</pre>
|
|
356
383
|
</td>
|
|
357
384
|
<td>
|
|
358
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/
|
|
359
|
-
|
|
360
|
-
<span class='kw'>def</span> <span class='
|
|
361
|
-
<span class='
|
|
362
|
-
<span class='kw'>when</span> <span class='const'>NilClass</span> <span class='kw'>then</span> <span class='kw'>nil</span>
|
|
363
|
-
<span class='kw'>when</span> <span class='const'><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></span> <span class='kw'>then</span> <span class='id identifier rubyid_currency'>currency</span>
|
|
364
|
-
<span class='kw'>when</span> <span class='const'>String</span> <span class='kw'>then</span> <span class='const'><span class='object_link'><a href="Mint/CurrencyRegistry.html" title="Mint::CurrencyRegistry (module)">CurrencyRegistry</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currencies'><span class='object_link'><a href="Mint/CurrencyRegistry.html#currencies-instance_method" title="Mint::CurrencyRegistry#currencies (method)">currencies</a></span></span><span class='lbracket'>[</span><span class='id identifier rubyid_currency'>currency</span><span class='rbracket'>]</span>
|
|
365
|
-
<span class='kw'>else</span> <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 must be [Currency], [String] or nil (</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_currency'>currency</span><span class='embexpr_end'>}</span><span class='tstring_content'>)</span><span class='tstring_end'>"</span></span>
|
|
366
|
-
<span class='kw'>end</span>
|
|
385
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/locale_backend.rb', line 27</span>
|
|
386
|
+
|
|
387
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_locale_backend'>locale_backend</span>
|
|
388
|
+
<span class='ivar'>@locale_backend</span>
|
|
367
389
|
<span class='kw'>end</span></pre>
|
|
368
390
|
</td>
|
|
369
391
|
</tr>
|
|
370
392
|
</table>
|
|
371
393
|
</div>
|
|
372
394
|
|
|
373
|
-
|
|
374
|
-
|
|
395
|
+
</div>
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
<div id="class_method_details" class="method_details_list">
|
|
399
|
+
<h2>Class Method Details</h2>
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
<div class="method_details first">
|
|
403
|
+
<h3 class="signature first" id="money-class_method">
|
|
375
404
|
|
|
376
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>
|
|
377
406
|
|
|
@@ -463,16 +492,16 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
463
492
|
<td>
|
|
464
493
|
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 15</span>
|
|
465
494
|
|
|
466
|
-
<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
|
|
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>
|
|
467
496
|
</td>
|
|
468
497
|
</tr>
|
|
469
498
|
</table>
|
|
470
499
|
</div>
|
|
471
500
|
|
|
472
501
|
<div class="method_details ">
|
|
473
|
-
<h3 class="signature " id="
|
|
502
|
+
<h3 class="signature " id="use_top_level_constants!-class_method">
|
|
474
503
|
|
|
475
|
-
.<strong>
|
|
504
|
+
.<strong>use_top_level_constants!</strong> ⇒ <tt>Object</tt>
|
|
476
505
|
|
|
477
506
|
|
|
478
507
|
|
|
@@ -480,90 +509,113 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
480
509
|
|
|
481
510
|
</h3><div class="docstring">
|
|
482
511
|
<div class="discussion">
|
|
483
|
-
<p>Registers
|
|
512
|
+
<p>Registers top-level ::Money and ::Currency constants as aliases for Mint's classes.</p>
|
|
484
513
|
|
|
485
514
|
</div>
|
|
486
515
|
</div>
|
|
487
516
|
<div class="tags">
|
|
488
|
-
<p class="tag_title">Parameters:</p>
|
|
489
|
-
<ul class="param">
|
|
490
517
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
<span class='name'>code</span>
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
<span class='type'>(<tt>String</tt>)</span>
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
—
|
|
501
|
-
<div class='inline'><p>the unique currency code</p></div>
|
|
502
|
-
|
|
503
|
-
</li>
|
|
518
|
+
<p class="tag_title">Raises:</p>
|
|
519
|
+
<ul class="raise">
|
|
504
520
|
|
|
505
521
|
<li>
|
|
506
522
|
|
|
507
|
-
<span class='name'>subunit</span>
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
<span class='type'>(<tt>Integer</tt>)</span>
|
|
511
523
|
|
|
524
|
+
<span class='type'>(<tt>NameError</tt>)</span>
|
|
512
525
|
|
|
513
|
-
<em class="default">(defaults to: <tt>0</tt>)</em>
|
|
514
526
|
|
|
515
527
|
|
|
516
528
|
—
|
|
517
|
-
<div class='inline'><p>
|
|
529
|
+
<div class='inline'><p>if ::Money or ::Currency are already defined and differ</p></div>
|
|
518
530
|
|
|
519
531
|
</li>
|
|
520
532
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
533
|
+
</ul>
|
|
534
|
+
|
|
535
|
+
</div><table class="source_code">
|
|
536
|
+
<tr>
|
|
537
|
+
<td>
|
|
538
|
+
<pre class="lines">
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
8
|
|
542
|
+
9
|
|
543
|
+
10
|
|
544
|
+
11
|
|
545
|
+
12
|
|
546
|
+
13
|
|
547
|
+
14
|
|
548
|
+
15
|
|
549
|
+
16</pre>
|
|
550
|
+
</td>
|
|
551
|
+
<td>
|
|
552
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/dsl/top_level.rb', line 8</span>
|
|
553
|
+
|
|
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>
|
|
563
|
+
</td>
|
|
564
|
+
</tr>
|
|
565
|
+
</table>
|
|
566
|
+
</div>
|
|
567
|
+
|
|
568
|
+
<div class="method_details ">
|
|
569
|
+
<h3 class="signature " id="with_rounding-class_method">
|
|
570
|
+
|
|
571
|
+
.<strong>with_rounding</strong>(mode) { ... } ⇒ <tt>Object</tt>
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
</h3><div class="docstring">
|
|
578
|
+
<div class="discussion">
|
|
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>
|
|
583
|
+
|
|
584
|
+
</div>
|
|
585
|
+
</div>
|
|
586
|
+
<div class="tags">
|
|
587
|
+
<p class="tag_title">Parameters:</p>
|
|
588
|
+
<ul class="param">
|
|
536
589
|
|
|
537
590
|
<li>
|
|
538
591
|
|
|
539
|
-
<span class='name'>
|
|
540
|
-
|
|
592
|
+
<span class='name'>mode</span>
|
|
541
593
|
|
|
542
|
-
<span class='type'>(<tt>Integer</tt>)</span>
|
|
543
594
|
|
|
595
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
|
544
596
|
|
|
545
|
-
<em class="default">(defaults to: <tt>0</tt>)</em>
|
|
546
597
|
|
|
547
598
|
|
|
548
599
|
—
|
|
549
|
-
<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>
|
|
550
602
|
|
|
551
603
|
</li>
|
|
552
604
|
|
|
553
605
|
</ul>
|
|
554
606
|
|
|
555
|
-
<p class="tag_title">
|
|
556
|
-
<ul class="
|
|
607
|
+
<p class="tag_title">Yields:</p>
|
|
608
|
+
<ul class="yield">
|
|
557
609
|
|
|
558
610
|
<li>
|
|
559
611
|
|
|
560
612
|
|
|
561
|
-
<span class='type'
|
|
613
|
+
<span class='type'></span>
|
|
562
614
|
|
|
563
615
|
|
|
564
616
|
|
|
565
|
-
|
|
566
|
-
<div class='inline'><p>the
|
|
617
|
+
|
|
618
|
+
<div class='inline'><p>block to execute with the rounding mode active</p></div>
|
|
567
619
|
|
|
568
620
|
</li>
|
|
569
621
|
|
|
@@ -579,19 +631,7 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
579
631
|
|
|
580
632
|
|
|
581
633
|
—
|
|
582
|
-
<div class='inline'><p>if
|
|
583
|
-
|
|
584
|
-
</li>
|
|
585
|
-
|
|
586
|
-
<li>
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
<span class='type'>(<tt>KeyError</tt>)</span>
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
—
|
|
594
|
-
<div class='inline'><p>if the currency code is already registered</p></div>
|
|
634
|
+
<div class='inline'><p>if <code>mode</code> is not a recognised rounding mode</p></div>
|
|
595
635
|
|
|
596
636
|
</li>
|
|
597
637
|
|
|
@@ -603,25 +643,21 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
603
643
|
<pre class="lines">
|
|
604
644
|
|
|
605
645
|
|
|
606
|
-
|
|
607
|
-
41
|
|
608
|
-
42</pre>
|
|
646
|
+
31</pre>
|
|
609
647
|
</td>
|
|
610
648
|
<td>
|
|
611
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line
|
|
649
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 31</span>
|
|
612
650
|
|
|
613
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
|
614
|
-
<span class='const'><span class='object_link'><a href="Mint/CurrencyRegistry.html" title="Mint::CurrencyRegistry (module)">CurrencyRegistry</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register'><span class='object_link'><a href="Mint/CurrencyRegistry.html#register-instance_method" title="Mint::CurrencyRegistry#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>
|
|
615
|
-
<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>
|
|
616
652
|
</td>
|
|
617
653
|
</tr>
|
|
618
654
|
</table>
|
|
619
655
|
</div>
|
|
620
656
|
|
|
621
657
|
<div class="method_details ">
|
|
622
|
-
<h3 class="signature " id="
|
|
658
|
+
<h3 class="signature " id="world_currencies-class_method">
|
|
623
659
|
|
|
624
|
-
.<strong>
|
|
660
|
+
.<strong>world_currencies</strong> ⇒ <tt>Hash{String => <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>}</tt>
|
|
625
661
|
|
|
626
662
|
|
|
627
663
|
|
|
@@ -629,24 +665,28 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
629
665
|
|
|
630
666
|
</h3><div class="docstring">
|
|
631
667
|
<div class="discussion">
|
|
632
|
-
<p
|
|
668
|
+
<p class="note private">
|
|
669
|
+
<strong>This method is part of a private API.</strong>
|
|
670
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
671
|
+
</p>
|
|
672
|
+
<p>Returns the frozen world-currencies hash.</p>
|
|
633
673
|
|
|
634
674
|
</div>
|
|
635
675
|
</div>
|
|
636
676
|
<div class="tags">
|
|
637
677
|
|
|
638
|
-
<p class="tag_title">
|
|
639
|
-
<ul class="
|
|
678
|
+
<p class="tag_title">Returns:</p>
|
|
679
|
+
<ul class="return">
|
|
640
680
|
|
|
641
681
|
<li>
|
|
642
682
|
|
|
643
683
|
|
|
644
|
-
<span class='type'>(<tt>
|
|
684
|
+
<span class='type'>(<tt>Hash{String => <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>}</tt>)</span>
|
|
645
685
|
|
|
646
686
|
|
|
647
687
|
|
|
648
688
|
—
|
|
649
|
-
<div class='inline'><p>
|
|
689
|
+
<div class='inline'><p>the frozen world-currencies hash</p></div>
|
|
650
690
|
|
|
651
691
|
</li>
|
|
652
692
|
|
|
@@ -658,37 +698,27 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
658
698
|
<pre class="lines">
|
|
659
699
|
|
|
660
700
|
|
|
661
|
-
|
|
662
|
-
9
|
|
663
|
-
10
|
|
664
|
-
11
|
|
665
|
-
12
|
|
666
|
-
13
|
|
667
|
-
14
|
|
668
|
-
15
|
|
669
|
-
16</pre>
|
|
701
|
+
19</pre>
|
|
670
702
|
</td>
|
|
671
703
|
<td>
|
|
672
|
-
<pre class="code"><span class="info file"># File 'lib/minting/mint/
|
|
704
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 19</span>
|
|
673
705
|
|
|
674
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
|
675
|
-
<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>
|
|
676
|
-
<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>
|
|
677
|
-
<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>
|
|
678
|
-
<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>
|
|
679
|
-
<span class='kw'>else</span>
|
|
680
|
-
<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>
|
|
681
|
-
<span class='kw'>end</span>
|
|
682
|
-
<span class='kw'>end</span></pre>
|
|
706
|
+
<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>
|
|
683
707
|
</td>
|
|
684
708
|
</tr>
|
|
685
709
|
</table>
|
|
686
710
|
</div>
|
|
687
711
|
|
|
688
|
-
|
|
689
|
-
|
|
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">
|
|
690
720
|
|
|
691
|
-
|
|
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>
|
|
692
722
|
|
|
693
723
|
|
|
694
724
|
|
|
@@ -696,28 +726,73 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
696
726
|
|
|
697
727
|
</h3><div class="docstring">
|
|
698
728
|
<div class="discussion">
|
|
699
|
-
<p class="
|
|
700
|
-
|
|
701
|
-
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
702
|
-
</p>
|
|
703
|
-
<p>Loads ISO world currencies from YAML file into the registry.</p>
|
|
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>
|
|
704
731
|
|
|
705
732
|
</div>
|
|
706
733
|
</div>
|
|
707
734
|
<div class="tags">
|
|
708
735
|
|
|
709
|
-
<
|
|
710
|
-
<
|
|
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>
|
|
753
|
+
<ul class="param">
|
|
711
754
|
|
|
712
755
|
<li>
|
|
713
756
|
|
|
757
|
+
<span class='name'>input</span>
|
|
714
758
|
|
|
715
|
-
<span class='type'>(<tt>Hash{String => <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>}</tt>)</span>
|
|
716
759
|
|
|
760
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
—
|
|
765
|
+
<div class='inline'><p>Amount input, optionally including a currency symbol or code</p></div>
|
|
766
|
+
|
|
767
|
+
</li>
|
|
768
|
+
|
|
769
|
+
<li>
|
|
770
|
+
|
|
771
|
+
<span class='name'>currency</span>
|
|
772
|
+
|
|
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>
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
717
778
|
|
|
718
779
|
|
|
719
780
|
—
|
|
720
|
-
<div class='inline'><p>ISO
|
|
781
|
+
<div class='inline'><p>ISO code when not present in <code>input</code></p></div>
|
|
782
|
+
|
|
783
|
+
</li>
|
|
784
|
+
|
|
785
|
+
</ul>
|
|
786
|
+
|
|
787
|
+
<p class="tag_title">Returns:</p>
|
|
788
|
+
<ul class="return">
|
|
789
|
+
|
|
790
|
+
<li>
|
|
791
|
+
|
|
792
|
+
|
|
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>
|
|
794
|
+
|
|
795
|
+
|
|
721
796
|
|
|
722
797
|
</li>
|
|
723
798
|
|
|
@@ -729,39 +804,49 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
729
804
|
<pre class="lines">
|
|
730
805
|
|
|
731
806
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
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>
|
|
739
822
|
</td>
|
|
740
823
|
<td>
|
|
741
|
-
<pre class="code"><span class="info file"># File 'lib/minting/
|
|
824
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/parser/parser.rb', line 22</span>
|
|
825
|
+
|
|
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>
|
|
742
831
|
|
|
743
|
-
<span class='
|
|
744
|
-
<span class='
|
|
745
|
-
<span class='id identifier rubyid_path'>path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_expand_path'>expand_path</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>../data</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid___dir__'>__dir__</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>world-currencies.yaml</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
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>
|
|
746
834
|
|
|
747
|
-
|
|
748
|
-
<span class='kw'>
|
|
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>
|
|
749
840
|
<span class='kw'>end</span></pre>
|
|
750
841
|
</td>
|
|
751
842
|
</tr>
|
|
752
843
|
</table>
|
|
753
844
|
</div>
|
|
754
845
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
<div id="instance_method_details" class="method_details_list">
|
|
758
|
-
<h2>Instance Method Details</h2>
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
<div class="method_details first">
|
|
762
|
-
<h3 class="signature first" id="parse-instance_method">
|
|
846
|
+
<div class="method_details ">
|
|
847
|
+
<h3 class="signature " id="parse!-instance_method">
|
|
763
848
|
|
|
764
|
-
#<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>
|
|
765
850
|
|
|
766
851
|
|
|
767
852
|
|
|
@@ -769,7 +854,7 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
769
854
|
|
|
770
855
|
</h3><div class="docstring">
|
|
771
856
|
<div class="discussion">
|
|
772
|
-
<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>
|
|
773
858
|
|
|
774
859
|
</div>
|
|
775
860
|
</div>
|
|
@@ -779,17 +864,8 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
779
864
|
<h4 class="tag_title">Examples:</h4>
|
|
780
865
|
|
|
781
866
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
<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]
|
|
785
|
-
</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>
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
<h5 class="example_title"><div class='inline'><p>With symbol or code in the string</p></div></h5>
|
|
789
|
-
|
|
790
|
-
<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]
|
|
791
|
-
</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]
|
|
792
|
-
</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>
|
|
793
869
|
|
|
794
870
|
</div>
|
|
795
871
|
<p class="tag_title">Parameters:</p>
|
|
@@ -863,32 +939,38 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
863
939
|
<pre class="lines">
|
|
864
940
|
|
|
865
941
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
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>
|
|
878
957
|
</td>
|
|
879
958
|
<td>
|
|
880
|
-
<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>
|
|
881
960
|
|
|
882
|
-
<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>
|
|
883
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>
|
|
884
963
|
|
|
885
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>
|
|
886
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>
|
|
887
966
|
|
|
888
|
-
<span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='
|
|
889
|
-
<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>
|
|
890
972
|
|
|
891
|
-
<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>
|
|
892
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>
|
|
893
975
|
<span class='kw'>end</span></pre>
|
|
894
976
|
</td>
|
|
@@ -901,7 +983,7 @@ or retrieves it directly if already a Currency object.</p>
|
|
|
901
983
|
</div>
|
|
902
984
|
|
|
903
985
|
<div id="footer">
|
|
904
|
-
Generated on
|
|
986
|
+
Generated on Tue Jun 16 20:22:19 2026 by
|
|
905
987
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
906
988
|
0.9.44 (ruby-4.0.5).
|
|
907
989
|
</div>
|