minting 1.6.3 → 1.7.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 +7 -2
- data/Rakefile +13 -3
- data/doc/Mint/Currency.html +993 -0
- data/doc/Mint/CurrencyRegistry.html +511 -0
- data/doc/Mint/Money.html +3856 -0
- data/doc/Mint/UnknownCurrency.html +136 -0
- data/doc/Mint.html +886 -0
- data/doc/Minting.html +142 -0
- data/doc/_index.html +158 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +206 -0
- data/doc/css/style.css +1089 -0
- data/doc/file.README.html +278 -0
- data/doc/file_list.html +59 -0
- data/doc/frames.html +22 -0
- data/doc/index.html +278 -0
- data/doc/js/app.js +801 -0
- data/doc/js/full_list.js +334 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +510 -0
- data/doc/top-level-namespace.html +143 -0
- data/lib/minting/mint/currency/currency_registry.rb +1 -1
- data/lib/minting/mint/dsl/range.rb +54 -0
- data/lib/minting/mint/{dsl.rb → dsl/refinements.rb} +0 -10
- data/lib/minting/mint/dsl/top_level.rb +14 -0
- data/lib/minting/mint/mint.rb +2 -2
- data/lib/minting/mint/parser.rb +16 -9
- data/lib/minting/mint.rb +3 -1
- data/lib/minting/money/allocation.rb +14 -14
- data/lib/minting/money/arithmetics.rb +5 -5
- data/lib/minting/money/coercion.rb +8 -11
- data/lib/minting/money/formatting.rb +23 -28
- data/lib/minting/version.rb +1 -1
- data/minting.gemspec +5 -2
- metadata +31 -5
data/doc/Mint.html
ADDED
|
@@ -0,0 +1,886 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
Module: Mint
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.9.44
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css">
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css">
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "Mint";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div id="main_progress" aria-hidden="true"></div>
|
|
31
|
+
|
|
32
|
+
<div class="nav_wrap">
|
|
33
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
|
34
|
+
<div id="resizer"></div>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div id="main" tabindex="-1">
|
|
38
|
+
<div id="header">
|
|
39
|
+
<div id="menu">
|
|
40
|
+
|
|
41
|
+
<a href="_index.html">Index (M)</a> »
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
<span class="title">Mint</span>
|
|
45
|
+
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<div id="search">
|
|
49
|
+
|
|
50
|
+
<a class="full_list_link" id="class_list_link"
|
|
51
|
+
href="class_list.html">
|
|
52
|
+
|
|
53
|
+
<svg width="24" height="24">
|
|
54
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
55
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
56
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
57
|
+
</svg>
|
|
58
|
+
</a>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
<div class="clear"></div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div id="content"><h1>Module: Mint
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
</h1>
|
|
69
|
+
<div class="box_info">
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
<dl>
|
|
75
|
+
<dt>Extended by:</dt>
|
|
76
|
+
<dd><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></dd>
|
|
77
|
+
</dl>
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
<dl>
|
|
85
|
+
<dt>Included in:</dt>
|
|
86
|
+
<dd><span class='object_link'><a href="" title="Mint (module)">Mint</a></span></dd>
|
|
87
|
+
</dl>
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
<dl>
|
|
92
|
+
<dt>Defined in:</dt>
|
|
93
|
+
<dd>lib/minting/mint/dsl.rb<span class="defines">,<br>
|
|
94
|
+
lib/minting/mint/mint.rb,<br> lib/minting/mint/parser.rb,<br> lib/minting/money/money.rb,<br> lib/minting/money/coercion.rb,<br> lib/minting/money/allocation.rb,<br> lib/minting/money/comparable.rb,<br> lib/minting/money/conversion.rb,<br> lib/minting/money/formatting.rb,<br> lib/minting/money/arithmetics.rb,<br> lib/minting/money/constructors.rb,<br> lib/minting/mint/currency/currency.rb,<br> lib/minting/mint/currency/world_currencies.rb,<br> lib/minting/mint/currency/currency_registry.rb</span>
|
|
95
|
+
|
|
96
|
+
</dd>
|
|
97
|
+
</dl>
|
|
98
|
+
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
<h2>Overview</h2><div class="docstring">
|
|
102
|
+
<div class="discussion">
|
|
103
|
+
<p>Mint currency store (internal)</p>
|
|
104
|
+
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
<div class="tags">
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
</div><h2>Defined Under Namespace</h2>
|
|
111
|
+
<p class="children">
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Mint/CurrencyRegistry.html" title="Mint::CurrencyRegistry (module)">CurrencyRegistry</a></span>
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>, <span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span>, <span class='object_link'><a href="Mint/UnknownCurrency.html" title="Mint::UnknownCurrency (class)">UnknownCurrency</a></span>
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
</p>
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
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 ">
|
|
138
|
+
<span class="summary_signature">
|
|
139
|
+
|
|
140
|
+
<a href="#currency-class_method" title="currency (class method)">.<strong>currency</strong>(currency) ⇒ Currency<sup>?</sup> </a>
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
</span>
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
<span class="summary_desc"><div class='inline'><p>Finds a registered currency by its code, symbol, or retrieves it directly if already a Currency object.</p></div></span>
|
|
155
|
+
|
|
156
|
+
</li>
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
<li class="public ">
|
|
160
|
+
<span class="summary_signature">
|
|
161
|
+
|
|
162
|
+
<a href="#money-class_method" title="money (class method)">.<strong>money</strong>(amount, currency_code) ⇒ Money </a>
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
</span>
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
<span class="summary_desc"><div class='inline'><p>Creates a new <span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span> instance with the given amount and currency code.</p></div></span>
|
|
177
|
+
|
|
178
|
+
</li>
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
<li class="public ">
|
|
182
|
+
<span class="summary_signature">
|
|
183
|
+
|
|
184
|
+
<a href="#register_currency-class_method" title="register_currency (class method)">.<strong>register_currency</strong>(code:, subunit: 0, symbol: '', priority: 0) ⇒ Currency </a>
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
</span>
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
<span class="summary_desc"><div class='inline'><p>Registers a new currency, raising a KeyError if already registered.</p></div></span>
|
|
199
|
+
|
|
200
|
+
</li>
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
<li class="public ">
|
|
204
|
+
<span class="summary_signature">
|
|
205
|
+
|
|
206
|
+
<a href="#use_top_level_constants!-class_method" title="use_top_level_constants! (class method)">.<strong>use_top_level_constants!</strong> ⇒ Object </a>
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
</span>
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
|
221
|
+
|
|
222
|
+
</li>
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
<li class="public ">
|
|
226
|
+
<span class="summary_signature">
|
|
227
|
+
|
|
228
|
+
<a href="#world_currencies-class_method" title="world_currencies (class method)">.<strong>world_currencies</strong> ⇒ Hash{String => Currency} </a>
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
</span>
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
<span class="private note title">private</span>
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
<span class="summary_desc"><div class='inline'><p>Loads ISO world currencies from YAML file into the registry.</p></div></span>
|
|
243
|
+
|
|
244
|
+
</li>
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
</ul>
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
<h2>
|
|
251
|
+
Instance Method Summary
|
|
252
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
253
|
+
</h2>
|
|
254
|
+
|
|
255
|
+
<ul class="summary">
|
|
256
|
+
|
|
257
|
+
<li class="public ">
|
|
258
|
+
<span class="summary_signature">
|
|
259
|
+
|
|
260
|
+
<a href="#parse-instance_method" title="#parse (instance method)">#<strong>parse</strong>(input, currency = nil) ⇒ Money </a>
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
</span>
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
<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>
|
|
275
|
+
|
|
276
|
+
</li>
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
</ul>
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
<div id="class_method_details" class="method_details_list">
|
|
286
|
+
<h2>Class Method Details</h2>
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
<div class="method_details first">
|
|
290
|
+
<h3 class="signature first" id="currency-class_method">
|
|
291
|
+
|
|
292
|
+
.<strong>currency</strong>(currency) ⇒ <tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt><sup>?</sup>
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
</h3><div class="docstring">
|
|
299
|
+
<div class="discussion">
|
|
300
|
+
<p>Finds a registered currency by its code, symbol,
|
|
301
|
+
or retrieves it directly if already a Currency object.</p>
|
|
302
|
+
|
|
303
|
+
</div>
|
|
304
|
+
</div>
|
|
305
|
+
<div class="tags">
|
|
306
|
+
<p class="tag_title">Parameters:</p>
|
|
307
|
+
<ul class="param">
|
|
308
|
+
|
|
309
|
+
<li>
|
|
310
|
+
|
|
311
|
+
<span class='name'>currency</span>
|
|
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
|
+
|
|
317
|
+
|
|
318
|
+
—
|
|
319
|
+
<div class='inline'><p>the currency identifier or object</p></div>
|
|
320
|
+
|
|
321
|
+
</li>
|
|
322
|
+
|
|
323
|
+
</ul>
|
|
324
|
+
|
|
325
|
+
<p class="tag_title">Returns:</p>
|
|
326
|
+
<ul class="return">
|
|
327
|
+
|
|
328
|
+
<li>
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>nil</tt>)</span>
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
—
|
|
336
|
+
<div class='inline'><p>the registered Currency instance or nil if not found</p></div>
|
|
337
|
+
|
|
338
|
+
</li>
|
|
339
|
+
|
|
340
|
+
</ul>
|
|
341
|
+
|
|
342
|
+
</div><table class="source_code">
|
|
343
|
+
<tr>
|
|
344
|
+
<td>
|
|
345
|
+
<pre class="lines">
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
22
|
|
349
|
+
23
|
|
350
|
+
24
|
|
351
|
+
25
|
|
352
|
+
26
|
|
353
|
+
27
|
|
354
|
+
28
|
|
355
|
+
29</pre>
|
|
356
|
+
</td>
|
|
357
|
+
<td>
|
|
358
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 22</span>
|
|
359
|
+
|
|
360
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_currency'>currency</span><span class='lparen'>(</span><span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
|
|
361
|
+
<span class='kw'>case</span> <span class='id identifier rubyid_currency'>currency</span>
|
|
362
|
+
<span class='kw'>when</span> <span class='kw'>nil</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] ot [String] (</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>
|
|
367
|
+
<span class='kw'>end</span></pre>
|
|
368
|
+
</td>
|
|
369
|
+
</tr>
|
|
370
|
+
</table>
|
|
371
|
+
</div>
|
|
372
|
+
|
|
373
|
+
<div class="method_details ">
|
|
374
|
+
<h3 class="signature " id="money-class_method">
|
|
375
|
+
|
|
376
|
+
.<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
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
</h3><div class="docstring">
|
|
383
|
+
<div class="discussion">
|
|
384
|
+
<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>
|
|
385
|
+
|
|
386
|
+
</div>
|
|
387
|
+
</div>
|
|
388
|
+
<div class="tags">
|
|
389
|
+
<p class="tag_title">Parameters:</p>
|
|
390
|
+
<ul class="param">
|
|
391
|
+
|
|
392
|
+
<li>
|
|
393
|
+
|
|
394
|
+
<span class='name'>amount</span>
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
<span class='type'>(<tt>Numeric</tt>)</span>
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
—
|
|
402
|
+
<div class='inline'><p>the financial value</p></div>
|
|
403
|
+
|
|
404
|
+
</li>
|
|
405
|
+
|
|
406
|
+
<li>
|
|
407
|
+
|
|
408
|
+
<span class='name'>currency_code</span>
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
<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>
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
—
|
|
416
|
+
<div class='inline'><p>Currency code</p></div>
|
|
417
|
+
|
|
418
|
+
</li>
|
|
419
|
+
|
|
420
|
+
</ul>
|
|
421
|
+
|
|
422
|
+
<p class="tag_title">Returns:</p>
|
|
423
|
+
<ul class="return">
|
|
424
|
+
|
|
425
|
+
<li>
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
—
|
|
433
|
+
<div class='inline'><p>the instantiated Money object</p></div>
|
|
434
|
+
|
|
435
|
+
</li>
|
|
436
|
+
|
|
437
|
+
</ul>
|
|
438
|
+
<p class="tag_title">Raises:</p>
|
|
439
|
+
<ul class="raise">
|
|
440
|
+
|
|
441
|
+
<li>
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
—
|
|
449
|
+
<div class='inline'><p>if the currency code is not registered</p></div>
|
|
450
|
+
|
|
451
|
+
</li>
|
|
452
|
+
|
|
453
|
+
</ul>
|
|
454
|
+
|
|
455
|
+
</div><table class="source_code">
|
|
456
|
+
<tr>
|
|
457
|
+
<td>
|
|
458
|
+
<pre class="lines">
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
15</pre>
|
|
462
|
+
</td>
|
|
463
|
+
<td>
|
|
464
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 15</span>
|
|
465
|
+
|
|
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 rubyid_create'><span class='object_link'><a href="Mint/Money.html#create-class_method" title="Mint::Money.create (method)">create</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
|
+
</td>
|
|
468
|
+
</tr>
|
|
469
|
+
</table>
|
|
470
|
+
</div>
|
|
471
|
+
|
|
472
|
+
<div class="method_details ">
|
|
473
|
+
<h3 class="signature " id="register_currency-class_method">
|
|
474
|
+
|
|
475
|
+
.<strong>register_currency</strong>(code:, subunit: 0, symbol: '', priority: 0) ⇒ <tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
</h3><div class="docstring">
|
|
482
|
+
<div class="discussion">
|
|
483
|
+
<p>Registers a new currency, raising a KeyError if already registered.</p>
|
|
484
|
+
|
|
485
|
+
</div>
|
|
486
|
+
</div>
|
|
487
|
+
<div class="tags">
|
|
488
|
+
<p class="tag_title">Parameters:</p>
|
|
489
|
+
<ul class="param">
|
|
490
|
+
|
|
491
|
+
<li>
|
|
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>
|
|
504
|
+
|
|
505
|
+
<li>
|
|
506
|
+
|
|
507
|
+
<span class='name'>subunit</span>
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
<span class='type'>(<tt>Integer</tt>)</span>
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
<em class="default">(defaults to: <tt>0</tt>)</em>
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
—
|
|
517
|
+
<div class='inline'><p>the decimal subunit precision, defaults to 0</p></div>
|
|
518
|
+
|
|
519
|
+
</li>
|
|
520
|
+
|
|
521
|
+
<li>
|
|
522
|
+
|
|
523
|
+
<span class='name'>symbol</span>
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
<em class="default">(defaults to: <tt>''</tt>)</em>
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
—
|
|
533
|
+
<div class='inline'><p>the display symbol</p></div>
|
|
534
|
+
|
|
535
|
+
</li>
|
|
536
|
+
|
|
537
|
+
<li>
|
|
538
|
+
|
|
539
|
+
<span class='name'>priority</span>
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
<span class='type'>(<tt>Integer</tt>)</span>
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
<em class="default">(defaults to: <tt>0</tt>)</em>
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
—
|
|
549
|
+
<div class='inline'><p>parser precedence priority</p></div>
|
|
550
|
+
|
|
551
|
+
</li>
|
|
552
|
+
|
|
553
|
+
</ul>
|
|
554
|
+
|
|
555
|
+
<p class="tag_title">Returns:</p>
|
|
556
|
+
<ul class="return">
|
|
557
|
+
|
|
558
|
+
<li>
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>)</span>
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
—
|
|
566
|
+
<div class='inline'><p>the newly registered Currency instance</p></div>
|
|
567
|
+
|
|
568
|
+
</li>
|
|
569
|
+
|
|
570
|
+
</ul>
|
|
571
|
+
<p class="tag_title">Raises:</p>
|
|
572
|
+
<ul class="raise">
|
|
573
|
+
|
|
574
|
+
<li>
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
—
|
|
582
|
+
<div class='inline'><p>if the code contains invalid characters</p></div>
|
|
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>
|
|
595
|
+
|
|
596
|
+
</li>
|
|
597
|
+
|
|
598
|
+
</ul>
|
|
599
|
+
|
|
600
|
+
</div><table class="source_code">
|
|
601
|
+
<tr>
|
|
602
|
+
<td>
|
|
603
|
+
<pre class="lines">
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
40
|
|
607
|
+
41
|
|
608
|
+
42</pre>
|
|
609
|
+
</td>
|
|
610
|
+
<td>
|
|
611
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/mint.rb', line 40</span>
|
|
612
|
+
|
|
613
|
+
<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>
|
|
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>
|
|
616
|
+
</td>
|
|
617
|
+
</tr>
|
|
618
|
+
</table>
|
|
619
|
+
</div>
|
|
620
|
+
|
|
621
|
+
<div class="method_details ">
|
|
622
|
+
<h3 class="signature " id="use_top_level_constants!-class_method">
|
|
623
|
+
|
|
624
|
+
.<strong>use_top_level_constants!</strong> ⇒ <tt>Object</tt>
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
</h3><table class="source_code">
|
|
631
|
+
<tr>
|
|
632
|
+
<td>
|
|
633
|
+
<pre class="lines">
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
23
|
|
637
|
+
24
|
|
638
|
+
25
|
|
639
|
+
26
|
|
640
|
+
27
|
|
641
|
+
28
|
|
642
|
+
29
|
|
643
|
+
30
|
|
644
|
+
31</pre>
|
|
645
|
+
</td>
|
|
646
|
+
<td>
|
|
647
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/dsl.rb', line 23</span>
|
|
648
|
+
|
|
649
|
+
<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>
|
|
650
|
+
<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>
|
|
651
|
+
<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>
|
|
652
|
+
<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>
|
|
653
|
+
<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>
|
|
654
|
+
<span class='kw'>else</span>
|
|
655
|
+
<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>
|
|
656
|
+
<span class='kw'>end</span>
|
|
657
|
+
<span class='kw'>end</span></pre>
|
|
658
|
+
</td>
|
|
659
|
+
</tr>
|
|
660
|
+
</table>
|
|
661
|
+
</div>
|
|
662
|
+
|
|
663
|
+
<div class="method_details ">
|
|
664
|
+
<h3 class="signature " id="world_currencies-class_method">
|
|
665
|
+
|
|
666
|
+
.<strong>world_currencies</strong> ⇒ <tt>Hash{String => <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>}</tt>
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
</h3><div class="docstring">
|
|
673
|
+
<div class="discussion">
|
|
674
|
+
<p class="note private">
|
|
675
|
+
<strong>This method is part of a private API.</strong>
|
|
676
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
677
|
+
</p>
|
|
678
|
+
<p>Loads ISO world currencies from YAML file into the registry.</p>
|
|
679
|
+
|
|
680
|
+
</div>
|
|
681
|
+
</div>
|
|
682
|
+
<div class="tags">
|
|
683
|
+
|
|
684
|
+
<p class="tag_title">Returns:</p>
|
|
685
|
+
<ul class="return">
|
|
686
|
+
|
|
687
|
+
<li>
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
<span class='type'>(<tt>Hash{String => <span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span>}</tt>)</span>
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
—
|
|
695
|
+
<div class='inline'><p>ISO-4217 world currencies mapped by code</p></div>
|
|
696
|
+
|
|
697
|
+
</li>
|
|
698
|
+
|
|
699
|
+
</ul>
|
|
700
|
+
|
|
701
|
+
</div><table class="source_code">
|
|
702
|
+
<tr>
|
|
703
|
+
<td>
|
|
704
|
+
<pre class="lines">
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
9
|
|
708
|
+
10
|
|
709
|
+
11
|
|
710
|
+
12
|
|
711
|
+
13
|
|
712
|
+
14
|
|
713
|
+
15</pre>
|
|
714
|
+
</td>
|
|
715
|
+
<td>
|
|
716
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/currency/world_currencies.rb', line 9</span>
|
|
717
|
+
|
|
718
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_world_currencies'>world_currencies</span>
|
|
719
|
+
<span class='ivar'>@world_currencies</span> <span class='op'>||=</span> <span class='kw'>begin</span>
|
|
720
|
+
<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>
|
|
721
|
+
|
|
722
|
+
<span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_h'>to_h</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_entry'>entry</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_entry'>entry</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>code</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Mint/Currency.html#initialize-instance_method" title="Mint::Currency#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_entry'>entry</span><span class='period'>.</span><span class='id identifier rubyid_transform_keys'>transform_keys</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:to_sym</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
|
|
723
|
+
<span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>
|
|
724
|
+
<span class='kw'>end</span></pre>
|
|
725
|
+
</td>
|
|
726
|
+
</tr>
|
|
727
|
+
</table>
|
|
728
|
+
</div>
|
|
729
|
+
|
|
730
|
+
</div>
|
|
731
|
+
|
|
732
|
+
<div id="instance_method_details" class="method_details_list">
|
|
733
|
+
<h2>Instance Method Details</h2>
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
<div class="method_details first">
|
|
737
|
+
<h3 class="signature first" id="parse-instance_method">
|
|
738
|
+
|
|
739
|
+
#<strong>parse</strong>(input, currency = nil) ⇒ <tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
</h3><div class="docstring">
|
|
746
|
+
<div class="discussion">
|
|
747
|
+
<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>
|
|
748
|
+
|
|
749
|
+
</div>
|
|
750
|
+
</div>
|
|
751
|
+
<div class="tags">
|
|
752
|
+
|
|
753
|
+
<div class="examples">
|
|
754
|
+
<h4 class="tag_title">Examples:</h4>
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
<h5 class="example_title"><div class='inline'><p>With explicit currency</p></div></h5>
|
|
758
|
+
|
|
759
|
+
<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]
|
|
760
|
+
</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>
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
<h5 class="example_title"><div class='inline'><p>With symbol or code in the string</p></div></h5>
|
|
764
|
+
|
|
765
|
+
<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]
|
|
766
|
+
</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]
|
|
767
|
+
</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>
|
|
768
|
+
|
|
769
|
+
</div>
|
|
770
|
+
<p class="tag_title">Parameters:</p>
|
|
771
|
+
<ul class="param">
|
|
772
|
+
|
|
773
|
+
<li>
|
|
774
|
+
|
|
775
|
+
<span class='name'>input</span>
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
—
|
|
783
|
+
<div class='inline'><p>Amount input, optionally including a currency symbol or code</p></div>
|
|
784
|
+
|
|
785
|
+
</li>
|
|
786
|
+
|
|
787
|
+
<li>
|
|
788
|
+
|
|
789
|
+
<span class='name'>currency</span>
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
<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>
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
—
|
|
799
|
+
<div class='inline'><p>ISO code when not present in <code>input</code></p></div>
|
|
800
|
+
|
|
801
|
+
</li>
|
|
802
|
+
|
|
803
|
+
</ul>
|
|
804
|
+
|
|
805
|
+
<p class="tag_title">Returns:</p>
|
|
806
|
+
<ul class="return">
|
|
807
|
+
|
|
808
|
+
<li>
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
</li>
|
|
816
|
+
|
|
817
|
+
</ul>
|
|
818
|
+
<p class="tag_title">Raises:</p>
|
|
819
|
+
<ul class="raise">
|
|
820
|
+
|
|
821
|
+
<li>
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
—
|
|
829
|
+
<div class='inline'><p>when <code>input</code> is invalid or currency cannot be determined</p></div>
|
|
830
|
+
|
|
831
|
+
</li>
|
|
832
|
+
|
|
833
|
+
</ul>
|
|
834
|
+
|
|
835
|
+
</div><table class="source_code">
|
|
836
|
+
<tr>
|
|
837
|
+
<td>
|
|
838
|
+
<pre class="lines">
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
22
|
|
842
|
+
23
|
|
843
|
+
24
|
|
844
|
+
25
|
|
845
|
+
26
|
|
846
|
+
27
|
|
847
|
+
28
|
|
848
|
+
29
|
|
849
|
+
30
|
|
850
|
+
31
|
|
851
|
+
32
|
|
852
|
+
33</pre>
|
|
853
|
+
</td>
|
|
854
|
+
<td>
|
|
855
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/parser.rb', line 22</span>
|
|
856
|
+
|
|
857
|
+
<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>
|
|
858
|
+
<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>
|
|
859
|
+
|
|
860
|
+
<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>
|
|
861
|
+
<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>
|
|
862
|
+
|
|
863
|
+
<span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</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_currency'><span class='object_link'><a href="#currency-class_method" title="Mint.currency (method)">currency</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</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='rparen'>)</span>
|
|
864
|
+
<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 registered</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_currency'>currency</span>
|
|
865
|
+
|
|
866
|
+
<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_parse_amount'>parse_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
867
|
+
<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>
|
|
868
|
+
<span class='kw'>end</span></pre>
|
|
869
|
+
</td>
|
|
870
|
+
</tr>
|
|
871
|
+
</table>
|
|
872
|
+
</div>
|
|
873
|
+
|
|
874
|
+
</div>
|
|
875
|
+
|
|
876
|
+
</div>
|
|
877
|
+
|
|
878
|
+
<div id="footer">
|
|
879
|
+
Generated on Wed Jun 10 01:35:30 2026 by
|
|
880
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
881
|
+
0.9.44 (ruby-4.0.1).
|
|
882
|
+
</div>
|
|
883
|
+
|
|
884
|
+
</div>
|
|
885
|
+
</body>
|
|
886
|
+
</html>
|