minting 1.8.2 → 1.9.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 +26 -9
- data/bin/bench_check +34 -9
- data/doc/Mint/Currency.html +66 -33
- data/doc/Mint/Money.html +491 -240
- data/doc/Mint/RangeStepPatch.html +1 -1
- data/doc/Mint/Registry.html +7 -3
- data/doc/Mint/Rounding.html +25 -14
- data/doc/Mint/UnknownCurrency.html +1 -1
- data/doc/Mint.html +18 -7
- data/doc/Minting.html +2 -2
- data/doc/_index.html +1 -1
- data/doc/file.README.html +27 -46
- data/doc/index.html +27 -46
- data/doc/method_list.html +51 -35
- data/doc/top-level-namespace.html +1 -1
- data/lib/minting/currency/currency.rb +6 -1
- data/lib/minting/mint/{locale_backend.rb → i18n.rb} +27 -0
- data/lib/minting/mint/mint.rb +10 -1
- data/lib/minting/mint/registry/zeros.rb +2 -0
- data/lib/minting/mint/rounding.rb +14 -1
- data/lib/minting/mint.rb +1 -2
- data/lib/minting/money/allocation/allocation.rb +1 -1
- data/lib/minting/money/allocation/split.rb +1 -1
- data/lib/minting/money/arithmetics/methods.rb +1 -1
- data/lib/minting/money/arithmetics/operators.rb +1 -1
- data/lib/minting/money/clamp.rb +2 -2
- data/lib/minting/money/coercion.rb +1 -1
- data/lib/minting/money/comparable.rb +1 -1
- data/lib/minting/money/constructors.rb +21 -11
- data/lib/minting/money/conversion.rb +1 -1
- data/lib/minting/money/format/formatting.rb +59 -29
- data/lib/minting/money/format/to_s.rb +44 -16
- data/lib/minting/money/money.rb +14 -5
- data/lib/minting/version.rb +1 -1
- metadata +2 -2
data/doc/Mint/Money.html
CHANGED
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
|
|
102
102
|
<dl>
|
|
103
103
|
<dt>Defined in:</dt>
|
|
104
|
-
<dd>lib/minting/
|
|
105
|
-
lib/minting/money/money.rb,<br> lib/minting/money/coercion.rb,<br> lib/minting/money/comparable.rb,<br> lib/minting/money/conversion.rb,<br> lib/minting/money/format/to_s.rb,<br> lib/minting/money/constructors.rb,<br> lib/minting/money/allocation/split.rb,<br> lib/minting/money/format/formatting.rb,<br> lib/minting/money/arithmetics/methods.rb,<br> lib/minting/money/allocation/allocation.rb,<br> lib/minting/money/arithmetics/operators.rb</span>
|
|
104
|
+
<dd>lib/minting/mint/i18n.rb<span class="defines">,<br>
|
|
105
|
+
lib/minting/money/clamp.rb,<br> lib/minting/money/money.rb,<br> lib/minting/money/coercion.rb,<br> lib/minting/money/comparable.rb,<br> lib/minting/money/conversion.rb,<br> lib/minting/money/format/to_s.rb,<br> lib/minting/money/constructors.rb,<br> lib/minting/money/allocation/split.rb,<br> lib/minting/money/format/formatting.rb,<br> lib/minting/money/arithmetics/methods.rb,<br> lib/minting/money/allocation/allocation.rb,<br> lib/minting/money/arithmetics/operators.rb</span>
|
|
106
106
|
|
|
107
107
|
</dd>
|
|
108
108
|
</dl>
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
|
|
112
112
|
<h2>Overview</h2><div class="docstring">
|
|
113
113
|
<div class="discussion">
|
|
114
|
-
<p
|
|
114
|
+
<p>:nodoc:</p>
|
|
115
115
|
|
|
116
116
|
</div>
|
|
117
117
|
</div>
|
|
@@ -243,7 +243,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
243
243
|
<li class="public ">
|
|
244
244
|
<span class="summary_signature">
|
|
245
245
|
|
|
246
|
-
<a href="#from-class_method" title="from (class method)">.<strong>from</strong>(amount, currency) ⇒
|
|
246
|
+
<a href="#from-class_method" title="from (class method)">.<strong>from</strong>(amount, currency) ⇒ Money </a>
|
|
247
247
|
|
|
248
248
|
|
|
249
249
|
|
|
@@ -265,7 +265,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
265
265
|
<li class="public ">
|
|
266
266
|
<span class="summary_signature">
|
|
267
267
|
|
|
268
|
-
<a href="#
|
|
268
|
+
<a href="#from_subunits-class_method" title="from_subunits (class method)">.<strong>from_subunits</strong>(subunits, currency) ⇒ Money </a>
|
|
269
269
|
|
|
270
270
|
|
|
271
271
|
|
|
@@ -279,7 +279,29 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
279
279
|
|
|
280
280
|
|
|
281
281
|
|
|
282
|
-
<span class="summary_desc"><div class='inline'><p>Builds a Money from a
|
|
282
|
+
<span class="summary_desc"><div class='inline'><p>Builds a Money from a subunit (smallest-unit) Integer amount.</p></div></span>
|
|
283
|
+
|
|
284
|
+
</li>
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
<li class="public ">
|
|
288
|
+
<span class="summary_signature">
|
|
289
|
+
|
|
290
|
+
<a href="#no_currency-class_method" title="no_currency (class method)">.<strong>no_currency</strong>(amount) ⇒ Money </a>
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
</span>
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
<span class="summary_desc"><div class='inline'><p>Creates a new Money without a currency (ISO 4217 XXX — "No Currency").</p></div></span>
|
|
283
305
|
|
|
284
306
|
</li>
|
|
285
307
|
|
|
@@ -583,7 +605,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
583
605
|
<li class="public ">
|
|
584
606
|
<span class="summary_signature">
|
|
585
607
|
|
|
586
|
-
<a href="#
|
|
608
|
+
<a href="#clamp-instance_method" title="#clamp (instance method)">#<strong>clamp</strong>(min_or_range, max = nil) ⇒ Money </a>
|
|
587
609
|
|
|
588
610
|
|
|
589
611
|
|
|
@@ -597,7 +619,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
597
619
|
|
|
598
620
|
|
|
599
621
|
|
|
600
|
-
<span class="summary_desc"><div class='inline'><p>
|
|
622
|
+
<span class="summary_desc"><div class='inline'><p>Constrains <code>self</code> to the inclusive range [+min+, +max+].</p></div></span>
|
|
601
623
|
|
|
602
624
|
</li>
|
|
603
625
|
|
|
@@ -605,7 +627,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
605
627
|
<li class="public ">
|
|
606
628
|
<span class="summary_signature">
|
|
607
629
|
|
|
608
|
-
<a href="#
|
|
630
|
+
<a href="#coerce-instance_method" title="#coerce (instance method)">#<strong>coerce</strong>(other) ⇒ Array(CoercedNumber, Money) </a>
|
|
609
631
|
|
|
610
632
|
|
|
611
633
|
|
|
@@ -616,10 +638,10 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
616
638
|
|
|
617
639
|
|
|
618
640
|
|
|
619
|
-
|
|
641
|
+
<span class="private note title">private</span>
|
|
620
642
|
|
|
621
643
|
|
|
622
|
-
<span class="summary_desc"><div class='inline'><p>
|
|
644
|
+
<span class="summary_desc"><div class='inline'><p>Allows <span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span> to interact seamlessly as the right-hand operand in Numeric arithmetic.</p></div></span>
|
|
623
645
|
|
|
624
646
|
</li>
|
|
625
647
|
|
|
@@ -627,7 +649,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
627
649
|
<li class="public ">
|
|
628
650
|
<span class="summary_signature">
|
|
629
651
|
|
|
630
|
-
<a href="#
|
|
652
|
+
<a href="#copy_with-instance_method" title="#copy_with (instance method)">#<strong>copy_with</strong>(amount:) ⇒ Money </a>
|
|
631
653
|
|
|
632
654
|
|
|
633
655
|
|
|
@@ -638,10 +660,10 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
638
660
|
|
|
639
661
|
|
|
640
662
|
|
|
641
|
-
|
|
663
|
+
|
|
642
664
|
|
|
643
665
|
|
|
644
|
-
<span class="summary_desc"><div class='inline'><p>
|
|
666
|
+
<span class="summary_desc"><div class='inline'><p>Returns a new Money object with the specified amount, or self if unchanged.</p></div></span>
|
|
645
667
|
|
|
646
668
|
</li>
|
|
647
669
|
|
|
@@ -693,7 +715,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
693
715
|
<li class="public ">
|
|
694
716
|
<span class="summary_signature">
|
|
695
717
|
|
|
696
|
-
<a href="#fractional-instance_method" title="#fractional (instance method)">#<strong>fractional</strong> ⇒
|
|
718
|
+
<a href="#fractional-instance_method" title="#fractional (instance method)">#<strong>fractional</strong> ⇒ Object </a>
|
|
697
719
|
|
|
698
720
|
|
|
699
721
|
|
|
@@ -707,7 +729,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
707
729
|
|
|
708
730
|
|
|
709
731
|
|
|
710
|
-
<span class="summary_desc"><div class='inline'><p>Returns the
|
|
732
|
+
<span class="summary_desc"><div class='inline'><p>Returns the fractional part of the amount.</p></div></span>
|
|
711
733
|
|
|
712
734
|
</li>
|
|
713
735
|
|
|
@@ -756,10 +778,10 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
756
778
|
</li>
|
|
757
779
|
|
|
758
780
|
|
|
759
|
-
<li class="public ">
|
|
781
|
+
<li class="public deprecated">
|
|
760
782
|
<span class="summary_signature">
|
|
761
783
|
|
|
762
|
-
<a href="#mint-instance_method" title="#mint (instance method)">#<strong>mint</strong>(new_amount) ⇒
|
|
784
|
+
<a href="#mint-instance_method" title="#mint (instance method)">#<strong>mint</strong>(new_amount) ⇒ Money </a>
|
|
763
785
|
|
|
764
786
|
|
|
765
787
|
|
|
@@ -769,11 +791,11 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
769
791
|
|
|
770
792
|
|
|
771
793
|
|
|
772
|
-
|
|
794
|
+
<span class="deprecated note title">deprecated</span>
|
|
773
795
|
|
|
774
796
|
|
|
775
797
|
|
|
776
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
|
798
|
+
<span class="summary_desc"><strong>Deprecated.</strong> <div class='inline'><p>Use <span class='object_link'><a href="#copy_with-instance_method" title="Mint::Money#copy_with (method)">#copy_with</a></span> instead. Will be removed in v2.</p></div></span>
|
|
777
799
|
|
|
778
800
|
</li>
|
|
779
801
|
|
|
@@ -891,6 +913,28 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
891
913
|
<li class="public ">
|
|
892
914
|
<span class="summary_signature">
|
|
893
915
|
|
|
916
|
+
<a href="#subunits-instance_method" title="#subunits (instance method)">#<strong>subunits</strong> ⇒ Integer </a>
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
</span>
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
<span class="summary_desc"><div class='inline'><p>Returns the monetary amount expressed in the currency's smallest unit (fractional units).</p></div></span>
|
|
931
|
+
|
|
932
|
+
</li>
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
<li class="public ">
|
|
936
|
+
<span class="summary_signature">
|
|
937
|
+
|
|
894
938
|
<a href="#succ-instance_method" title="#succ (instance method)">#<strong>succ</strong> ⇒ Money </a>
|
|
895
939
|
|
|
896
940
|
|
|
@@ -1143,12 +1187,12 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1143
1187
|
<pre class="lines">
|
|
1144
1188
|
|
|
1145
1189
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1190
|
+
24
|
|
1191
|
+
25
|
|
1192
|
+
26</pre>
|
|
1149
1193
|
</td>
|
|
1150
1194
|
<td>
|
|
1151
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
1195
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 24</span>
|
|
1152
1196
|
|
|
1153
1197
|
<span class='kw'>def</span> <span class='id identifier rubyid_amount'>amount</span>
|
|
1154
1198
|
<span class='ivar'>@amount</span>
|
|
@@ -1184,12 +1228,12 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
1184
1228
|
<pre class="lines">
|
|
1185
1229
|
|
|
1186
1230
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1231
|
+
24
|
|
1232
|
+
25
|
|
1233
|
+
26</pre>
|
|
1190
1234
|
</td>
|
|
1191
1235
|
<td>
|
|
1192
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
1236
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 24</span>
|
|
1193
1237
|
|
|
1194
1238
|
<span class='kw'>def</span> <span class='id identifier rubyid_currency'>currency</span>
|
|
1195
1239
|
<span class='ivar'>@currency</span>
|
|
@@ -1231,13 +1275,13 @@ TODO: deprecate in a future major release</p>
|
|
|
1231
1275
|
<pre class="lines">
|
|
1232
1276
|
|
|
1233
1277
|
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1278
|
+
69
|
|
1279
|
+
70
|
|
1280
|
+
71
|
|
1281
|
+
72</pre>
|
|
1238
1282
|
</td>
|
|
1239
1283
|
<td>
|
|
1240
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
1284
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 69</span>
|
|
1241
1285
|
|
|
1242
1286
|
<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
1287
|
<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>
|
|
@@ -1251,7 +1295,7 @@ TODO: deprecate in a future major release</p>
|
|
|
1251
1295
|
<div class="method_details ">
|
|
1252
1296
|
<h3 class="signature " id="from-class_method">
|
|
1253
1297
|
|
|
1254
|
-
.<strong>from</strong>(amount, currency) ⇒ <tt>
|
|
1298
|
+
.<strong>from</strong>(amount, currency) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
1255
1299
|
|
|
1256
1300
|
|
|
1257
1301
|
|
|
@@ -1264,7 +1308,15 @@ TODO: deprecate in a future major release</p>
|
|
|
1264
1308
|
</div>
|
|
1265
1309
|
</div>
|
|
1266
1310
|
<div class="tags">
|
|
1267
|
-
|
|
1311
|
+
|
|
1312
|
+
<div class="examples">
|
|
1313
|
+
<h4 class="tag_title">Examples:</h4>
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
<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'>from</span><span class='lparen'>(</span><span class='int'>10</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 10.00]</span></code></pre>
|
|
1317
|
+
|
|
1318
|
+
</div>
|
|
1319
|
+
<p class="tag_title">Parameters:</p>
|
|
1268
1320
|
<ul class="param">
|
|
1269
1321
|
|
|
1270
1322
|
<li>
|
|
@@ -1297,6 +1349,22 @@ TODO: deprecate in a future major release</p>
|
|
|
1297
1349
|
|
|
1298
1350
|
</ul>
|
|
1299
1351
|
|
|
1352
|
+
<p class="tag_title">Returns:</p>
|
|
1353
|
+
<ul class="return">
|
|
1354
|
+
|
|
1355
|
+
<li>
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
—
|
|
1363
|
+
<div class='inline'><p>the new Money instance</p></div>
|
|
1364
|
+
|
|
1365
|
+
</li>
|
|
1366
|
+
|
|
1367
|
+
</ul>
|
|
1300
1368
|
<p class="tag_title">Raises:</p>
|
|
1301
1369
|
<ul class="raise">
|
|
1302
1370
|
|
|
@@ -1320,17 +1388,17 @@ TODO: deprecate in a future major release</p>
|
|
|
1320
1388
|
<pre class="lines">
|
|
1321
1389
|
|
|
1322
1390
|
|
|
1323
|
-
10
|
|
1324
|
-
11
|
|
1325
|
-
12
|
|
1326
1391
|
13
|
|
1327
1392
|
14
|
|
1328
1393
|
15
|
|
1329
1394
|
16
|
|
1330
|
-
17
|
|
1395
|
+
17
|
|
1396
|
+
18
|
|
1397
|
+
19
|
|
1398
|
+
20</pre>
|
|
1331
1399
|
</td>
|
|
1332
1400
|
<td>
|
|
1333
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
1401
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 13</span>
|
|
1334
1402
|
|
|
1335
1403
|
<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
1404
|
<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>
|
|
@@ -1346,9 +1414,9 @@ TODO: deprecate in a future major release</p>
|
|
|
1346
1414
|
</div>
|
|
1347
1415
|
|
|
1348
1416
|
<div class="method_details ">
|
|
1349
|
-
<h3 class="signature " id="
|
|
1417
|
+
<h3 class="signature " id="from_subunits-class_method">
|
|
1350
1418
|
|
|
1351
|
-
.<strong>
|
|
1419
|
+
.<strong>from_subunits</strong>(subunits, currency) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
1352
1420
|
|
|
1353
1421
|
|
|
1354
1422
|
|
|
@@ -1356,8 +1424,8 @@ TODO: deprecate in a future major release</p>
|
|
|
1356
1424
|
|
|
1357
1425
|
</h3><div class="docstring">
|
|
1358
1426
|
<div class="discussion">
|
|
1359
|
-
<p>Builds a Money from a
|
|
1360
|
-
This is the inverse of <span class='object_link'><a href="#
|
|
1427
|
+
<p>Builds a Money from a subunit (smallest-unit) Integer amount.
|
|
1428
|
+
This is the inverse of <span class='object_link'><a href="#subunits-instance_method" title="Mint::Money#subunits (method)">#subunits</a></span>: for USD, the subunit is
|
|
1361
1429
|
1 cent; for JPY it is 1 yen; for IQD it is 1 dinar (subunit 3).</p>
|
|
1362
1430
|
|
|
1363
1431
|
</div>
|
|
@@ -1370,18 +1438,18 @@ This is the inverse of <span class='object_link'><a href="#fractional-instance_m
|
|
|
1370
1438
|
|
|
1371
1439
|
<h5 class="example_title"><div class='inline'><p>USD cents</p></div></h5>
|
|
1372
1440
|
|
|
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
|
|
1441
|
+
<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_subunits'>from_subunits</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
1442
|
|
|
1375
1443
|
|
|
1376
1444
|
<h5 class="example_title"><div class='inline'><p>JPY (subunit 0)</p></div></h5>
|
|
1377
1445
|
|
|
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
|
|
1446
|
+
<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_subunits'>from_subunits</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
1447
|
|
|
1380
1448
|
|
|
1381
1449
|
<h5 class="example_title"><div class='inline'><p>Round trip</p></div></h5>
|
|
1382
1450
|
|
|
1383
1451
|
<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
|
|
1452
|
+
<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_subunits'>from_subunits</span><span class='lparen'>(</span><span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_subunits'>subunits</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
1453
|
|
|
1386
1454
|
</div>
|
|
1387
1455
|
<p class="tag_title">Parameters:</p>
|
|
@@ -1389,7 +1457,7 @@ This is the inverse of <span class='object_link'><a href="#fractional-instance_m
|
|
|
1389
1457
|
|
|
1390
1458
|
<li>
|
|
1391
1459
|
|
|
1392
|
-
<span class='name'>
|
|
1460
|
+
<span class='name'>subunits</span>
|
|
1393
1461
|
|
|
1394
1462
|
|
|
1395
1463
|
<span class='type'>(<tt>Integer</tt>)</span>
|
|
@@ -1445,7 +1513,7 @@ smallest unit (e.g. cents). Must be an Integer to preserve exactness.</p></div>
|
|
|
1445
1513
|
|
|
1446
1514
|
|
|
1447
1515
|
—
|
|
1448
|
-
<div class='inline'><p>if <code>
|
|
1516
|
+
<div class='inline'><p>if <code>subunits</code> is not an Integer or <code>currency</code>
|
|
1449
1517
|
is not registered</p></div>
|
|
1450
1518
|
|
|
1451
1519
|
</li>
|
|
@@ -1458,27 +1526,120 @@ is not registered</p></div>
|
|
|
1458
1526
|
<pre class="lines">
|
|
1459
1527
|
|
|
1460
1528
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1529
|
+
92
|
|
1530
|
+
93
|
|
1531
|
+
94
|
|
1532
|
+
95
|
|
1533
|
+
96
|
|
1534
|
+
97
|
|
1535
|
+
98</pre>
|
|
1468
1536
|
</td>
|
|
1469
1537
|
<td>
|
|
1470
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
1538
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 92</span>
|
|
1471
1539
|
|
|
1472
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
|
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'>
|
|
1540
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_from_subunits'>from_subunits</span><span class='lparen'>(</span><span class='id identifier rubyid_subunits'>subunits</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
|
|
1541
|
+
<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'>subunits must be an Integer</span><span class='tstring_end'>'</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_subunits'>subunits</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
1542
|
|
|
1475
1543
|
<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
|
|
1544
|
+
<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_subunits'>subunits</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
1545
|
<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
1546
|
<span class='kw'>end</span></pre>
|
|
1479
1547
|
</td>
|
|
1480
1548
|
</tr>
|
|
1481
1549
|
</table>
|
|
1550
|
+
</div>
|
|
1551
|
+
|
|
1552
|
+
<div class="method_details ">
|
|
1553
|
+
<h3 class="signature " id="no_currency-class_method">
|
|
1554
|
+
|
|
1555
|
+
.<strong>no_currency</strong>(amount) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
</h3><div class="docstring">
|
|
1562
|
+
<div class="discussion">
|
|
1563
|
+
<p>Creates a new Money without a currency (ISO 4217 XXX — "No Currency").</p>
|
|
1564
|
+
|
|
1565
|
+
</div>
|
|
1566
|
+
</div>
|
|
1567
|
+
<div class="tags">
|
|
1568
|
+
|
|
1569
|
+
<div class="examples">
|
|
1570
|
+
<h4 class="tag_title">Examples:</h4>
|
|
1571
|
+
|
|
1572
|
+
|
|
1573
|
+
<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_no_currency'>no_currency</span><span class='lparen'>(</span><span class='int'>100</span><span class='rparen'>)</span> <span class='comment'>#=> [XXX 100]</span></code></pre>
|
|
1574
|
+
|
|
1575
|
+
</div>
|
|
1576
|
+
<p class="tag_title">Parameters:</p>
|
|
1577
|
+
<ul class="param">
|
|
1578
|
+
|
|
1579
|
+
<li>
|
|
1580
|
+
|
|
1581
|
+
<span class='name'>amount</span>
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
<span class='type'>(<tt>Numeric</tt>)</span>
|
|
1585
|
+
|
|
1586
|
+
|
|
1587
|
+
|
|
1588
|
+
—
|
|
1589
|
+
<div class='inline'><p>The monetary amount</p></div>
|
|
1590
|
+
|
|
1591
|
+
</li>
|
|
1592
|
+
|
|
1593
|
+
</ul>
|
|
1594
|
+
|
|
1595
|
+
<p class="tag_title">Returns:</p>
|
|
1596
|
+
<ul class="return">
|
|
1597
|
+
|
|
1598
|
+
<li>
|
|
1599
|
+
|
|
1600
|
+
|
|
1601
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
1602
|
+
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
—
|
|
1606
|
+
<div class='inline'><p>a Money instance with the XXX currency</p></div>
|
|
1607
|
+
|
|
1608
|
+
</li>
|
|
1609
|
+
|
|
1610
|
+
</ul>
|
|
1611
|
+
<p class="tag_title">Raises:</p>
|
|
1612
|
+
<ul class="raise">
|
|
1613
|
+
|
|
1614
|
+
<li>
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
|
1618
|
+
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
—
|
|
1622
|
+
<div class='inline'><p>If amount is not numeric</p></div>
|
|
1623
|
+
|
|
1624
|
+
</li>
|
|
1625
|
+
|
|
1626
|
+
</ul>
|
|
1627
|
+
|
|
1628
|
+
</div><table class="source_code">
|
|
1629
|
+
<tr>
|
|
1630
|
+
<td>
|
|
1631
|
+
<pre class="lines">
|
|
1632
|
+
|
|
1633
|
+
|
|
1634
|
+
29</pre>
|
|
1635
|
+
</td>
|
|
1636
|
+
<td>
|
|
1637
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 29</span>
|
|
1638
|
+
|
|
1639
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_no_currency'>no_currency</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='rparen'>)</span> <span class='op'>=</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='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>XXX</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span></pre>
|
|
1640
|
+
</td>
|
|
1641
|
+
</tr>
|
|
1642
|
+
</table>
|
|
1482
1643
|
</div>
|
|
1483
1644
|
|
|
1484
1645
|
<div class="method_details ">
|
|
@@ -1570,10 +1731,10 @@ is not registered</p></div>
|
|
|
1570
1731
|
<pre class="lines">
|
|
1571
1732
|
|
|
1572
1733
|
|
|
1573
|
-
|
|
1734
|
+
46</pre>
|
|
1574
1735
|
</td>
|
|
1575
1736
|
<td>
|
|
1576
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
1737
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 46</span>
|
|
1577
1738
|
|
|
1578
1739
|
<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
1740
|
</td>
|
|
@@ -1677,10 +1838,10 @@ is not registered</p></div>
|
|
|
1677
1838
|
<pre class="lines">
|
|
1678
1839
|
|
|
1679
1840
|
|
|
1680
|
-
|
|
1841
|
+
58</pre>
|
|
1681
1842
|
</td>
|
|
1682
1843
|
<td>
|
|
1683
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
1844
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 58</span>
|
|
1684
1845
|
|
|
1685
1846
|
<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>
|
|
1686
1847
|
</td>
|
|
@@ -1762,10 +1923,10 @@ is not registered</p></div>
|
|
|
1762
1923
|
<pre class="lines">
|
|
1763
1924
|
|
|
1764
1925
|
|
|
1765
|
-
|
|
1926
|
+
65</pre>
|
|
1766
1927
|
</td>
|
|
1767
1928
|
<td>
|
|
1768
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
1929
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 65</span>
|
|
1769
1930
|
|
|
1770
1931
|
<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>
|
|
1771
1932
|
</td>
|
|
@@ -1865,7 +2026,7 @@ is not registered</p></div>
|
|
|
1865
2026
|
<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>
|
|
1866
2027
|
<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>
|
|
1867
2028
|
|
|
1868
|
-
<span class='id identifier
|
|
2029
|
+
<span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</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>
|
|
1869
2030
|
<span class='kw'>end</span></pre>
|
|
1870
2031
|
</td>
|
|
1871
2032
|
</tr>
|
|
@@ -1953,7 +2114,7 @@ is not registered</p></div>
|
|
|
1953
2114
|
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 67</span>
|
|
1954
2115
|
|
|
1955
2116
|
<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>
|
|
1956
|
-
<span class='kw'>return</span> <span class='id identifier
|
|
2117
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</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>
|
|
1957
2118
|
|
|
1958
2119
|
<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>
|
|
1959
2120
|
<span class='kw'>end</span></pre>
|
|
@@ -2050,7 +2211,7 @@ is not registered</p></div>
|
|
|
2050
2211
|
<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>
|
|
2051
2212
|
<span class='kw'>case</span> <span class='id identifier rubyid_addend'>addend</span>
|
|
2052
2213
|
<span class='kw'>in</span> <span class='int'>0</span> <span class='kw'>then</span> <span class='kw'>self</span>
|
|
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
|
|
2214
|
+
<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_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</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>
|
|
2054
2215
|
<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>
|
|
2055
2216
|
<span class='kw'>end</span>
|
|
2056
2217
|
<span class='kw'>end</span></pre>
|
|
@@ -2147,7 +2308,7 @@ is not registered</p></div>
|
|
|
2147
2308
|
<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>
|
|
2148
2309
|
<span class='kw'>case</span> <span class='id identifier rubyid_subtrahend'>subtrahend</span>
|
|
2149
2310
|
<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>
|
|
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
|
|
2311
|
+
<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_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</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>
|
|
2151
2312
|
<span class='kw'>end</span>
|
|
2152
2313
|
<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>
|
|
2153
2314
|
<span class='kw'>end</span></pre>
|
|
@@ -2201,7 +2362,7 @@ is not registered</p></div>
|
|
|
2201
2362
|
<td>
|
|
2202
2363
|
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 35</span>
|
|
2203
2364
|
|
|
2204
|
-
<span class='kw'>def</span> <span class='op'>-@</span> <span class='op'>=</span> <span class='id identifier
|
|
2365
|
+
<span class='kw'>def</span> <span class='op'>-@</span> <span class='op'>=</span> <span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</span> <span class='op'>-</span><span class='id identifier rubyid_amount'>amount</span><span class='rparen'>)</span></pre>
|
|
2205
2366
|
</td>
|
|
2206
2367
|
</tr>
|
|
2207
2368
|
</table>
|
|
@@ -2306,7 +2467,7 @@ is not registered</p></div>
|
|
|
2306
2467
|
|
|
2307
2468
|
<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>
|
|
2308
2469
|
<span class='kw'>case</span> <span class='id identifier rubyid_divisor'>divisor</span>
|
|
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
|
|
2470
|
+
<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_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</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>
|
|
2310
2471
|
<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>
|
|
2311
2472
|
<span class='kw'>end</span>
|
|
2312
2473
|
<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>
|
|
@@ -2485,7 +2646,7 @@ two_usd > Mint.money(2, 'BRL')
|
|
|
2485
2646
|
<td>
|
|
2486
2647
|
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/methods.rb', line 9</span>
|
|
2487
2648
|
|
|
2488
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_abs'>abs</span> <span class='op'>=</span> <span class='id identifier
|
|
2649
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_abs'>abs</span> <span class='op'>=</span> <span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</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>
|
|
2489
2650
|
</td>
|
|
2490
2651
|
</tr>
|
|
2491
2652
|
</table>
|
|
@@ -2600,107 +2761,6 @@ Disperses any subunit rounding amounts across the initial slots</p>
|
|
|
2600
2761
|
</td>
|
|
2601
2762
|
</tr>
|
|
2602
2763
|
</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>
|
|
2704
2764
|
</div>
|
|
2705
2765
|
|
|
2706
2766
|
<div class="method_details ">
|
|
@@ -2857,7 +2917,7 @@ if min is a Range, and max is not nil</p></div>
|
|
|
2857
2917
|
<span class='kw'>else</span>
|
|
2858
2918
|
<span class='id identifier rubyid_min'>min</span> <span class='op'>=</span> <span class='id identifier rubyid_min_or_range'>min_or_range</span>
|
|
2859
2919
|
<span class='kw'>end</span>
|
|
2860
|
-
<span class='id identifier
|
|
2920
|
+
<span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</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>
|
|
2861
2921
|
<span class='kw'>end</span></pre>
|
|
2862
2922
|
</td>
|
|
2863
2923
|
</tr>
|
|
@@ -2949,6 +3009,107 @@ This enables expressions like <code>5 * money</code> where <code>5</code> is a N
|
|
|
2949
3009
|
</td>
|
|
2950
3010
|
</tr>
|
|
2951
3011
|
</table>
|
|
3012
|
+
</div>
|
|
3013
|
+
|
|
3014
|
+
<div class="method_details ">
|
|
3015
|
+
<h3 class="signature " id="copy_with-instance_method">
|
|
3016
|
+
|
|
3017
|
+
#<strong>copy_with</strong>(amount:) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
3018
|
+
|
|
3019
|
+
|
|
3020
|
+
|
|
3021
|
+
|
|
3022
|
+
|
|
3023
|
+
</h3><div class="docstring">
|
|
3024
|
+
<div class="discussion">
|
|
3025
|
+
<p>Returns a new Money object with the specified amount, or self if unchanged.
|
|
3026
|
+
This is the primary method for creating a modified copy of a Money instance
|
|
3027
|
+
while preserving immutability.</p>
|
|
3028
|
+
|
|
3029
|
+
</div>
|
|
3030
|
+
</div>
|
|
3031
|
+
<div class="tags">
|
|
3032
|
+
|
|
3033
|
+
<div class="examples">
|
|
3034
|
+
<h4 class="tag_title">Examples:</h4>
|
|
3035
|
+
|
|
3036
|
+
|
|
3037
|
+
<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>
|
|
3038
|
+
<span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</span> <span class='float'>15.00</span><span class='rparen'>)</span> <span class='comment'>#=> [USD 15.00]
|
|
3039
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</span> <span class='float'>10.00</span><span class='rparen'>)</span> <span class='comment'>#=> [USD 10.00] (returns self)</span></code></pre>
|
|
3040
|
+
|
|
3041
|
+
</div>
|
|
3042
|
+
<p class="tag_title">Parameters:</p>
|
|
3043
|
+
<ul class="param">
|
|
3044
|
+
|
|
3045
|
+
<li>
|
|
3046
|
+
|
|
3047
|
+
<span class='name'>amount</span>
|
|
3048
|
+
|
|
3049
|
+
|
|
3050
|
+
<span class='type'>(<tt>Numeric</tt>)</span>
|
|
3051
|
+
|
|
3052
|
+
|
|
3053
|
+
|
|
3054
|
+
—
|
|
3055
|
+
<div class='inline'><p>The new monetary amount</p></div>
|
|
3056
|
+
|
|
3057
|
+
</li>
|
|
3058
|
+
|
|
3059
|
+
</ul>
|
|
3060
|
+
|
|
3061
|
+
<p class="tag_title">Returns:</p>
|
|
3062
|
+
<ul class="return">
|
|
3063
|
+
|
|
3064
|
+
<li>
|
|
3065
|
+
|
|
3066
|
+
|
|
3067
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
3068
|
+
|
|
3069
|
+
|
|
3070
|
+
|
|
3071
|
+
—
|
|
3072
|
+
<div class='inline'><p>A new Money object with the new amount, or self if the amount is unchanged</p></div>
|
|
3073
|
+
|
|
3074
|
+
</li>
|
|
3075
|
+
|
|
3076
|
+
</ul>
|
|
3077
|
+
|
|
3078
|
+
</div><table class="source_code">
|
|
3079
|
+
<tr>
|
|
3080
|
+
<td>
|
|
3081
|
+
<pre class="lines">
|
|
3082
|
+
|
|
3083
|
+
|
|
3084
|
+
110
|
|
3085
|
+
111
|
|
3086
|
+
112
|
|
3087
|
+
113
|
|
3088
|
+
114
|
|
3089
|
+
115
|
|
3090
|
+
116
|
|
3091
|
+
117
|
|
3092
|
+
118
|
|
3093
|
+
119
|
|
3094
|
+
120</pre>
|
|
3095
|
+
</td>
|
|
3096
|
+
<td>
|
|
3097
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 110</span>
|
|
3098
|
+
|
|
3099
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</span><span class='rparen'>)</span>
|
|
3100
|
+
<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>
|
|
3101
|
+
|
|
3102
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>==</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_amount'>amount</span>
|
|
3103
|
+
<span class='kw'>self</span>
|
|
3104
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span>
|
|
3105
|
+
<span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_zero'>zero</span>
|
|
3106
|
+
<span class='kw'>else</span>
|
|
3107
|
+
<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_amount'>amount</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span>
|
|
3108
|
+
<span class='kw'>end</span>
|
|
3109
|
+
<span class='kw'>end</span></pre>
|
|
3110
|
+
</td>
|
|
3111
|
+
</tr>
|
|
3112
|
+
</table>
|
|
2952
3113
|
</div>
|
|
2953
3114
|
|
|
2954
3115
|
<div class="method_details ">
|
|
@@ -2999,10 +3160,10 @@ This enables expressions like <code>5 * money</code> where <code>5</code> is a N
|
|
|
2999
3160
|
<pre class="lines">
|
|
3000
3161
|
|
|
3001
3162
|
|
|
3002
|
-
|
|
3163
|
+
31</pre>
|
|
3003
3164
|
</td>
|
|
3004
3165
|
<td>
|
|
3005
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
3166
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 31</span>
|
|
3006
3167
|
|
|
3007
3168
|
<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>
|
|
3008
3169
|
</td>
|
|
@@ -3070,7 +3231,7 @@ Unlike ==, does not treat zero as equivalent across currencies.</p>
|
|
|
3070
3231
|
<div class="method_details ">
|
|
3071
3232
|
<h3 class="signature " id="fractional-instance_method">
|
|
3072
3233
|
|
|
3073
|
-
#<strong>fractional</strong> ⇒ <tt>
|
|
3234
|
+
#<strong>fractional</strong> ⇒ <tt>Object</tt>
|
|
3074
3235
|
|
|
3075
3236
|
|
|
3076
3237
|
|
|
@@ -3078,8 +3239,7 @@ Unlike ==, does not treat zero as equivalent across currencies.</p>
|
|
|
3078
3239
|
|
|
3079
3240
|
</h3><div class="docstring">
|
|
3080
3241
|
<div class="discussion">
|
|
3081
|
-
<p>Returns the
|
|
3082
|
-
For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (subunit 3).</p>
|
|
3242
|
+
<p>Returns the fractional part of the amount.</p>
|
|
3083
3243
|
|
|
3084
3244
|
</div>
|
|
3085
3245
|
</div>
|
|
@@ -3089,28 +3249,12 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
3089
3249
|
<h4 class="tag_title">Examples:</h4>
|
|
3090
3250
|
|
|
3091
3251
|
|
|
3092
|
-
<pre class="example code"><code><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'>1234.56</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='period'>.</span><span class='id identifier rubyid_fractional'>fractional</span> <span class='comment'>#=>
|
|
3093
|
-
</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='int'>1000</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='period'>.</span><span class='id identifier rubyid_fractional'>fractional</span> <span class='comment'>#=>
|
|
3094
|
-
</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'>123.456</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>IQD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_fractional'>fractional</span> <span class='comment'>#=>
|
|
3252
|
+
<pre class="example code"><code><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'>1234.56</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='period'>.</span><span class='id identifier rubyid_fractional'>fractional</span> <span class='comment'>#=> 56
|
|
3253
|
+
</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='int'>1000</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='period'>.</span><span class='id identifier rubyid_fractional'>fractional</span> <span class='comment'>#=> 0
|
|
3254
|
+
</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'>123.456</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>IQD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_fractional'>fractional</span> <span class='comment'>#=> 456</span></code></pre>
|
|
3095
3255
|
|
|
3096
3256
|
</div>
|
|
3097
3257
|
|
|
3098
|
-
<p class="tag_title">Returns:</p>
|
|
3099
|
-
<ul class="return">
|
|
3100
|
-
|
|
3101
|
-
<li>
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
<span class='type'>(<tt>Integer</tt>)</span>
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
—
|
|
3109
|
-
<div class='inline'><p>the amount in fractional units</p></div>
|
|
3110
|
-
|
|
3111
|
-
</li>
|
|
3112
|
-
|
|
3113
|
-
</ul>
|
|
3114
3258
|
|
|
3115
3259
|
</div><table class="source_code">
|
|
3116
3260
|
<tr>
|
|
@@ -3118,12 +3262,12 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
3118
3262
|
<pre class="lines">
|
|
3119
3263
|
|
|
3120
3264
|
|
|
3121
|
-
|
|
3265
|
+
48</pre>
|
|
3122
3266
|
</td>
|
|
3123
3267
|
<td>
|
|
3124
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
3268
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 48</span>
|
|
3125
3269
|
|
|
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>
|
|
3270
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_fractional'>fractional</span> <span class='op'>=</span> <span class='lparen'>(</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='op'>%</span> <span class='int'>1</span><span class='rparen'>)</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>
|
|
3127
3271
|
</td>
|
|
3128
3272
|
</tr>
|
|
3129
3273
|
</table>
|
|
@@ -3169,10 +3313,10 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
3169
3313
|
<pre class="lines">
|
|
3170
3314
|
|
|
3171
3315
|
|
|
3172
|
-
|
|
3316
|
+
53</pre>
|
|
3173
3317
|
</td>
|
|
3174
3318
|
<td>
|
|
3175
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
3319
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 53</span>
|
|
3176
3320
|
|
|
3177
3321
|
<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>
|
|
3178
3322
|
</td>
|
|
@@ -3220,12 +3364,12 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
3220
3364
|
<pre class="lines">
|
|
3221
3365
|
|
|
3222
3366
|
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3367
|
+
58
|
|
3368
|
+
59
|
|
3369
|
+
60</pre>
|
|
3226
3370
|
</td>
|
|
3227
3371
|
<td>
|
|
3228
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line
|
|
3372
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 58</span>
|
|
3229
3373
|
|
|
3230
3374
|
<span class='kw'>def</span> <span class='id identifier rubyid_inspect'>inspect</span>
|
|
3231
3375
|
<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>
|
|
@@ -3238,29 +3382,81 @@ For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (s
|
|
|
3238
3382
|
<div class="method_details ">
|
|
3239
3383
|
<h3 class="signature " id="mint-instance_method">
|
|
3240
3384
|
|
|
3241
|
-
#<strong>mint</strong>(new_amount) ⇒ <tt>
|
|
3385
|
+
#<strong>mint</strong>(new_amount) ⇒ <tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>
|
|
3242
3386
|
|
|
3243
3387
|
|
|
3244
3388
|
|
|
3245
3389
|
|
|
3246
3390
|
|
|
3247
|
-
</h3><
|
|
3391
|
+
</h3><div class="docstring">
|
|
3392
|
+
<div class="discussion">
|
|
3393
|
+
<div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'><p>Use <span class='object_link'><a href="#copy_with-instance_method" title="Mint::Money#copy_with (method)">#copy_with</a></span> instead. Will be removed in v2.</p></div></div>
|
|
3394
|
+
<p>Returns a new Money with the given amount in the same currency.</p>
|
|
3395
|
+
|
|
3396
|
+
</div>
|
|
3397
|
+
</div>
|
|
3398
|
+
<div class="tags">
|
|
3399
|
+
|
|
3400
|
+
<div class="examples">
|
|
3401
|
+
<h4 class="tag_title">Examples:</h4>
|
|
3402
|
+
|
|
3403
|
+
|
|
3404
|
+
<pre class="example code"><code><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='int'>10</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='period'>.</span><span class='id identifier rubyid_mint'>mint</span><span class='lparen'>(</span><span class='int'>15</span><span class='rparen'>)</span> <span class='comment'>#=> [USD 15.00]</span></code></pre>
|
|
3405
|
+
|
|
3406
|
+
</div>
|
|
3407
|
+
<p class="tag_title">Parameters:</p>
|
|
3408
|
+
<ul class="param">
|
|
3409
|
+
|
|
3410
|
+
<li>
|
|
3411
|
+
|
|
3412
|
+
<span class='name'>new_amount</span>
|
|
3413
|
+
|
|
3414
|
+
|
|
3415
|
+
<span class='type'>(<tt>Numeric</tt>)</span>
|
|
3416
|
+
|
|
3417
|
+
|
|
3418
|
+
|
|
3419
|
+
—
|
|
3420
|
+
<div class='inline'><p>the new monetary amount</p></div>
|
|
3421
|
+
|
|
3422
|
+
</li>
|
|
3423
|
+
|
|
3424
|
+
</ul>
|
|
3425
|
+
|
|
3426
|
+
<p class="tag_title">Returns:</p>
|
|
3427
|
+
<ul class="return">
|
|
3428
|
+
|
|
3429
|
+
<li>
|
|
3430
|
+
|
|
3431
|
+
|
|
3432
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></tt>)</span>
|
|
3433
|
+
|
|
3434
|
+
|
|
3435
|
+
|
|
3436
|
+
—
|
|
3437
|
+
<div class='inline'><p>a new Money instance, or self if unchanged</p></div>
|
|
3438
|
+
|
|
3439
|
+
</li>
|
|
3440
|
+
|
|
3441
|
+
</ul>
|
|
3442
|
+
|
|
3443
|
+
</div><table class="source_code">
|
|
3248
3444
|
<tr>
|
|
3249
3445
|
<td>
|
|
3250
3446
|
<pre class="lines">
|
|
3251
3447
|
|
|
3252
3448
|
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3449
|
+
129
|
|
3450
|
+
130
|
|
3451
|
+
131
|
|
3452
|
+
132</pre>
|
|
3257
3453
|
</td>
|
|
3258
3454
|
<td>
|
|
3259
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line
|
|
3455
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/constructors.rb', line 129</span>
|
|
3260
3456
|
|
|
3261
3457
|
<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>
|
|
3262
3458
|
<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
|
|
3459
|
+
<span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</span> <span class='id identifier rubyid_new_amount'>new_amount</span><span class='rparen'>)</span>
|
|
3264
3460
|
<span class='kw'>end</span></pre>
|
|
3265
3461
|
</td>
|
|
3266
3462
|
</tr>
|
|
@@ -3597,6 +3793,68 @@ so that the sum is preserved.</p>
|
|
|
3597
3793
|
</td>
|
|
3598
3794
|
</tr>
|
|
3599
3795
|
</table>
|
|
3796
|
+
</div>
|
|
3797
|
+
|
|
3798
|
+
<div class="method_details ">
|
|
3799
|
+
<h3 class="signature " id="subunits-instance_method">
|
|
3800
|
+
|
|
3801
|
+
#<strong>subunits</strong> ⇒ <tt>Integer</tt>
|
|
3802
|
+
|
|
3803
|
+
|
|
3804
|
+
|
|
3805
|
+
|
|
3806
|
+
|
|
3807
|
+
</h3><div class="docstring">
|
|
3808
|
+
<div class="discussion">
|
|
3809
|
+
<p>Returns the monetary amount expressed in the currency's smallest unit (fractional units).
|
|
3810
|
+
For example, cents for USD (subunit 2), yen for JPY (subunit 0), fils for IQD (subunit 3).</p>
|
|
3811
|
+
|
|
3812
|
+
</div>
|
|
3813
|
+
</div>
|
|
3814
|
+
<div class="tags">
|
|
3815
|
+
|
|
3816
|
+
<div class="examples">
|
|
3817
|
+
<h4 class="tag_title">Examples:</h4>
|
|
3818
|
+
|
|
3819
|
+
|
|
3820
|
+
<pre class="example code"><code><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'>1234.56</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='period'>.</span><span class='id identifier rubyid_subunits'>subunits</span> <span class='comment'>#=> 123456
|
|
3821
|
+
</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='int'>1000</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='period'>.</span><span class='id identifier rubyid_subunits'>subunits</span> <span class='comment'>#=> 1000
|
|
3822
|
+
</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'>123.456</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>IQD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_subunits'>subunits</span> <span class='comment'>#=> 123456</span></code></pre>
|
|
3823
|
+
|
|
3824
|
+
</div>
|
|
3825
|
+
|
|
3826
|
+
<p class="tag_title">Returns:</p>
|
|
3827
|
+
<ul class="return">
|
|
3828
|
+
|
|
3829
|
+
<li>
|
|
3830
|
+
|
|
3831
|
+
|
|
3832
|
+
<span class='type'>(<tt>Integer</tt>)</span>
|
|
3833
|
+
|
|
3834
|
+
|
|
3835
|
+
|
|
3836
|
+
—
|
|
3837
|
+
<div class='inline'><p>the amount in fractional units</p></div>
|
|
3838
|
+
|
|
3839
|
+
</li>
|
|
3840
|
+
|
|
3841
|
+
</ul>
|
|
3842
|
+
|
|
3843
|
+
</div><table class="source_code">
|
|
3844
|
+
<tr>
|
|
3845
|
+
<td>
|
|
3846
|
+
<pre class="lines">
|
|
3847
|
+
|
|
3848
|
+
|
|
3849
|
+
41</pre>
|
|
3850
|
+
</td>
|
|
3851
|
+
<td>
|
|
3852
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/money.rb', line 41</span>
|
|
3853
|
+
|
|
3854
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_subunits'>subunits</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>
|
|
3855
|
+
</td>
|
|
3856
|
+
</tr>
|
|
3857
|
+
</table>
|
|
3600
3858
|
</div>
|
|
3601
3859
|
|
|
3602
3860
|
<div class="method_details ">
|
|
@@ -3645,7 +3903,7 @@ Enables standard ranges and stepping (e.g. <code>1.dollar..10.dollars</code>).</
|
|
|
3645
3903
|
<td>
|
|
3646
3904
|
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/methods.rb', line 25</span>
|
|
3647
3905
|
|
|
3648
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_succ'>succ</span> <span class='op'>=</span> <span class='id identifier
|
|
3906
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_succ'>succ</span> <span class='op'>=</span> <span class='id identifier rubyid_copy_with'>copy_with</span><span class='lparen'>(</span><span class='label'>amount:</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>
|
|
3649
3907
|
</td>
|
|
3650
3908
|
</tr>
|
|
3651
3909
|
</table>
|
|
@@ -4114,6 +4372,14 @@ Highly optimized to run without external dependencies.</p>
|
|
|
4114
4372
|
</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>+f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "$+1234.56"</span></code></pre>
|
|
4115
4373
|
|
|
4116
4374
|
|
|
4375
|
+
<h5 class="example_title"><div class='inline'><p>Integral & fractional parts</p></div></h5>
|
|
4376
|
+
|
|
4377
|
+
<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'>%<integral>d.%<fractional>02d</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "1234.56"
|
|
4378
|
+
</span><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'>0.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>
|
|
4379
|
+
<span class='id identifier rubyid_price'>price</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'>%<integral>d dollars and %<fractional>02d cents</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
4380
|
+
<span class='comment'>#=> "0 dollars and 99 cents"</span></code></pre>
|
|
4381
|
+
|
|
4382
|
+
|
|
4117
4383
|
<h5 class="example_title"><div class='inline'><p>Per-sign Hash format (accounting parentheses)</p></div></h5>
|
|
4118
4384
|
|
|
4119
4385
|
<pre class="example code"><code><span class='id identifier rubyid_loss'>loss</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='op'>-</span><span class='float'>1234.56</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>
|
|
@@ -4148,9 +4414,10 @@ Highly optimized to run without external dependencies.</p>
|
|
|
4148
4414
|
|
|
4149
4415
|
—
|
|
4150
4416
|
<div class='inline'><p>Either a Format string with placeholders
|
|
4151
|
-
(%<symbol>s, %<amount>f, %<currency>s
|
|
4152
|
-
(:positive, :negative, :zero) each
|
|
4153
|
-
is convenient for sign-aware formats
|
|
4417
|
+
(%<symbol>s, %<amount>f, %<currency>s, %<integral>d, %<fractional>d),
|
|
4418
|
+
or a Hash with per-sign keys (:positive, :negative, :zero) each
|
|
4419
|
+
holding a format string. A Hash is convenient for sign-aware formats
|
|
4420
|
+
such as accounting parentheses:</p>
|
|
4154
4421
|
<pre class="code ruby"><code class="ruby"><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='lbrace'>{</span> <span class='label'>negative:</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='rbrace'>}</span><span class='rparen'>)</span>
|
|
4155
4422
|
</code></pre>
|
|
4156
4423
|
<p>Missing keys fall back to the module default, so a Hash with only
|
|
@@ -4237,13 +4504,6 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
4237
4504
|
<pre class="lines">
|
|
4238
4505
|
|
|
4239
4506
|
|
|
4240
|
-
53
|
|
4241
|
-
54
|
|
4242
|
-
55
|
|
4243
|
-
56
|
|
4244
|
-
57
|
|
4245
|
-
58
|
|
4246
|
-
59
|
|
4247
4507
|
60
|
|
4248
4508
|
61
|
|
4249
4509
|
62
|
|
@@ -4257,11 +4517,10 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
4257
4517
|
70
|
|
4258
4518
|
71
|
|
4259
4519
|
72
|
|
4260
|
-
73
|
|
4261
|
-
74</pre>
|
|
4520
|
+
73</pre>
|
|
4262
4521
|
</td>
|
|
4263
4522
|
<td>
|
|
4264
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/format/to_s.rb', line
|
|
4523
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/format/to_s.rb', line 60</span>
|
|
4265
4524
|
|
|
4266
4525
|
<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
4526
|
<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>
|
|
@@ -4273,15 +4532,7 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
4273
4532
|
<span class='kw'>else</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Invalid format. Only String or Hash are accepted</span><span class='tstring_end'>'</span></span>
|
|
4274
4533
|
<span class='kw'>end</span>
|
|
4275
4534
|
|
|
4276
|
-
<span class='id identifier rubyid_formatted'>formatted</span> <span class='op'>=</span> <span class='id identifier rubyid_format_amount'>format_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span>
|
|
4277
|
-
|
|
4278
|
-
<span class='id identifier rubyid_formatted'>formatted</span><span class='period'>.</span><span class='id identifier rubyid_tr!'>tr!</span><span class='lparen'>(</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='id identifier rubyid_decimal'>decimal</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_decimal'>decimal</span> <span class='op'>!=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span>
|
|
4279
|
-
|
|
4280
|
-
<span class='kw'>unless</span> <span class='id identifier rubyid_thousand'>thousand</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
|
4281
|
-
<span class='comment'># Regular expression courtesy of Money gem
|
|
4282
|
-
</span> <span class='comment'># Matches digits followed by groups of 3 digits until non-digit or end
|
|
4283
|
-
</span> <span class='id identifier rubyid_formatted'>formatted</span><span class='period'>.</span><span class='id identifier rubyid_gsub!'>gsub!</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(\d)(?=(?:\d{3})+(?:[^\d]{1}|$))</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\\1</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_thousand'>thousand</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
4284
|
-
<span class='kw'>end</span>
|
|
4535
|
+
<span class='id identifier rubyid_formatted'>formatted</span> <span class='op'>=</span> <span class='id identifier rubyid_format_amount'>format_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='comma'>,</span> <span class='label'>decimal:</span> <span class='id identifier rubyid_decimal'>decimal</span><span class='comma'>,</span> <span class='label'>thousand:</span> <span class='id identifier rubyid_thousand'>thousand</span><span class='rparen'>)</span>
|
|
4285
4536
|
|
|
4286
4537
|
<span class='id identifier rubyid_width'>width</span> <span class='op'>?</span> <span class='id identifier rubyid_formatted'>formatted</span><span class='period'>.</span><span class='id identifier rubyid_rjust'>rjust</span><span class='lparen'>(</span><span class='id identifier rubyid_width'>width</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_formatted'>formatted</span>
|
|
4287
4538
|
<span class='kw'>end</span></pre>
|
|
@@ -4346,7 +4597,7 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
4346
4597
|
</div>
|
|
4347
4598
|
|
|
4348
4599
|
<div id="footer">
|
|
4349
|
-
Generated on
|
|
4600
|
+
Generated on Mon Jun 22 16:47:02 2026 by
|
|
4350
4601
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
4351
4602
|
0.9.44 (ruby-4.0.5).
|
|
4352
4603
|
</div>
|