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/Money.html
CHANGED
|
@@ -235,6 +235,28 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
235
235
|
|
|
236
236
|
|
|
237
237
|
|
|
238
|
+
<span class="summary_desc"><div class='inline'><p>Backwards-compatible alias for previous API TODO: deprecate in a future major release.</p></div></span>
|
|
239
|
+
|
|
240
|
+
</li>
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
<li class="public ">
|
|
244
|
+
<span class="summary_signature">
|
|
245
|
+
|
|
246
|
+
<a href="#from-class_method" title="from (class method)">.<strong>from</strong>(amount, currency) ⇒ Object </a>
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
</span>
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
238
260
|
<span class="summary_desc"><div class='inline'><p>Creates a new Money immutable object with the specified amount and currency.</p></div></span>
|
|
239
261
|
|
|
240
262
|
</li>
|
|
@@ -262,6 +284,72 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
262
284
|
</li>
|
|
263
285
|
|
|
264
286
|
|
|
287
|
+
<li class="public ">
|
|
288
|
+
<span class="summary_signature">
|
|
289
|
+
|
|
290
|
+
<a href="#parse-class_method" title="parse (class method)">.<strong>parse</strong>(input, currency = nil) ⇒ Money<sup>?</sup> </a>
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
</span>
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
<span class="summary_desc"><div class='inline'><p>Parses a human-readable money string into a <span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span> object.</p></div></span>
|
|
305
|
+
|
|
306
|
+
</li>
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
<li class="public ">
|
|
310
|
+
<span class="summary_signature">
|
|
311
|
+
|
|
312
|
+
<a href="#parse!-class_method" title="parse! (class method)">.<strong>parse!</strong>(input, currency = nil) ⇒ Money </a>
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
</span>
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
<span class="summary_desc"><div class='inline'><p>Like <span class='object_link'><a href="#parse-class_method" title="Mint::Money.parse (method)">Money.parse</a></span> but raises on failure.</p></div></span>
|
|
327
|
+
|
|
328
|
+
</li>
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
<li class="public ">
|
|
332
|
+
<span class="summary_signature">
|
|
333
|
+
|
|
334
|
+
<a href="#zero-class_method" title="zero (class method)">.<strong>zero</strong>(currency) ⇒ Money </a>
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
</span>
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
<span class="summary_desc"><div class='inline'><p>Returns a frozen zero Money in the given currency.</p></div></span>
|
|
349
|
+
|
|
350
|
+
</li>
|
|
351
|
+
|
|
352
|
+
|
|
265
353
|
</ul>
|
|
266
354
|
|
|
267
355
|
|
|
@@ -495,6 +583,28 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
495
583
|
<li class="public ">
|
|
496
584
|
<span class="summary_signature">
|
|
497
585
|
|
|
586
|
+
<a href="#change-instance_method" title="#change (instance method)">#<strong>change</strong>(new_amount) ⇒ Money </a>
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
</span>
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
<span class="summary_desc"><div class='inline'><p>Returns a new Money object with the specified amount, or self if unchanged.</p></div></span>
|
|
601
|
+
|
|
602
|
+
</li>
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
<li class="public ">
|
|
606
|
+
<span class="summary_signature">
|
|
607
|
+
|
|
498
608
|
<a href="#clamp-instance_method" title="#clamp (instance method)">#<strong>clamp</strong>(min_or_range, max = nil) ⇒ Money </a>
|
|
499
609
|
|
|
500
610
|
|
|
@@ -649,7 +759,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
649
759
|
<li class="public ">
|
|
650
760
|
<span class="summary_signature">
|
|
651
761
|
|
|
652
|
-
<a href="#mint-instance_method" title="#mint (instance method)">#<strong>mint</strong>(new_amount) ⇒
|
|
762
|
+
<a href="#mint-instance_method" title="#mint (instance method)">#<strong>mint</strong>(new_amount) ⇒ Object </a>
|
|
653
763
|
|
|
654
764
|
|
|
655
765
|
|
|
@@ -663,7 +773,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
663
773
|
|
|
664
774
|
|
|
665
775
|
|
|
666
|
-
<span class="summary_desc"><div class='inline'
|
|
776
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
|
667
777
|
|
|
668
778
|
</li>
|
|
669
779
|
|
|
@@ -751,7 +861,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
751
861
|
|
|
752
862
|
|
|
753
863
|
|
|
754
|
-
<span class="summary_desc"><div class='inline'><p>Helper method to verify if another
|
|
864
|
+
<span class="summary_desc"><div class='inline'><p>Helper method to verify if another Money has the identical currency.</p></div></span>
|
|
755
865
|
|
|
756
866
|
</li>
|
|
757
867
|
|
|
@@ -957,7 +1067,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
957
1067
|
<li class="public ">
|
|
958
1068
|
<span class="summary_signature">
|
|
959
1069
|
|
|
960
|
-
<a href="#to_s-instance_method" title="#to_s (instance method)">#<strong>to_s</strong>(format:
|
|
1070
|
+
<a href="#to_s-instance_method" title="#to_s (instance method)">#<strong>to_s</strong>(format: nil, decimal: nil, thousand: nil, width: nil) ⇒ String </a>
|
|
961
1071
|
|
|
962
1072
|
|
|
963
1073
|
|
|
@@ -1033,12 +1143,12 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1033
1143
|
<pre class="lines">
|
|
1034
1144
|
|
|
1035
1145
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1146
|
+
22
|
|
1147
|
+
23
|
|
1148
|
+
24</pre>
|
|
1039
1149
|
</td>
|
|
1040
1150
|
<td>
|
|
1041
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
1151
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 22</span>
|
|
1042
1152
|
|
|
1043
1153
|
<span class='kw'>def</span> <span class='id identifier rubyid_amount'>amount</span>
|
|
1044
1154
|
<span class='ivar'>@amount</span>
|
|
@@ -1074,12 +1184,12 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1074
1184
|
<pre class="lines">
|
|
1075
1185
|
|
|
1076
1186
|
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1187
|
+
22
|
|
1188
|
+
23
|
|
1189
|
+
24</pre>
|
|
1080
1190
|
</td>
|
|
1081
1191
|
<td>
|
|
1082
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
1192
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 22</span>
|
|
1083
1193
|
|
|
1084
1194
|
<span class='kw'>def</span> <span class='id identifier rubyid_currency'>currency</span>
|
|
1085
1195
|
<span class='ivar'>@currency</span>
|
|
@@ -1105,6 +1215,48 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1105
1215
|
|
|
1106
1216
|
|
|
1107
1217
|
|
|
1218
|
+
</h3><div class="docstring">
|
|
1219
|
+
<div class="discussion">
|
|
1220
|
+
<p>Backwards-compatible alias for previous API
|
|
1221
|
+
TODO: deprecate in a future major release</p>
|
|
1222
|
+
|
|
1223
|
+
</div>
|
|
1224
|
+
</div>
|
|
1225
|
+
<div class="tags">
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
</div><table class="source_code">
|
|
1229
|
+
<tr>
|
|
1230
|
+
<td>
|
|
1231
|
+
<pre class="lines">
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
57
|
|
1235
|
+
58
|
|
1236
|
+
59
|
|
1237
|
+
60</pre>
|
|
1238
|
+
</td>
|
|
1239
|
+
<td>
|
|
1240
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 57</span>
|
|
1241
|
+
|
|
1242
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</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>
|
|
1243
|
+
<span class='id identifier rubyid_warn'>warn</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Money.create is now deprecated. Use Money.from</span><span class='tstring_end'>'</span></span>
|
|
1244
|
+
<span class='id identifier rubyid_from'>from</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>
|
|
1245
|
+
<span class='kw'>end</span></pre>
|
|
1246
|
+
</td>
|
|
1247
|
+
</tr>
|
|
1248
|
+
</table>
|
|
1249
|
+
</div>
|
|
1250
|
+
|
|
1251
|
+
<div class="method_details ">
|
|
1252
|
+
<h3 class="signature " id="from-class_method">
|
|
1253
|
+
|
|
1254
|
+
.<strong>from</strong>(amount, currency) ⇒ <tt>Object</tt>
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1108
1260
|
</h3><div class="docstring">
|
|
1109
1261
|
<div class="discussion">
|
|
1110
1262
|
<p>Creates a new Money immutable object with the specified amount and currency</p>
|
|
@@ -1131,20 +1283,377 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1131
1283
|
|
|
1132
1284
|
<li>
|
|
1133
1285
|
|
|
1134
|
-
<span class='name'>currency</span>
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
<span class='type'>(<tt><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>String</tt>)</span>
|
|
1286
|
+
<span class='name'>currency</span>
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
<span class='type'>(<tt><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>String</tt>)</span>
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
—
|
|
1294
|
+
<div class='inline'><p>The currency code or currency object</p></div>
|
|
1295
|
+
|
|
1296
|
+
</li>
|
|
1297
|
+
|
|
1298
|
+
</ul>
|
|
1299
|
+
|
|
1300
|
+
<p class="tag_title">Raises:</p>
|
|
1301
|
+
<ul class="raise">
|
|
1302
|
+
|
|
1303
|
+
<li>
|
|
1304
|
+
|
|
1305
|
+
|
|
1306
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
—
|
|
1311
|
+
<div class='inline'><p>If amount is not numeric or currency is invalid</p></div>
|
|
1312
|
+
|
|
1313
|
+
</li>
|
|
1314
|
+
|
|
1315
|
+
</ul>
|
|
1316
|
+
|
|
1317
|
+
</div><table class="source_code">
|
|
1318
|
+
<tr>
|
|
1319
|
+
<td>
|
|
1320
|
+
<pre class="lines">
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
10
|
|
1324
|
+
11
|
|
1325
|
+
12
|
|
1326
|
+
13
|
|
1327
|
+
14
|
|
1328
|
+
15
|
|
1329
|
+
16
|
|
1330
|
+
17</pre>
|
|
1331
|
+
</td>
|
|
1332
|
+
<td>
|
|
1333
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 10</span>
|
|
1334
|
+
|
|
1335
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_from'>from</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>
|
|
1336
|
+
<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'>amount must be Numeric</span><span class='tstring_end'>'</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Numeric</span><span class='rparen'>)</span>
|
|
1337
|
+
|
|
1338
|
+
<span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></span><span class='period'>.</span><span class='id identifier rubyid_resolve!'><span class='object_link'><a href="Currency.html#resolve!-class_method" title="Mint::Currency.resolve! (method)">resolve!</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
|
|
1339
|
+
<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>
|
|
1340
|
+
|
|
1341
|
+
<span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span> <span class='op'>?</span> <span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_zero'>zero</span> <span class='op'>:</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>
|
|
1342
|
+
<span class='kw'>end</span></pre>
|
|
1343
|
+
</td>
|
|
1344
|
+
</tr>
|
|
1345
|
+
</table>
|
|
1346
|
+
</div>
|
|
1347
|
+
|
|
1348
|
+
<div class="method_details ">
|
|
1349
|
+
<h3 class="signature " id="from_fractional-class_method">
|
|
1350
|
+
|
|
1351
|
+
.<strong>from_fractional</strong>(fractional, currency) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
</h3><div class="docstring">
|
|
1358
|
+
<div class="discussion">
|
|
1359
|
+
<p>Builds a Money from a fractional (smallest-unit) Integer amount.
|
|
1360
|
+
This is the inverse of <span class='object_link'><a href="#fractional-instance_method" title="Mint::Money#fractional (method)">#fractional</a></span>: for USD, the fractional unit is
|
|
1361
|
+
1 cent; for JPY it is 1 yen; for IQD it is 1 dinar (subunit 3).</p>
|
|
1362
|
+
|
|
1363
|
+
</div>
|
|
1364
|
+
</div>
|
|
1365
|
+
<div class="tags">
|
|
1366
|
+
|
|
1367
|
+
<div class="examples">
|
|
1368
|
+
<h4 class="tag_title">Examples:</h4>
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
<h5 class="example_title"><div class='inline'><p>USD cents</p></div></h5>
|
|
1372
|
+
|
|
1373
|
+
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from_fractional'>from_fractional</span><span class='lparen'>(</span><span class='int'>123_456</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 1234.56]</span></code></pre>
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
<h5 class="example_title"><div class='inline'><p>JPY (subunit 0)</p></div></h5>
|
|
1377
|
+
|
|
1378
|
+
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from_fractional'>from_fractional</span><span class='lparen'>(</span><span class='int'>1234</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>JPY</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [JPY 1234]</span></code></pre>
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
<h5 class="example_title"><div class='inline'><p>Round trip</p></div></h5>
|
|
1382
|
+
|
|
1383
|
+
<pre class="example code"><code><span class='id identifier rubyid_m'>m</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="../Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>9.99</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>
|
|
1384
|
+
<span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from_fractional'>from_fractional</span><span class='lparen'>(</span><span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_fractional'>fractional</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='op'>==</span> <span class='id identifier rubyid_m'>m</span> <span class='comment'>#=> true</span></code></pre>
|
|
1385
|
+
|
|
1386
|
+
</div>
|
|
1387
|
+
<p class="tag_title">Parameters:</p>
|
|
1388
|
+
<ul class="param">
|
|
1389
|
+
|
|
1390
|
+
<li>
|
|
1391
|
+
|
|
1392
|
+
<span class='name'>fractional</span>
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
<span class='type'>(<tt>Integer</tt>)</span>
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
—
|
|
1400
|
+
<div class='inline'><p>the amount expressed in the currency's
|
|
1401
|
+
smallest unit (e.g. cents). Must be an Integer to preserve exactness.</p></div>
|
|
1402
|
+
|
|
1403
|
+
</li>
|
|
1404
|
+
|
|
1405
|
+
<li>
|
|
1406
|
+
|
|
1407
|
+
<span class='name'>currency</span>
|
|
1408
|
+
|
|
1409
|
+
|
|
1410
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>, <tt><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>)</span>
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
—
|
|
1415
|
+
<div class='inline'><p>the currency identifier</p></div>
|
|
1416
|
+
|
|
1417
|
+
</li>
|
|
1418
|
+
|
|
1419
|
+
</ul>
|
|
1420
|
+
|
|
1421
|
+
<p class="tag_title">Returns:</p>
|
|
1422
|
+
<ul class="return">
|
|
1423
|
+
|
|
1424
|
+
<li>
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
—
|
|
1432
|
+
<div class='inline'><p>the resulting Money instance</p></div>
|
|
1433
|
+
|
|
1434
|
+
</li>
|
|
1435
|
+
|
|
1436
|
+
</ul>
|
|
1437
|
+
<p class="tag_title">Raises:</p>
|
|
1438
|
+
<ul class="raise">
|
|
1439
|
+
|
|
1440
|
+
<li>
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
—
|
|
1448
|
+
<div class='inline'><p>if <code>fractional</code> is not an Integer or <code>currency</code>
|
|
1449
|
+
is not registered</p></div>
|
|
1450
|
+
|
|
1451
|
+
</li>
|
|
1452
|
+
|
|
1453
|
+
</ul>
|
|
1454
|
+
|
|
1455
|
+
</div><table class="source_code">
|
|
1456
|
+
<tr>
|
|
1457
|
+
<td>
|
|
1458
|
+
<pre class="lines">
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
80
|
|
1462
|
+
81
|
|
1463
|
+
82
|
|
1464
|
+
83
|
|
1465
|
+
84
|
|
1466
|
+
85
|
|
1467
|
+
86</pre>
|
|
1468
|
+
</td>
|
|
1469
|
+
<td>
|
|
1470
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 80</span>
|
|
1471
|
+
|
|
1472
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_from_fractional'>from_fractional</span><span class='lparen'>(</span><span class='id identifier rubyid_fractional'>fractional</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
|
|
1473
|
+
<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'>fractional must be an Integer</span><span class='tstring_end'>'</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_fractional'>fractional</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Integer</span><span class='rparen'>)</span>
|
|
1474
|
+
|
|
1475
|
+
<span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></span><span class='period'>.</span><span class='id identifier rubyid_resolve!'><span class='object_link'><a href="Currency.html#resolve!-class_method" title="Mint::Currency.resolve! (method)">resolve!</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
|
|
1476
|
+
<span class='id identifier rubyid_amount'>amount</span> <span class='op'>=</span> <span class='const'>Rational</span><span class='lparen'>(</span><span class='id identifier rubyid_fractional'>fractional</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_fractional_multiplier'>fractional_multiplier</span><span class='rparen'>)</span>
|
|
1477
|
+
<span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span> <span class='op'>?</span> <span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_zero'>zero</span> <span class='op'>:</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>
|
|
1478
|
+
<span class='kw'>end</span></pre>
|
|
1479
|
+
</td>
|
|
1480
|
+
</tr>
|
|
1481
|
+
</table>
|
|
1482
|
+
</div>
|
|
1483
|
+
|
|
1484
|
+
<div class="method_details ">
|
|
1485
|
+
<h3 class="signature " id="parse-class_method">
|
|
1486
|
+
|
|
1487
|
+
.<strong>parse</strong>(input, currency = nil) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt><sup>?</sup>
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
</h3><div class="docstring">
|
|
1494
|
+
<div class="discussion">
|
|
1495
|
+
<p>Parses a human-readable money string into a <span class='object_link'><a href="" title="Mint::Money (class)">Mint::Money</a></span> object.</p>
|
|
1496
|
+
<p>Returns <code>nil</code> when the input is invalid or currency cannot be determined.</p>
|
|
1497
|
+
|
|
1498
|
+
</div>
|
|
1499
|
+
</div>
|
|
1500
|
+
<div class="tags">
|
|
1501
|
+
|
|
1502
|
+
<div class="examples">
|
|
1503
|
+
<h4 class="tag_title">Examples:</h4>
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
<h5 class="example_title"><div class='inline'><p>With explicit currency</p></div></h5>
|
|
1507
|
+
|
|
1508
|
+
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" 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]
|
|
1509
|
+
</span><span class='const'><span class='object_link'><a href="" 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'>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>
|
|
1510
|
+
|
|
1511
|
+
|
|
1512
|
+
<h5 class="example_title"><div class='inline'><p>With symbol or code in the string</p></div></h5>
|
|
1513
|
+
|
|
1514
|
+
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" 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]
|
|
1515
|
+
</span><span class='const'><span class='object_link'><a href="" 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>
|
|
1516
|
+
|
|
1517
|
+
</div>
|
|
1518
|
+
<p class="tag_title">Parameters:</p>
|
|
1519
|
+
<ul class="param">
|
|
1520
|
+
|
|
1521
|
+
<li>
|
|
1522
|
+
|
|
1523
|
+
<span class='name'>input</span>
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
1527
|
+
|
|
1528
|
+
|
|
1529
|
+
|
|
1530
|
+
—
|
|
1531
|
+
<div class='inline'><p>Amount input, optionally including a currency symbol or code</p></div>
|
|
1532
|
+
|
|
1533
|
+
</li>
|
|
1534
|
+
|
|
1535
|
+
<li>
|
|
1536
|
+
|
|
1537
|
+
<span class='name'>currency</span>
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>, <tt><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>nil</tt>)</span>
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
—
|
|
1547
|
+
<div class='inline'><p>ISO code when not present in <code>input</code></p></div>
|
|
1548
|
+
|
|
1549
|
+
</li>
|
|
1550
|
+
|
|
1551
|
+
</ul>
|
|
1552
|
+
|
|
1553
|
+
<p class="tag_title">Returns:</p>
|
|
1554
|
+
<ul class="return">
|
|
1555
|
+
|
|
1556
|
+
<li>
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>, <tt>nil</tt>)</span>
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
</li>
|
|
1564
|
+
|
|
1565
|
+
</ul>
|
|
1566
|
+
|
|
1567
|
+
</div><table class="source_code">
|
|
1568
|
+
<tr>
|
|
1569
|
+
<td>
|
|
1570
|
+
<pre class="lines">
|
|
1571
|
+
|
|
1572
|
+
|
|
1573
|
+
34</pre>
|
|
1574
|
+
</td>
|
|
1575
|
+
<td>
|
|
1576
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 34</span>
|
|
1577
|
+
|
|
1578
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</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> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="../Mint.html#parse-instance_method" title="Mint#parse (method)">parse</a></span></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></pre>
|
|
1579
|
+
</td>
|
|
1580
|
+
</tr>
|
|
1581
|
+
</table>
|
|
1582
|
+
</div>
|
|
1583
|
+
|
|
1584
|
+
<div class="method_details ">
|
|
1585
|
+
<h3 class="signature " id="parse!-class_method">
|
|
1586
|
+
|
|
1587
|
+
.<strong>parse!</strong>(input, currency = nil) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
|
|
1593
|
+
</h3><div class="docstring">
|
|
1594
|
+
<div class="discussion">
|
|
1595
|
+
<p>Like <span class='object_link'><a href="#parse-class_method" title="Mint::Money.parse (method)">parse</a></span> but raises on failure.</p>
|
|
1596
|
+
|
|
1597
|
+
</div>
|
|
1598
|
+
</div>
|
|
1599
|
+
<div class="tags">
|
|
1600
|
+
|
|
1601
|
+
<div class="examples">
|
|
1602
|
+
<h4 class="tag_title">Examples:</h4>
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" 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]
|
|
1606
|
+
</span><span class='const'><span class='object_link'><a href="" 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'>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>
|
|
1607
|
+
|
|
1608
|
+
</div>
|
|
1609
|
+
<p class="tag_title">Parameters:</p>
|
|
1610
|
+
<ul class="param">
|
|
1611
|
+
|
|
1612
|
+
<li>
|
|
1613
|
+
|
|
1614
|
+
<span class='name'>input</span>
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
1618
|
+
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
—
|
|
1622
|
+
<div class='inline'><p>Amount input, optionally including a currency symbol or code</p></div>
|
|
1623
|
+
|
|
1624
|
+
</li>
|
|
1625
|
+
|
|
1626
|
+
<li>
|
|
1627
|
+
|
|
1628
|
+
<span class='name'>currency</span>
|
|
1629
|
+
|
|
1630
|
+
|
|
1631
|
+
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>, <tt><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>, <tt>nil</tt>)</span>
|
|
1632
|
+
|
|
1633
|
+
|
|
1634
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
1635
|
+
|
|
1636
|
+
|
|
1637
|
+
—
|
|
1638
|
+
<div class='inline'><p>ISO code when not present in <code>input</code></p></div>
|
|
1639
|
+
|
|
1640
|
+
</li>
|
|
1641
|
+
|
|
1642
|
+
</ul>
|
|
1643
|
+
|
|
1644
|
+
<p class="tag_title">Returns:</p>
|
|
1645
|
+
<ul class="return">
|
|
1646
|
+
|
|
1647
|
+
<li>
|
|
1648
|
+
|
|
1138
1649
|
|
|
1650
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
1139
1651
|
|
|
1140
1652
|
|
|
1141
|
-
—
|
|
1142
|
-
<div class='inline'><p>The currency code or currency object</p></div>
|
|
1143
1653
|
|
|
1144
1654
|
</li>
|
|
1145
1655
|
|
|
1146
1656
|
</ul>
|
|
1147
|
-
|
|
1148
1657
|
<p class="tag_title">Raises:</p>
|
|
1149
1658
|
<ul class="raise">
|
|
1150
1659
|
|
|
@@ -1156,7 +1665,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1156
1665
|
|
|
1157
1666
|
|
|
1158
1667
|
—
|
|
1159
|
-
<div class='inline'><p>
|
|
1668
|
+
<div class='inline'><p>when <code>input</code> is invalid or currency cannot be determined</p></div>
|
|
1160
1669
|
|
|
1161
1670
|
</li>
|
|
1162
1671
|
|
|
@@ -1168,35 +1677,21 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1168
1677
|
<pre class="lines">
|
|
1169
1678
|
|
|
1170
1679
|
|
|
1171
|
-
|
|
1172
|
-
11
|
|
1173
|
-
12
|
|
1174
|
-
13
|
|
1175
|
-
14
|
|
1176
|
-
15
|
|
1177
|
-
16
|
|
1178
|
-
17</pre>
|
|
1680
|
+
46</pre>
|
|
1179
1681
|
</td>
|
|
1180
1682
|
<td>
|
|
1181
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
1182
|
-
|
|
1183
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</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>
|
|
1184
|
-
<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'>amount must be Numeric</span><span class='tstring_end'>'</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Numeric</span><span class='rparen'>)</span>
|
|
1185
|
-
|
|
1186
|
-
<span class='id identifier rubyid_checked_currency'>checked_currency</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency'><span class='object_link'><a href="../Mint.html#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>
|
|
1187
|
-
<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 not found (</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> <span class='kw'>unless</span> <span class='id identifier rubyid_checked_currency'>checked_currency</span>
|
|
1683
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 46</span>
|
|
1188
1684
|
|
|
1189
|
-
|
|
1190
|
-
<span class='kw'>end</span></pre>
|
|
1685
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</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> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse!'><span class='object_link'><a href="../Mint.html#parse!-instance_method" title="Mint#parse! (method)">parse!</a></span></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></pre>
|
|
1191
1686
|
</td>
|
|
1192
1687
|
</tr>
|
|
1193
1688
|
</table>
|
|
1194
1689
|
</div>
|
|
1195
1690
|
|
|
1196
1691
|
<div class="method_details ">
|
|
1197
|
-
<h3 class="signature " id="
|
|
1692
|
+
<h3 class="signature " id="zero-class_method">
|
|
1198
1693
|
|
|
1199
|
-
.<strong>
|
|
1694
|
+
.<strong>zero</strong>(currency) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
1200
1695
|
|
|
1201
1696
|
|
|
1202
1697
|
|
|
@@ -1204,63 +1699,25 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1204
1699
|
|
|
1205
1700
|
</h3><div class="docstring">
|
|
1206
1701
|
<div class="discussion">
|
|
1207
|
-
<p>
|
|
1208
|
-
This is the inverse of <span class='object_link'><a href="#fractional-instance_method" title="Mint::Money#fractional (method)">#fractional</a></span>: for USD, the fractional unit is
|
|
1209
|
-
1 cent; for JPY it is 1 yen; for IQD it is 1 dinar (subunit 3).</p>
|
|
1702
|
+
<p>Returns a frozen zero Money in the given currency.</p>
|
|
1210
1703
|
|
|
1211
1704
|
</div>
|
|
1212
1705
|
</div>
|
|
1213
1706
|
<div class="tags">
|
|
1214
|
-
|
|
1215
|
-
<div class="examples">
|
|
1216
|
-
<h4 class="tag_title">Examples:</h4>
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
<h5 class="example_title"><div class='inline'><p>USD cents</p></div></h5>
|
|
1220
|
-
|
|
1221
|
-
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from_fractional'>from_fractional</span><span class='lparen'>(</span><span class='int'>123_456</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 1234.56]</span></code></pre>
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
<h5 class="example_title"><div class='inline'><p>JPY (subunit 0)</p></div></h5>
|
|
1225
|
-
|
|
1226
|
-
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from_fractional'>from_fractional</span><span class='lparen'>(</span><span class='int'>1234</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>JPY</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [JPY 1234]</span></code></pre>
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
<h5 class="example_title"><div class='inline'><p>Round trip</p></div></h5>
|
|
1230
|
-
|
|
1231
|
-
<pre class="example code"><code><span class='id identifier rubyid_m'>m</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="../Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>9.99</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>
|
|
1232
|
-
<span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from_fractional'>from_fractional</span><span class='lparen'>(</span><span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_fractional'>fractional</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='op'>==</span> <span class='id identifier rubyid_m'>m</span> <span class='comment'>#=> true</span></code></pre>
|
|
1233
|
-
|
|
1234
|
-
</div>
|
|
1235
|
-
<p class="tag_title">Parameters:</p>
|
|
1707
|
+
<p class="tag_title">Parameters:</p>
|
|
1236
1708
|
<ul class="param">
|
|
1237
1709
|
|
|
1238
|
-
<li>
|
|
1239
|
-
|
|
1240
|
-
<span class='name'>fractional</span>
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
<span class='type'>(<tt>Integer</tt>)</span>
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
—
|
|
1248
|
-
<div class='inline'><p>the amount expressed in the currency's
|
|
1249
|
-
smallest unit (e.g. cents). Must be an Integer to preserve exactness.</p></div>
|
|
1250
|
-
|
|
1251
|
-
</li>
|
|
1252
|
-
|
|
1253
1710
|
<li>
|
|
1254
1711
|
|
|
1255
1712
|
<span class='name'>currency</span>
|
|
1256
1713
|
|
|
1257
1714
|
|
|
1258
|
-
<span class='type'>(<tt>String</tt>, <tt
|
|
1715
|
+
<span class='type'>(<tt>String</tt>, <tt><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></tt>)</span>
|
|
1259
1716
|
|
|
1260
1717
|
|
|
1261
1718
|
|
|
1262
1719
|
—
|
|
1263
|
-
<div class='inline'><p>
|
|
1720
|
+
<div class='inline'><p>a currency code or object</p></div>
|
|
1264
1721
|
|
|
1265
1722
|
</li>
|
|
1266
1723
|
|
|
@@ -1277,7 +1734,7 @@ smallest unit (e.g. cents). Must be an Integer to preserve exactness.</p></div>
|
|
|
1277
1734
|
|
|
1278
1735
|
|
|
1279
1736
|
—
|
|
1280
|
-
<div class='inline'><p>
|
|
1737
|
+
<div class='inline'><p>a frozen zero-Money</p></div>
|
|
1281
1738
|
|
|
1282
1739
|
</li>
|
|
1283
1740
|
|
|
@@ -1293,8 +1750,7 @@ smallest unit (e.g. cents). Must be an Integer to preserve exactness.</p></div>
|
|
|
1293
1750
|
|
|
1294
1751
|
|
|
1295
1752
|
—
|
|
1296
|
-
<div class='inline'><p>if
|
|
1297
|
-
is not registered</p></div>
|
|
1753
|
+
<div class='inline'><p>if the currency can't be resolved</p></div>
|
|
1298
1754
|
|
|
1299
1755
|
</li>
|
|
1300
1756
|
|
|
@@ -1306,28 +1762,12 @@ is not registered</p></div>
|
|
|
1306
1762
|
<pre class="lines">
|
|
1307
1763
|
|
|
1308
1764
|
|
|
1309
|
-
|
|
1310
|
-
38
|
|
1311
|
-
39
|
|
1312
|
-
40
|
|
1313
|
-
41
|
|
1314
|
-
42
|
|
1315
|
-
43
|
|
1316
|
-
44
|
|
1317
|
-
45</pre>
|
|
1765
|
+
53</pre>
|
|
1318
1766
|
</td>
|
|
1319
1767
|
<td>
|
|
1320
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
1321
|
-
|
|
1322
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_from_fractional'>from_fractional</span><span class='lparen'>(</span><span class='id identifier rubyid_fractional'>fractional</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
|
|
1323
|
-
<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'>fractional must be an Integer</span><span class='tstring_end'>'</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_fractional'>fractional</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Integer</span><span class='rparen'>)</span>
|
|
1324
|
-
|
|
1325
|
-
<span class='id identifier rubyid_checked_currency'>checked_currency</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency'><span class='object_link'><a href="../Mint.html#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>
|
|
1326
|
-
<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 not found (</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> <span class='kw'>unless</span> <span class='id identifier rubyid_checked_currency'>checked_currency</span>
|
|
1768
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 53</span>
|
|
1327
1769
|
|
|
1328
|
-
|
|
1329
|
-
<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_checked_currency'>checked_currency</span><span class='rparen'>)</span>
|
|
1330
|
-
<span class='kw'>end</span></pre>
|
|
1770
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_zero'>zero</span><span class='lparen'>(</span><span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Currency.html" title="Mint::Currency (class)">Currency</a></span></span><span class='period'>.</span><span class='id identifier rubyid_resolve!'><span class='object_link'><a href="Currency.html#resolve!-class_method" title="Mint::Currency.resolve! (method)">resolve!</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_zero'><span class='object_link'><a href="Currency.html#zero-class_method" title="Mint::Currency.zero (method)">zero</a></span></span></pre>
|
|
1331
1771
|
</td>
|
|
1332
1772
|
</tr>
|
|
1333
1773
|
</table>
|
|
@@ -1425,7 +1865,7 @@ is not registered</p></div>
|
|
|
1425
1865
|
<span class='kw'>def</span> <span class='op'>*</span><span class='lparen'>(</span><span class='id identifier rubyid_multiplicand'>multiplicand</span><span class='rparen'>)</span>
|
|
1426
1866
|
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'> can't be multiplied by </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_multiplicand'>multiplicand</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_multiplicand'>multiplicand</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Numeric</span><span class='rparen'>)</span>
|
|
1427
1867
|
|
|
1428
|
-
<span class='id identifier
|
|
1868
|
+
<span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span> <span class='op'>*</span> <span class='id identifier rubyid_multiplicand'>multiplicand</span><span class='rparen'>)</span>
|
|
1429
1869
|
<span class='kw'>end</span></pre>
|
|
1430
1870
|
</td>
|
|
1431
1871
|
</tr>
|
|
@@ -1513,7 +1953,7 @@ is not registered</p></div>
|
|
|
1513
1953
|
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 67</span>
|
|
1514
1954
|
|
|
1515
1955
|
<span class='kw'>def</span> <span class='op'>**</span><span class='lparen'>(</span><span class='id identifier rubyid_exponent'>exponent</span><span class='rparen'>)</span>
|
|
1516
|
-
<span class='kw'>return</span> <span class='id identifier
|
|
1956
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='op'>**</span><span class='id identifier rubyid_exponent'>exponent</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_exponent'>exponent</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Numeric</span><span class='rparen'>)</span>
|
|
1517
1957
|
|
|
1518
1958
|
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'> can't be powered by </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_exponent'>exponent</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
1519
1959
|
<span class='kw'>end</span></pre>
|
|
@@ -1610,7 +2050,7 @@ is not registered</p></div>
|
|
|
1610
2050
|
<span class='kw'>def</span> <span class='op'>+</span><span class='lparen'>(</span><span class='id identifier rubyid_addend'>addend</span><span class='rparen'>)</span>
|
|
1611
2051
|
<span class='kw'>case</span> <span class='id identifier rubyid_addend'>addend</span>
|
|
1612
2052
|
<span class='kw'>in</span> <span class='int'>0</span> <span class='kw'>then</span> <span class='kw'>self</span>
|
|
1613
|
-
<span class='kw'>in</span> <span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span> <span class='kw'>if</span> <span class='id identifier rubyid_same_currency?'>same_currency?</span><span class='lparen'>(</span><span class='id identifier rubyid_addend'>addend</span><span class='rparen'>)</span> <span class='kw'>then</span> <span class='id identifier
|
|
2053
|
+
<span class='kw'>in</span> <span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span> <span class='kw'>if</span> <span class='id identifier rubyid_same_currency?'>same_currency?</span><span class='lparen'>(</span><span class='id identifier rubyid_addend'>addend</span><span class='rparen'>)</span> <span class='kw'>then</span> <span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span> <span class='op'>+</span> <span class='id identifier rubyid_addend'>addend</span><span class='period'>.</span><span class='id identifier rubyid_amount'>amount</span><span class='rparen'>)</span>
|
|
1614
2054
|
<span class='kw'>else</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_addend'>addend</span><span class='embexpr_end'>}</span><span class='tstring_content'> can't be added to </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
1615
2055
|
<span class='kw'>end</span>
|
|
1616
2056
|
<span class='kw'>end</span></pre>
|
|
@@ -1707,7 +2147,7 @@ is not registered</p></div>
|
|
|
1707
2147
|
<span class='kw'>def</span> <span class='op'>-</span><span class='lparen'>(</span><span class='id identifier rubyid_subtrahend'>subtrahend</span><span class='rparen'>)</span>
|
|
1708
2148
|
<span class='kw'>case</span> <span class='id identifier rubyid_subtrahend'>subtrahend</span>
|
|
1709
2149
|
<span class='kw'>when</span> <span class='int'>0</span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='kw'>self</span>
|
|
1710
|
-
<span class='kw'>when</span> <span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier
|
|
2150
|
+
<span class='kw'>when</span> <span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span> <span class='op'>-</span> <span class='id identifier rubyid_subtrahend'>subtrahend</span><span class='period'>.</span><span class='id identifier rubyid_amount'>amount</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_same_currency?'>same_currency?</span><span class='lparen'>(</span><span class='id identifier rubyid_subtrahend'>subtrahend</span><span class='rparen'>)</span>
|
|
1711
2151
|
<span class='kw'>end</span>
|
|
1712
2152
|
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_subtrahend'>subtrahend</span><span class='embexpr_end'>}</span><span class='tstring_content'> can't be subtracted from </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
1713
2153
|
<span class='kw'>end</span></pre>
|
|
@@ -1761,7 +2201,7 @@ is not registered</p></div>
|
|
|
1761
2201
|
<td>
|
|
1762
2202
|
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 35</span>
|
|
1763
2203
|
|
|
1764
|
-
<span class='kw'>def</span> <span class='op'>-@</span> <span class='op'>=</span> <span class='id identifier
|
|
2204
|
+
<span class='kw'>def</span> <span class='op'>-@</span> <span class='op'>=</span> <span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='op'>-</span><span class='id identifier rubyid_amount'>amount</span><span class='rparen'>)</span></pre>
|
|
1765
2205
|
</td>
|
|
1766
2206
|
</tr>
|
|
1767
2207
|
</table>
|
|
@@ -1866,7 +2306,7 @@ is not registered</p></div>
|
|
|
1866
2306
|
|
|
1867
2307
|
<span class='kw'>def</span> <span class='op'>/</span><span class='lparen'>(</span><span class='id identifier rubyid_divisor'>divisor</span><span class='rparen'>)</span>
|
|
1868
2308
|
<span class='kw'>case</span> <span class='id identifier rubyid_divisor'>divisor</span>
|
|
1869
|
-
<span class='kw'>when</span> <span class='const'>Numeric</span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier
|
|
2309
|
+
<span class='kw'>when</span> <span class='const'>Numeric</span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span> <span class='op'>/</span> <span class='id identifier rubyid_divisor'>divisor</span><span class='rparen'>)</span>
|
|
1870
2310
|
<span class='kw'>when</span> <span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>/</span> <span class='id identifier rubyid_divisor'>divisor</span><span class='period'>.</span><span class='id identifier rubyid_amount'>amount</span> <span class='kw'>if</span> <span class='id identifier rubyid_same_currency?'>same_currency?</span> <span class='id identifier rubyid_divisor'>divisor</span>
|
|
1871
2311
|
<span class='kw'>end</span>
|
|
1872
2312
|
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_content'> can't be divided by </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_divisor'>divisor</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
@@ -2045,7 +2485,7 @@ two_usd > Mint.money(2, 'BRL')
|
|
|
2045
2485
|
<td>
|
|
2046
2486
|
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/methods.rb', line 9</span>
|
|
2047
2487
|
|
|
2048
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_abs'>abs</span> <span class='op'>=</span> <span class='id identifier
|
|
2488
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_abs'>abs</span> <span class='op'>=</span> <span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span><span class='rparen'>)</span></pre>
|
|
2049
2489
|
</td>
|
|
2050
2490
|
</tr>
|
|
2051
2491
|
</table>
|
|
@@ -2144,8 +2584,7 @@ Disperses any subunit rounding amounts across the initial slots</p>
|
|
|
2144
2584
|
19
|
|
2145
2585
|
20
|
|
2146
2586
|
21
|
|
2147
|
-
22
|
|
2148
|
-
23</pre>
|
|
2587
|
+
22</pre>
|
|
2149
2588
|
</td>
|
|
2150
2589
|
<td>
|
|
2151
2590
|
<pre class="code"><span class="info file"># File 'lib/minting/money/allocation/allocation.rb', line 15</span>
|
|
@@ -2155,13 +2594,113 @@ Disperses any subunit rounding amounts across the initial slots</p>
|
|
|
2155
2594
|
<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'>Need at least 1 proportion element</span><span class='tstring_end'>'</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_proportions'>proportions</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
|
2156
2595
|
<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'>Proportions total must not be zero</span><span class='tstring_end'>'</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_whole'>whole</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span>
|
|
2157
2596
|
|
|
2158
|
-
<span class='id identifier
|
|
2159
|
-
<span class='id identifier rubyid_amounts'>amounts</span> <span class='op'>=</span> <span class='id identifier rubyid_proportions'>proportions</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_rate'>rate</span><span class='op'>|</span> <span class='const'>Rational</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span> <span class='op'>*</span> <span class='id identifier rubyid_rate'>rate</span><span class='comma'>,</span> <span class='id identifier rubyid_whole'>whole</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_round'>round</span><span class='lparen'>(</span><span class='id identifier rubyid_subunit'>subunit</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
|
2597
|
+
<span class='id identifier rubyid_amounts'>amounts</span> <span class='op'>=</span> <span class='id identifier rubyid_proportions'>proportions</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_rate'>rate</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='const'>Rational</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span> <span class='op'>*</span> <span class='id identifier rubyid_rate'>rate</span><span class='comma'>,</span> <span class='id identifier rubyid_whole'>whole</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
|
2160
2598
|
<span class='id identifier rubyid_allocate_left_over'>allocate_left_over</span><span class='lparen'>(</span><span class='label'>amounts:</span> <span class='id identifier rubyid_amounts'>amounts</span><span class='comma'>,</span> <span class='label'>left_over:</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>-</span> <span class='id identifier rubyid_amounts'>amounts</span><span class='period'>.</span><span class='id identifier rubyid_sum'>sum</span><span class='rparen'>)</span>
|
|
2161
2599
|
<span class='kw'>end</span></pre>
|
|
2162
2600
|
</td>
|
|
2163
2601
|
</tr>
|
|
2164
2602
|
</table>
|
|
2603
|
+
</div>
|
|
2604
|
+
|
|
2605
|
+
<div class="method_details ">
|
|
2606
|
+
<h3 class="signature " id="change-instance_method">
|
|
2607
|
+
|
|
2608
|
+
#<strong>change</strong>(new_amount) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
2609
|
+
|
|
2610
|
+
|
|
2611
|
+
|
|
2612
|
+
|
|
2613
|
+
|
|
2614
|
+
</h3><div class="docstring">
|
|
2615
|
+
<div class="discussion">
|
|
2616
|
+
<p>Returns a new Money object with the specified amount, or self if unchanged.
|
|
2617
|
+
This is the primary method for creating a modified copy of a Money instance
|
|
2618
|
+
while preserving immutability.</p>
|
|
2619
|
+
|
|
2620
|
+
</div>
|
|
2621
|
+
</div>
|
|
2622
|
+
<div class="tags">
|
|
2623
|
+
|
|
2624
|
+
<div class="examples">
|
|
2625
|
+
<h4 class="tag_title">Examples:</h4>
|
|
2626
|
+
|
|
2627
|
+
|
|
2628
|
+
<pre class="example code"><code><span class='id identifier rubyid_price'>price</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="../Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>10.00</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>
|
|
2629
|
+
<span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='float'>15.00</span><span class='rparen'>)</span> <span class='comment'>#=> [USD 15.00]
|
|
2630
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='float'>10.00</span><span class='rparen'>)</span> <span class='comment'>#=> [USD 10.00] (returns self)</span></code></pre>
|
|
2631
|
+
|
|
2632
|
+
</div>
|
|
2633
|
+
<p class="tag_title">Parameters:</p>
|
|
2634
|
+
<ul class="param">
|
|
2635
|
+
|
|
2636
|
+
<li>
|
|
2637
|
+
|
|
2638
|
+
<span class='name'>new_amount</span>
|
|
2639
|
+
|
|
2640
|
+
|
|
2641
|
+
<span class='type'>(<tt>Numeric</tt>)</span>
|
|
2642
|
+
|
|
2643
|
+
|
|
2644
|
+
|
|
2645
|
+
—
|
|
2646
|
+
<div class='inline'><p>The new monetary amount</p></div>
|
|
2647
|
+
|
|
2648
|
+
</li>
|
|
2649
|
+
|
|
2650
|
+
</ul>
|
|
2651
|
+
|
|
2652
|
+
<p class="tag_title">Returns:</p>
|
|
2653
|
+
<ul class="return">
|
|
2654
|
+
|
|
2655
|
+
<li>
|
|
2656
|
+
|
|
2657
|
+
|
|
2658
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
2659
|
+
|
|
2660
|
+
|
|
2661
|
+
|
|
2662
|
+
—
|
|
2663
|
+
<div class='inline'><p>A new Money object with the new amount, or self if the amount is unchanged</p></div>
|
|
2664
|
+
|
|
2665
|
+
</li>
|
|
2666
|
+
|
|
2667
|
+
</ul>
|
|
2668
|
+
|
|
2669
|
+
</div><table class="source_code">
|
|
2670
|
+
<tr>
|
|
2671
|
+
<td>
|
|
2672
|
+
<pre class="lines">
|
|
2673
|
+
|
|
2674
|
+
|
|
2675
|
+
98
|
|
2676
|
+
99
|
|
2677
|
+
100
|
|
2678
|
+
101
|
|
2679
|
+
102
|
|
2680
|
+
103
|
|
2681
|
+
104
|
|
2682
|
+
105
|
|
2683
|
+
106
|
|
2684
|
+
107
|
|
2685
|
+
108</pre>
|
|
2686
|
+
</td>
|
|
2687
|
+
<td>
|
|
2688
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 98</span>
|
|
2689
|
+
|
|
2690
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_new_amount'>new_amount</span><span class='rparen'>)</span>
|
|
2691
|
+
<span class='id identifier rubyid_new_amount'>new_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_new_amount'>new_amount</span><span class='rparen'>)</span>
|
|
2692
|
+
|
|
2693
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_new_amount'>new_amount</span> <span class='op'>==</span> <span class='id identifier rubyid_amount'>amount</span>
|
|
2694
|
+
<span class='kw'>self</span>
|
|
2695
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_new_amount'>new_amount</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span>
|
|
2696
|
+
<span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_zero'>zero</span>
|
|
2697
|
+
<span class='kw'>else</span>
|
|
2698
|
+
<span class='const'><span class='object_link'><a href="" 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_new_amount'>new_amount</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
|
|
2699
|
+
<span class='kw'>end</span>
|
|
2700
|
+
<span class='kw'>end</span></pre>
|
|
2701
|
+
</td>
|
|
2702
|
+
</tr>
|
|
2703
|
+
</table>
|
|
2165
2704
|
</div>
|
|
2166
2705
|
|
|
2167
2706
|
<div class="method_details ">
|
|
@@ -2318,7 +2857,7 @@ if min is a Range, and max is not nil</p></div>
|
|
|
2318
2857
|
<span class='kw'>else</span>
|
|
2319
2858
|
<span class='id identifier rubyid_min'>min</span> <span class='op'>=</span> <span class='id identifier rubyid_min_or_range'>min_or_range</span>
|
|
2320
2859
|
<span class='kw'>end</span>
|
|
2321
|
-
<span class='id identifier
|
|
2860
|
+
<span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_clamp'>clamp</span><span class='lparen'>(</span><span class='id identifier rubyid_normalize_boundary'>normalize_boundary</span><span class='lparen'>(</span><span class='id identifier rubyid_min'>min</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_normalize_boundary'>normalize_boundary</span><span class='lparen'>(</span><span class='id identifier rubyid_max'>max</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
2322
2861
|
<span class='kw'>end</span></pre>
|
|
2323
2862
|
</td>
|
|
2324
2863
|
</tr>
|
|
@@ -2460,10 +2999,10 @@ This enables expressions like <code>5 * money</code> where <code>5</code> is a N
|
|
|
2460
2999
|
<pre class="lines">
|
|
2461
3000
|
|
|
2462
3001
|
|
|
2463
|
-
|
|
3002
|
+
29</pre>
|
|
2464
3003
|
</td>
|
|
2465
3004
|
<td>
|
|
2466
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
3005
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 29</span>
|
|
2467
3006
|
|
|
2468
3007
|
<span class='kw'>def</span> <span class='id identifier rubyid_currency_code'>currency_code</span> <span class='op'>=</span> <span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_code'>code</span></pre>
|
|
2469
3008
|
</td>
|
|
@@ -2579,10 +3118,10 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
2579
3118
|
<pre class="lines">
|
|
2580
3119
|
|
|
2581
3120
|
|
|
2582
|
-
|
|
3121
|
+
39</pre>
|
|
2583
3122
|
</td>
|
|
2584
3123
|
<td>
|
|
2585
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
3124
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 39</span>
|
|
2586
3125
|
|
|
2587
3126
|
<span class='kw'>def</span> <span class='id identifier rubyid_fractional'>fractional</span> <span class='op'>=</span> <span class='lparen'>(</span><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_fractional_multiplier'>fractional_multiplier</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span></pre>
|
|
2588
3127
|
</td>
|
|
@@ -2630,10 +3169,10 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
2630
3169
|
<pre class="lines">
|
|
2631
3170
|
|
|
2632
3171
|
|
|
2633
|
-
|
|
3172
|
+
44</pre>
|
|
2634
3173
|
</td>
|
|
2635
3174
|
<td>
|
|
2636
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
3175
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 44</span>
|
|
2637
3176
|
|
|
2638
3177
|
<span class='kw'>def</span> <span class='id identifier rubyid_hash'>hash</span> <span class='op'>=</span> <span class='lbracket'>[</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='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_hash'>hash</span></pre>
|
|
2639
3178
|
</td>
|
|
@@ -2681,12 +3220,12 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
2681
3220
|
<pre class="lines">
|
|
2682
3221
|
|
|
2683
3222
|
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
3223
|
+
49
|
|
3224
|
+
50
|
|
3225
|
+
51</pre>
|
|
2687
3226
|
</td>
|
|
2688
3227
|
<td>
|
|
2689
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
3228
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 49</span>
|
|
2690
3229
|
|
|
2691
3230
|
<span class='kw'>def</span> <span class='id identifier rubyid_inspect'>inspect</span>
|
|
2692
3231
|
<span class='const'>Kernel</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_currency_code'>currency_code</span><span class='embexpr_end'>}</span><span class='tstring_content'> %0.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_subunit'>subunit</span><span class='embexpr_end'>}</span><span class='tstring_content'>f]</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_amount'>amount</span>
|
|
@@ -2699,84 +3238,29 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
2699
3238
|
<div class="method_details ">
|
|
2700
3239
|
<h3 class="signature " id="mint-instance_method">
|
|
2701
3240
|
|
|
2702
|
-
#<strong>mint</strong>(new_amount) ⇒ <tt
|
|
3241
|
+
#<strong>mint</strong>(new_amount) ⇒ <tt>Object</tt>
|
|
2703
3242
|
|
|
2704
3243
|
|
|
2705
3244
|
|
|
2706
3245
|
|
|
2707
3246
|
|
|
2708
|
-
</h3><
|
|
2709
|
-
<div class="discussion">
|
|
2710
|
-
<p>Returns a new Money object with the specified amount, or self if unchanged.
|
|
2711
|
-
This is the primary method for creating a modified copy of a Money instance
|
|
2712
|
-
while preserving immutability.</p>
|
|
2713
|
-
|
|
2714
|
-
</div>
|
|
2715
|
-
</div>
|
|
2716
|
-
<div class="tags">
|
|
2717
|
-
|
|
2718
|
-
<div class="examples">
|
|
2719
|
-
<h4 class="tag_title">Examples:</h4>
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
<pre class="example code"><code><span class='id identifier rubyid_price'>price</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="../Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>10.00</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>
|
|
2723
|
-
<span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_mint'>mint</span><span class='lparen'>(</span><span class='float'>15.00</span><span class='rparen'>)</span> <span class='comment'>#=> [USD 15.00]
|
|
2724
|
-
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_mint'>mint</span><span class='lparen'>(</span><span class='float'>10.00</span><span class='rparen'>)</span> <span class='comment'>#=> [USD 10.00] (returns self)</span></code></pre>
|
|
2725
|
-
|
|
2726
|
-
</div>
|
|
2727
|
-
<p class="tag_title">Parameters:</p>
|
|
2728
|
-
<ul class="param">
|
|
2729
|
-
|
|
2730
|
-
<li>
|
|
2731
|
-
|
|
2732
|
-
<span class='name'>new_amount</span>
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
<span class='type'>(<tt>Numeric</tt>)</span>
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
—
|
|
2740
|
-
<div class='inline'><p>The new monetary amount</p></div>
|
|
2741
|
-
|
|
2742
|
-
</li>
|
|
2743
|
-
|
|
2744
|
-
</ul>
|
|
2745
|
-
|
|
2746
|
-
<p class="tag_title">Returns:</p>
|
|
2747
|
-
<ul class="return">
|
|
2748
|
-
|
|
2749
|
-
<li>
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
—
|
|
2757
|
-
<div class='inline'><p>A new Money object with the new amount, or self if the amount is unchanged</p></div>
|
|
2758
|
-
|
|
2759
|
-
</li>
|
|
2760
|
-
|
|
2761
|
-
</ul>
|
|
2762
|
-
|
|
2763
|
-
</div><table class="source_code">
|
|
3247
|
+
</h3><table class="source_code">
|
|
2764
3248
|
<tr>
|
|
2765
3249
|
<td>
|
|
2766
3250
|
<pre class="lines">
|
|
2767
3251
|
|
|
2768
3252
|
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
3253
|
+
110
|
|
3254
|
+
111
|
|
3255
|
+
112
|
|
3256
|
+
113</pre>
|
|
2773
3257
|
</td>
|
|
2774
3258
|
<td>
|
|
2775
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
3259
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 110</span>
|
|
2776
3260
|
|
|
2777
3261
|
<span class='kw'>def</span> <span class='id identifier rubyid_mint'>mint</span><span class='lparen'>(</span><span class='id identifier rubyid_new_amount'>new_amount</span><span class='rparen'>)</span>
|
|
2778
|
-
<span class='id identifier
|
|
2779
|
-
<span class='id identifier
|
|
3262
|
+
<span class='id identifier rubyid_warn'>warn</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Money#mint is now deprecated and will be removed in v2</span><span class='tstring_end'>'</span></span>
|
|
3263
|
+
<span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><span class='id identifier rubyid_new_amount'>new_amount</span><span class='rparen'>)</span>
|
|
2780
3264
|
<span class='kw'>end</span></pre>
|
|
2781
3265
|
</td>
|
|
2782
3266
|
</tr>
|
|
@@ -2947,7 +3431,7 @@ while preserving immutability.</p>
|
|
|
2947
3431
|
|
|
2948
3432
|
</h3><div class="docstring">
|
|
2949
3433
|
<div class="discussion">
|
|
2950
|
-
<p>Helper method to verify if another
|
|
3434
|
+
<p>Helper method to verify if another Money has the identical currency.</p>
|
|
2951
3435
|
|
|
2952
3436
|
</div>
|
|
2953
3437
|
</div>
|
|
@@ -2960,7 +3444,7 @@ while preserving immutability.</p>
|
|
|
2960
3444
|
<span class='name'>other</span>
|
|
2961
3445
|
|
|
2962
3446
|
|
|
2963
|
-
<span class='type'>(<tt><span class='object_link'><a href="
|
|
3447
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
2964
3448
|
|
|
2965
3449
|
|
|
2966
3450
|
|
|
@@ -2994,10 +3478,10 @@ while preserving immutability.</p>
|
|
|
2994
3478
|
<pre class="lines">
|
|
2995
3479
|
|
|
2996
3480
|
|
|
2997
|
-
|
|
3481
|
+
51</pre>
|
|
2998
3482
|
</td>
|
|
2999
3483
|
<td>
|
|
3000
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/
|
|
3484
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line 51</span>
|
|
3001
3485
|
|
|
3002
3486
|
<span class='kw'>def</span> <span class='id identifier rubyid_same_currency?'>same_currency?</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span> <span class='op'>=</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_currency'>currency</span> <span class='op'>==</span> <span class='id identifier rubyid_currency'>currency</span></pre>
|
|
3003
3487
|
</td>
|
|
@@ -3106,7 +3590,7 @@ so that the sum is preserved.</p>
|
|
|
3106
3590
|
<span class='kw'>def</span> <span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='id identifier rubyid_slices'>slices</span><span class='rparen'>)</span>
|
|
3107
3591
|
<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'>Slices quantity must be an poitive integer</span><span class='tstring_end'>'</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_slices'>slices</span><span class='period'>.</span><span class='id identifier rubyid_positive?'>positive?</span> <span class='op'>&&</span> <span class='id identifier rubyid_slices'>slices</span><span class='period'>.</span><span class='id identifier rubyid_integer?'>integer?</span>
|
|
3108
3592
|
|
|
3109
|
-
<span class='id identifier rubyid_fraction'>fraction</span> <span class='op'>=</span> <span class='
|
|
3593
|
+
<span class='id identifier rubyid_fraction'>fraction</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='op'>/</span> <span class='id identifier rubyid_slices'>slices</span><span class='rparen'>)</span>
|
|
3110
3594
|
<span class='id identifier rubyid_allocate_left_over'>allocate_left_over</span><span class='lparen'>(</span><span class='label'>amounts:</span> <span class='const'>Array</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_slices'>slices</span><span class='comma'>,</span> <span class='id identifier rubyid_fraction'>fraction</span><span class='rparen'>)</span><span class='comma'>,</span>
|
|
3111
3595
|
<span class='label'>left_over:</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>-</span> <span class='lparen'>(</span><span class='id identifier rubyid_fraction'>fraction</span> <span class='op'>*</span> <span class='id identifier rubyid_slices'>slices</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
3112
3596
|
<span class='kw'>end</span></pre>
|
|
@@ -3161,7 +3645,7 @@ Enables standard ranges and stepping (e.g. <code>1.dollar..10.dollars</code>).</
|
|
|
3161
3645
|
<td>
|
|
3162
3646
|
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/methods.rb', line 25</span>
|
|
3163
3647
|
|
|
3164
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_succ'>succ</span> <span class='op'>=</span> <span class='id identifier
|
|
3648
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_succ'>succ</span> <span class='op'>=</span> <span class='id identifier rubyid_change'>change</span><span class='lparen'>(</span><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_minimum_amount'>minimum_amount</span><span class='rparen'>)</span></pre>
|
|
3165
3649
|
</td>
|
|
3166
3650
|
</tr>
|
|
3167
3651
|
</table>
|
|
@@ -3596,7 +4080,7 @@ Highly optimized to run without external dependencies.</p>
|
|
|
3596
4080
|
<div class="method_details ">
|
|
3597
4081
|
<h3 class="signature " id="to_s-instance_method">
|
|
3598
4082
|
|
|
3599
|
-
#<strong>to_s</strong>(format:
|
|
4083
|
+
#<strong>to_s</strong>(format: nil, decimal: nil, thousand: nil, width: nil) ⇒ <tt>String</tt>
|
|
3600
4084
|
|
|
3601
4085
|
|
|
3602
4086
|
|
|
@@ -3642,6 +4126,11 @@ Highly optimized to run without external dependencies.</p>
|
|
|
3642
4126
|
<pre class="example code"><code><span class='id identifier rubyid_money'>money</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<amount>10.2f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> " 1234.56"
|
|
3643
4127
|
</span><span class='id identifier rubyid_money'>money</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<symbol>s%<amount>010.2f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "$0001234.56"</span></code></pre>
|
|
3644
4128
|
|
|
4129
|
+
|
|
4130
|
+
<h5 class="example_title"><div class='inline'><p>Locale-aware formatting (with Mint.locale_backend set)</p></div></h5>
|
|
4131
|
+
|
|
4132
|
+
<pre class="example code"><code><span class='id identifier rubyid_money'>money</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='comment'># decimal and thousand come from locale_backend</span></code></pre>
|
|
4133
|
+
|
|
3645
4134
|
</div>
|
|
3646
4135
|
<p class="tag_title">Parameters:</p>
|
|
3647
4136
|
<ul class="param">
|
|
@@ -3651,10 +4140,10 @@ Highly optimized to run without external dependencies.</p>
|
|
|
3651
4140
|
<span class='name'>format</span>
|
|
3652
4141
|
|
|
3653
4142
|
|
|
3654
|
-
<span class='type'>(<tt>String</tt>, <tt>Hash</tt>)</span>
|
|
4143
|
+
<span class='type'>(<tt>String</tt>, <tt>Hash</tt>, <tt>nil</tt>)</span>
|
|
3655
4144
|
|
|
3656
4145
|
|
|
3657
|
-
<em class="default">(defaults to: <tt
|
|
4146
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
3658
4147
|
|
|
3659
4148
|
|
|
3660
4149
|
—
|
|
@@ -3666,7 +4155,9 @@ is convenient for sign-aware formats such as accounting parentheses:</p>
|
|
|
3666
4155
|
</code></pre>
|
|
3667
4156
|
<p>Missing keys fall back to the module default, so a Hash with only
|
|
3668
4157
|
:negative will still format positives sensibly. The valid keys are
|
|
3669
|
-
:positive, :negative, :zero; anything else raises ArgumentError
|
|
4158
|
+
:positive, :negative, :zero; anything else raises ArgumentError.
|
|
4159
|
+
When <code>nil</code>, falls back to <code>Mint.locale_backend</code> if set, otherwise
|
|
4160
|
+
<code>"%<symbol>s%<amount>f"</code>.</p></div>
|
|
3670
4161
|
|
|
3671
4162
|
</li>
|
|
3672
4163
|
|
|
@@ -3675,14 +4166,15 @@ is convenient for sign-aware formats such as accounting parentheses:</p>
|
|
|
3675
4166
|
<span class='name'>thousand</span>
|
|
3676
4167
|
|
|
3677
4168
|
|
|
3678
|
-
<span class='type'>(<tt>String</tt>, <tt>false</tt>)</span>
|
|
4169
|
+
<span class='type'>(<tt>String</tt>, <tt>false</tt>, <tt>nil</tt>)</span>
|
|
3679
4170
|
|
|
3680
4171
|
|
|
3681
|
-
<em class="default">(defaults to: <tt
|
|
4172
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
3682
4173
|
|
|
3683
4174
|
|
|
3684
4175
|
—
|
|
3685
|
-
<div class='inline'><p>Thousands delimiter (e.g., ',' for 1,000)
|
|
4176
|
+
<div class='inline'><p>Thousands delimiter (e.g., ',' for 1,000).
|
|
4177
|
+
When <code>nil</code>, falls back to <code>Mint.locale_backend</code> if set, otherwise <code>","</code>.</p></div>
|
|
3686
4178
|
|
|
3687
4179
|
</li>
|
|
3688
4180
|
|
|
@@ -3691,14 +4183,15 @@ is convenient for sign-aware formats such as accounting parentheses:</p>
|
|
|
3691
4183
|
<span class='name'>decimal</span>
|
|
3692
4184
|
|
|
3693
4185
|
|
|
3694
|
-
<span class='type'>(<tt>String</tt>)</span>
|
|
4186
|
+
<span class='type'>(<tt>String</tt>, <tt>nil</tt>)</span>
|
|
3695
4187
|
|
|
3696
4188
|
|
|
3697
|
-
<em class="default">(defaults to: <tt
|
|
4189
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
3698
4190
|
|
|
3699
4191
|
|
|
3700
4192
|
—
|
|
3701
|
-
<div class='inline'><p>Decimal separator (e.g., '.' or ',')
|
|
4193
|
+
<div class='inline'><p>Decimal separator (e.g., '.' or ',').
|
|
4194
|
+
When <code>nil</code>, falls back to <code>Mint.locale_backend</code> if set, otherwise <code>"."</code>.</p></div>
|
|
3702
4195
|
|
|
3703
4196
|
</li>
|
|
3704
4197
|
|
|
@@ -3744,13 +4237,6 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3744
4237
|
<pre class="lines">
|
|
3745
4238
|
|
|
3746
4239
|
|
|
3747
|
-
46
|
|
3748
|
-
47
|
|
3749
|
-
48
|
|
3750
|
-
49
|
|
3751
|
-
50
|
|
3752
|
-
51
|
|
3753
|
-
52
|
|
3754
4240
|
53
|
|
3755
4241
|
54
|
|
3756
4242
|
55
|
|
@@ -3763,12 +4249,23 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3763
4249
|
62
|
|
3764
4250
|
63
|
|
3765
4251
|
64
|
|
3766
|
-
65
|
|
4252
|
+
65
|
|
4253
|
+
66
|
|
4254
|
+
67
|
|
4255
|
+
68
|
|
4256
|
+
69
|
|
4257
|
+
70
|
|
4258
|
+
71
|
|
4259
|
+
72
|
|
4260
|
+
73
|
|
4261
|
+
74</pre>
|
|
3767
4262
|
</td>
|
|
3768
4263
|
<td>
|
|
3769
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/format/to_s.rb', line
|
|
4264
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/format/to_s.rb', line 53</span>
|
|
4265
|
+
|
|
4266
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>decimal:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>thousand:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>width:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
4267
|
+
<span class='id identifier rubyid_format'>format</span><span class='comma'>,</span> <span class='id identifier rubyid_decimal'>decimal</span><span class='comma'>,</span> <span class='id identifier rubyid_thousand'>thousand</span> <span class='op'>=</span> <span class='id identifier rubyid_resolve_locale_for'>resolve_locale_for</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='comma'>,</span> <span class='id identifier rubyid_decimal'>decimal</span><span class='comma'>,</span> <span class='id identifier rubyid_thousand'>thousand</span><span class='rparen'>)</span>
|
|
3770
4268
|
|
|
3771
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<symbol>s%<amount>f</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>decimal:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>thousand:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>,</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>width:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
3772
4269
|
<span class='kw'>case</span> <span class='id identifier rubyid_format'>format</span>
|
|
3773
4270
|
<span class='kw'>when</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>'</span></span> <span class='kw'>then</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'>format must not be empty</span><span class='tstring_end'>'</span></span>
|
|
3774
4271
|
<span class='kw'>when</span> <span class='const'>Hash</span> <span class='kw'>then</span> <span class='id identifier rubyid_validate_format_hash'>validate_format_hash</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span>
|
|
@@ -3833,10 +4330,10 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3833
4330
|
<pre class="lines">
|
|
3834
4331
|
|
|
3835
4332
|
|
|
3836
|
-
|
|
4333
|
+
54</pre>
|
|
3837
4334
|
</td>
|
|
3838
4335
|
<td>
|
|
3839
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line
|
|
4336
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line 54</span>
|
|
3840
4337
|
|
|
3841
4338
|
<span class='kw'>def</span> <span class='id identifier rubyid_zero?'>zero?</span> <span class='op'>=</span> <span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span></pre>
|
|
3842
4339
|
</td>
|
|
@@ -3849,7 +4346,7 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3849
4346
|
</div>
|
|
3850
4347
|
|
|
3851
4348
|
<div id="footer">
|
|
3852
|
-
Generated on
|
|
4349
|
+
Generated on Tue Jun 16 20:22:19 2026 by
|
|
3853
4350
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
3854
4351
|
0.9.44 (ruby-4.0.5).
|
|
3855
4352
|
</div>
|