minting 1.7.0 → 1.7.2
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 +71 -118
- data/Rakefile +13 -1
- data/bin/bench_check +46 -0
- data/doc/Mint/Currency.html +178 -32
- data/doc/Mint/CurrencyRegistry.html +7 -7
- data/doc/Mint/Money.html +128 -125
- data/doc/Mint/RangeStepPatch.html +277 -0
- data/doc/Mint/UnknownCurrency.html +2 -2
- data/doc/Mint.html +47 -22
- data/doc/Minting.html +3 -3
- data/doc/_index.html +17 -2
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +86 -89
- data/doc/index.html +86 -89
- data/doc/method_list.html +29 -21
- data/doc/top-level-namespace.html +13 -5
- data/lib/minting/{mint/currency → currency}/currency.rb +8 -0
- data/lib/minting/{mint/currency → currency}/world_currencies.rb +1 -1
- data/lib/minting/mint/aliases.rb +3 -0
- data/lib/minting/mint/dsl/{refinements.rb → numeric.rb} +6 -5
- data/lib/minting/mint/dsl/range.rb +31 -18
- data/lib/minting/mint/dsl/string.rb +12 -0
- data/lib/minting/mint/dsl/top_level.rb +3 -0
- data/lib/minting/mint/mint.rb +16 -2
- data/lib/minting/mint/parser/parser.rb +66 -0
- data/lib/minting/mint/parser/separators.rb +39 -0
- data/lib/minting/mint.rb +17 -8
- data/lib/minting/money/allocation/allocation.rb +25 -0
- data/lib/minting/money/{allocation.rb → allocation/split.rb} +1 -19
- data/lib/minting/money/arithmetics/methods.rb +27 -0
- data/lib/minting/money/{arithmetics.rb → arithmetics/operators.rb} +0 -21
- data/lib/minting/money/clamp.rb +66 -0
- data/lib/minting/money/coercion.rb +10 -0
- data/lib/minting/money/comparable.rb +6 -0
- data/lib/minting/money/constructors.rb +13 -3
- data/lib/minting/money/format/formatting.rb +44 -0
- data/lib/minting/money/{formatting.rb → format/to_s.rb} +0 -32
- data/lib/minting/money/money.rb +0 -58
- data/lib/minting/version.rb +1 -1
- metadata +19 -14
- data/lib/minting/mint/parser.rb +0 -85
- /data/lib/minting/{mint/currency → currency}/currency_registry.rb +0 -0
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/money/
|
|
105
|
-
lib/minting/money/
|
|
104
|
+
<dd>lib/minting/money/clamp.rb<span class="defines">,<br>
|
|
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>
|
|
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>Money
|
|
114
|
+
<p>Money Arithmetics</p>
|
|
115
115
|
|
|
116
116
|
</div>
|
|
117
117
|
</div>
|
|
@@ -528,7 +528,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
528
528
|
|
|
529
529
|
|
|
530
530
|
|
|
531
|
-
|
|
531
|
+
<span class="private note title">private</span>
|
|
532
532
|
|
|
533
533
|
|
|
534
534
|
<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>
|
|
@@ -575,7 +575,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
575
575
|
|
|
576
576
|
|
|
577
577
|
|
|
578
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
|
578
|
+
<span class="summary_desc"><div class='inline'><p>Strict equality — both amount and currency must match exactly.</p></div></span>
|
|
579
579
|
|
|
580
580
|
</li>
|
|
581
581
|
|
|
@@ -693,7 +693,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
693
693
|
<li class="public ">
|
|
694
694
|
<span class="summary_signature">
|
|
695
695
|
|
|
696
|
-
<a href="#nonzero%3F-instance_method" title="#nonzero? (instance method)">#<strong>nonzero?</strong> ⇒
|
|
696
|
+
<a href="#nonzero%3F-instance_method" title="#nonzero? (instance method)">#<strong>nonzero?</strong> ⇒ self<sup>?</sup> </a>
|
|
697
697
|
|
|
698
698
|
|
|
699
699
|
|
|
@@ -707,7 +707,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
707
707
|
|
|
708
708
|
|
|
709
709
|
|
|
710
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
|
710
|
+
<span class="summary_desc"><div class='inline'><p>Self if amount is non-zero, nil otherwise.</p></div></span>
|
|
711
711
|
|
|
712
712
|
</li>
|
|
713
713
|
|
|
@@ -759,7 +759,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
759
759
|
<li class="public ">
|
|
760
760
|
<span class="summary_signature">
|
|
761
761
|
|
|
762
|
-
<a href="#split-instance_method" title="#split (instance method)">#<strong>split</strong>(
|
|
762
|
+
<a href="#split-instance_method" title="#split (instance method)">#<strong>split</strong>(slices) ⇒ Array<Money> </a>
|
|
763
763
|
|
|
764
764
|
|
|
765
765
|
|
|
@@ -993,7 +993,7 @@ Uses <code>%<symbol>s</code> for the currency symbol and <code>%<amount
|
|
|
993
993
|
|
|
994
994
|
|
|
995
995
|
|
|
996
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
|
996
|
+
<span class="summary_desc"><div class='inline'><p>True if amount is zero.</p></div></span>
|
|
997
997
|
|
|
998
998
|
</li>
|
|
999
999
|
|
|
@@ -1413,19 +1413,19 @@ is not registered</p></div>
|
|
|
1413
1413
|
<pre class="lines">
|
|
1414
1414
|
|
|
1415
1415
|
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1416
|
+
42
|
|
1417
|
+
43
|
|
1418
|
+
44
|
|
1419
|
+
45
|
|
1420
|
+
46</pre>
|
|
1421
1421
|
</td>
|
|
1422
1422
|
<td>
|
|
1423
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line
|
|
1423
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 42</span>
|
|
1424
1424
|
|
|
1425
1425
|
<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
|
-
<span class='
|
|
1426
|
+
<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
1427
|
|
|
1428
|
-
<span class='id identifier
|
|
1428
|
+
<span class='id identifier rubyid_mint'>mint</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
1429
|
<span class='kw'>end</span></pre>
|
|
1430
1430
|
</td>
|
|
1431
1431
|
</tr>
|
|
@@ -1503,14 +1503,14 @@ is not registered</p></div>
|
|
|
1503
1503
|
<pre class="lines">
|
|
1504
1504
|
|
|
1505
1505
|
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1506
|
+
67
|
|
1507
|
+
68
|
|
1508
|
+
69
|
|
1509
|
+
70
|
|
1510
|
+
71</pre>
|
|
1511
1511
|
</td>
|
|
1512
1512
|
<td>
|
|
1513
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line
|
|
1513
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 67</span>
|
|
1514
1514
|
|
|
1515
1515
|
<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
1516
|
<span class='kw'>return</span> <span class='id identifier rubyid_mint'>mint</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>
|
|
@@ -1596,23 +1596,23 @@ is not registered</p></div>
|
|
|
1596
1596
|
<pre class="lines">
|
|
1597
1597
|
|
|
1598
1598
|
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1599
|
+
11
|
|
1600
|
+
12
|
|
1601
|
+
13
|
|
1602
|
+
14
|
|
1603
|
+
15
|
|
1604
|
+
16
|
|
1605
|
+
17</pre>
|
|
1606
1606
|
</td>
|
|
1607
1607
|
<td>
|
|
1608
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line
|
|
1608
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 11</span>
|
|
1609
1609
|
|
|
1610
1610
|
<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
1611
|
<span class='kw'>case</span> <span class='id identifier rubyid_addend'>addend</span>
|
|
1612
|
-
<span class='kw'>
|
|
1613
|
-
<span class='kw'>
|
|
1612
|
+
<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 rubyid_mint'>mint</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
|
+
<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>
|
|
1614
1615
|
<span class='kw'>end</span>
|
|
1615
|
-
<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>
|
|
1616
1616
|
<span class='kw'>end</span></pre>
|
|
1617
1617
|
</td>
|
|
1618
1618
|
</tr>
|
|
@@ -1693,16 +1693,16 @@ is not registered</p></div>
|
|
|
1693
1693
|
<pre class="lines">
|
|
1694
1694
|
|
|
1695
1695
|
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1696
|
+
24
|
|
1697
|
+
25
|
|
1698
|
+
26
|
|
1699
|
+
27
|
|
1700
|
+
28
|
|
1701
|
+
29
|
|
1702
|
+
30</pre>
|
|
1703
1703
|
</td>
|
|
1704
1704
|
<td>
|
|
1705
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line
|
|
1705
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 24</span>
|
|
1706
1706
|
|
|
1707
1707
|
<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
1708
|
<span class='kw'>case</span> <span class='id identifier rubyid_subtrahend'>subtrahend</span>
|
|
@@ -1756,10 +1756,10 @@ is not registered</p></div>
|
|
|
1756
1756
|
<pre class="lines">
|
|
1757
1757
|
|
|
1758
1758
|
|
|
1759
|
-
|
|
1759
|
+
35</pre>
|
|
1760
1760
|
</td>
|
|
1761
1761
|
<td>
|
|
1762
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line
|
|
1762
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 35</span>
|
|
1763
1763
|
|
|
1764
1764
|
<span class='kw'>def</span> <span class='op'>-@</span> <span class='op'>=</span> <span class='id identifier rubyid_mint'>mint</span><span class='lparen'>(</span><span class='op'>-</span><span class='id identifier rubyid_amount'>amount</span><span class='rparen'>)</span></pre>
|
|
1765
1765
|
</td>
|
|
@@ -1853,16 +1853,16 @@ is not registered</p></div>
|
|
|
1853
1853
|
<pre class="lines">
|
|
1854
1854
|
|
|
1855
1855
|
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1856
|
+
54
|
|
1857
|
+
55
|
|
1858
|
+
56
|
|
1859
|
+
57
|
|
1860
|
+
58
|
|
1861
|
+
59
|
|
1862
|
+
60</pre>
|
|
1863
1863
|
</td>
|
|
1864
1864
|
<td>
|
|
1865
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line
|
|
1865
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/operators.rb', line 54</span>
|
|
1866
1866
|
|
|
1867
1867
|
<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
1868
|
<span class='kw'>case</span> <span class='id identifier rubyid_divisor'>divisor</span>
|
|
@@ -1914,16 +1914,16 @@ two_usd > Mint.money(2, 'BRL')
|
|
|
1914
1914
|
<pre class="lines">
|
|
1915
1915
|
|
|
1916
1916
|
|
|
1917
|
-
32
|
|
1918
|
-
33
|
|
1919
|
-
34
|
|
1920
|
-
35
|
|
1921
1917
|
36
|
|
1922
1918
|
37
|
|
1923
|
-
38
|
|
1919
|
+
38
|
|
1920
|
+
39
|
|
1921
|
+
40
|
|
1922
|
+
41
|
|
1923
|
+
42</pre>
|
|
1924
1924
|
</td>
|
|
1925
1925
|
<td>
|
|
1926
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line
|
|
1926
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line 36</span>
|
|
1927
1927
|
|
|
1928
1928
|
<span class='kw'>def</span> <span class='op'><=></span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
|
|
1929
1929
|
<span class='kw'>case</span> <span class='id identifier rubyid_other'>other</span>
|
|
@@ -2043,7 +2043,7 @@ two_usd > Mint.money(2, 'BRL')
|
|
|
2043
2043
|
9</pre>
|
|
2044
2044
|
</td>
|
|
2045
2045
|
<td>
|
|
2046
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line 9</span>
|
|
2046
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/methods.rb', line 9</span>
|
|
2047
2047
|
|
|
2048
2048
|
<span class='kw'>def</span> <span class='id identifier rubyid_abs'>abs</span> <span class='op'>=</span> <span class='id identifier rubyid_mint'>mint</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
2049
|
</td>
|
|
@@ -2148,7 +2148,7 @@ Disperses any subunit rounding amounts across the initial slots</p>
|
|
|
2148
2148
|
23</pre>
|
|
2149
2149
|
</td>
|
|
2150
2150
|
<td>
|
|
2151
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/allocation.rb', line 15</span>
|
|
2151
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/allocation/allocation.rb', line 15</span>
|
|
2152
2152
|
|
|
2153
2153
|
<span class='kw'>def</span> <span class='id identifier rubyid_allocate'>allocate</span><span class='lparen'>(</span><span class='id identifier rubyid_proportions'>proportions</span><span class='rparen'>)</span>
|
|
2154
2154
|
<span class='id identifier rubyid_whole'>whole</span> <span class='op'>=</span> <span class='id identifier rubyid_proportions'>proportions</span><span class='period'>.</span><span class='id identifier rubyid_sum'>sum</span><span class='period'>.</span><span class='id identifier rubyid_to_r'>to_r</span>
|
|
@@ -2157,7 +2157,7 @@ Disperses any subunit rounding amounts across the initial slots</p>
|
|
|
2157
2157
|
|
|
2158
2158
|
<span class='id identifier rubyid_subunit'>subunit</span> <span class='op'>=</span> <span class='id identifier rubyid_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_subunit'>subunit</span>
|
|
2159
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>
|
|
2160
|
-
<span class='id identifier rubyid_allocate_left_over
|
|
2160
|
+
<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
2161
|
<span class='kw'>end</span></pre>
|
|
2162
2162
|
</td>
|
|
2163
2163
|
</tr>
|
|
@@ -2296,19 +2296,19 @@ if min is a Range, and max is not nil</p></div>
|
|
|
2296
2296
|
<pre class="lines">
|
|
2297
2297
|
|
|
2298
2298
|
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2299
|
+
42
|
|
2300
|
+
43
|
|
2301
|
+
44
|
|
2302
|
+
45
|
|
2303
|
+
46
|
|
2304
|
+
47
|
|
2305
|
+
48
|
|
2306
|
+
49
|
|
2307
|
+
50
|
|
2308
|
+
51</pre>
|
|
2309
2309
|
</td>
|
|
2310
2310
|
<td>
|
|
2311
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/
|
|
2311
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/clamp.rb', line 42</span>
|
|
2312
2312
|
|
|
2313
2313
|
<span class='kw'>def</span> <span class='id identifier rubyid_clamp'>clamp</span><span class='lparen'>(</span><span class='id identifier rubyid_min_or_range'>min_or_range</span><span class='comma'>,</span> <span class='id identifier rubyid_max'>max</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
|
2314
2314
|
<span class='kw'>if</span> <span class='id identifier rubyid_min_or_range'>min_or_range</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Range</span><span class='rparen'>)</span>
|
|
@@ -2336,8 +2336,12 @@ if min is a Range, and max is not nil</p></div>
|
|
|
2336
2336
|
|
|
2337
2337
|
</h3><div class="docstring">
|
|
2338
2338
|
<div class="discussion">
|
|
2339
|
-
<p
|
|
2340
|
-
|
|
2339
|
+
<p class="note private">
|
|
2340
|
+
<strong>This method is part of a private API.</strong>
|
|
2341
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
2342
|
+
</p>
|
|
2343
|
+
<p>Allows <span class='object_link'><a href="" title="Mint::Money (class)">Mint::Money</a></span> to interact seamlessly as the right-hand operand in Numeric arithmetic.
|
|
2344
|
+
This enables expressions like <code>5 * money</code> where <code>5</code> is a Numeric and <code>money</code> is a Money object.</p>
|
|
2341
2345
|
|
|
2342
2346
|
</div>
|
|
2343
2347
|
</div>
|
|
@@ -2348,7 +2352,7 @@ This enables expressions like <code>5 + money</code> where <code>5</code> is a N
|
|
|
2348
2352
|
|
|
2349
2353
|
|
|
2350
2354
|
<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='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>
|
|
2351
|
-
<span class='int'>5</span> <span class='op'
|
|
2355
|
+
<span class='int'>5</span> <span class='op'>*</span> <span class='id identifier rubyid_price'>price</span> <span class='comment'>#=> [USD 50.00] (via coercion)</span></code></pre>
|
|
2352
2356
|
|
|
2353
2357
|
</div>
|
|
2354
2358
|
<p class="tag_title">Parameters:</p>
|
|
@@ -2478,7 +2482,8 @@ This enables expressions like <code>5 + money</code> where <code>5</code> is a N
|
|
|
2478
2482
|
|
|
2479
2483
|
</h3><div class="docstring">
|
|
2480
2484
|
<div class="discussion">
|
|
2481
|
-
|
|
2485
|
+
<p>Strict equality — both amount and currency must match exactly.
|
|
2486
|
+
Unlike ==, does not treat zero as equivalent across currencies.</p>
|
|
2482
2487
|
|
|
2483
2488
|
</div>
|
|
2484
2489
|
</div>
|
|
@@ -2504,14 +2509,14 @@ This enables expressions like <code>5 + money</code> where <code>5</code> is a N
|
|
|
2504
2509
|
<pre class="lines">
|
|
2505
2510
|
|
|
2506
2511
|
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
+
21
|
|
2513
|
+
22
|
|
2514
|
+
23
|
|
2515
|
+
24
|
|
2516
|
+
25</pre>
|
|
2512
2517
|
</td>
|
|
2513
2518
|
<td>
|
|
2514
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line
|
|
2519
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line 21</span>
|
|
2515
2520
|
|
|
2516
2521
|
<span class='kw'>def</span> <span class='id identifier rubyid_eql?'>eql?</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
|
|
2517
2522
|
<span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../Mint.html" title="Mint (module)">Mint</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span></span><span class='rparen'>)</span> <span class='op'>&&</span>
|
|
@@ -2821,7 +2826,7 @@ while preserving immutability.</p>
|
|
|
2821
2826
|
14</pre>
|
|
2822
2827
|
</td>
|
|
2823
2828
|
<td>
|
|
2824
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line 14</span>
|
|
2829
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/methods.rb', line 14</span>
|
|
2825
2830
|
|
|
2826
2831
|
<span class='kw'>def</span> <span class='id identifier rubyid_negative?'>negative?</span> <span class='op'>=</span> <span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_negative?'>negative?</span></pre>
|
|
2827
2832
|
</td>
|
|
@@ -2832,7 +2837,7 @@ while preserving immutability.</p>
|
|
|
2832
2837
|
<div class="method_details ">
|
|
2833
2838
|
<h3 class="signature " id="nonzero?-instance_method">
|
|
2834
2839
|
|
|
2835
|
-
#<strong>nonzero?</strong> ⇒ <tt>
|
|
2840
|
+
#<strong>nonzero?</strong> ⇒ <tt>self</tt><sup>?</sup>
|
|
2836
2841
|
|
|
2837
2842
|
|
|
2838
2843
|
|
|
@@ -2840,7 +2845,7 @@ while preserving immutability.</p>
|
|
|
2840
2845
|
|
|
2841
2846
|
</h3><div class="docstring">
|
|
2842
2847
|
<div class="discussion">
|
|
2843
|
-
|
|
2848
|
+
<p>Returns self if amount is non-zero, nil otherwise.</p>
|
|
2844
2849
|
|
|
2845
2850
|
</div>
|
|
2846
2851
|
</div>
|
|
@@ -2852,9 +2857,12 @@ while preserving immutability.</p>
|
|
|
2852
2857
|
<li>
|
|
2853
2858
|
|
|
2854
2859
|
|
|
2855
|
-
<span class='type'>(<tt>
|
|
2860
|
+
<span class='type'>(<tt>self</tt>, <tt>nil</tt>)</span>
|
|
2861
|
+
|
|
2856
2862
|
|
|
2857
2863
|
|
|
2864
|
+
—
|
|
2865
|
+
<div class='inline'><p>self if amount is non-zero, nil otherwise</p></div>
|
|
2858
2866
|
|
|
2859
2867
|
</li>
|
|
2860
2868
|
|
|
@@ -2866,10 +2874,10 @@ while preserving immutability.</p>
|
|
|
2866
2874
|
<pre class="lines">
|
|
2867
2875
|
|
|
2868
2876
|
|
|
2869
|
-
|
|
2877
|
+
45</pre>
|
|
2870
2878
|
</td>
|
|
2871
2879
|
<td>
|
|
2872
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line
|
|
2880
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line 45</span>
|
|
2873
2881
|
|
|
2874
2882
|
<span class='kw'>def</span> <span class='id identifier rubyid_nonzero?'>nonzero?</span> <span class='op'>=</span> <span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_nonzero?'>nonzero?</span></pre>
|
|
2875
2883
|
</td>
|
|
@@ -2920,7 +2928,7 @@ while preserving immutability.</p>
|
|
|
2920
2928
|
19</pre>
|
|
2921
2929
|
</td>
|
|
2922
2930
|
<td>
|
|
2923
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line 19</span>
|
|
2931
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/methods.rb', line 19</span>
|
|
2924
2932
|
|
|
2925
2933
|
<span class='kw'>def</span> <span class='id identifier rubyid_positive?'>positive?</span> <span class='op'>=</span> <span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_positive?'>positive?</span></pre>
|
|
2926
2934
|
</td>
|
|
@@ -3000,7 +3008,7 @@ while preserving immutability.</p>
|
|
|
3000
3008
|
<div class="method_details ">
|
|
3001
3009
|
<h3 class="signature " id="split-instance_method">
|
|
3002
3010
|
|
|
3003
|
-
#<strong>split</strong>(
|
|
3011
|
+
#<strong>split</strong>(slices) ⇒ <tt>Array<<span class='object_link'><a href="" title="Mint::Money (class)">Money</a></span>></tt>
|
|
3004
3012
|
|
|
3005
3013
|
|
|
3006
3014
|
|
|
@@ -3031,7 +3039,7 @@ so that the sum is preserved.</p>
|
|
|
3031
3039
|
|
|
3032
3040
|
<li>
|
|
3033
3041
|
|
|
3034
|
-
<span class='name'>
|
|
3042
|
+
<span class='name'>slices</span>
|
|
3035
3043
|
|
|
3036
3044
|
|
|
3037
3045
|
<span class='type'>(<tt>Integer</tt>)</span>
|
|
@@ -3084,29 +3092,23 @@ so that the sum is preserved.</p>
|
|
|
3084
3092
|
<pre class="lines">
|
|
3085
3093
|
|
|
3086
3094
|
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
43
|
|
3095
|
-
44
|
|
3096
|
-
45</pre>
|
|
3095
|
+
17
|
|
3096
|
+
18
|
|
3097
|
+
19
|
|
3098
|
+
20
|
|
3099
|
+
21
|
|
3100
|
+
22
|
|
3101
|
+
23</pre>
|
|
3097
3102
|
</td>
|
|
3098
3103
|
<td>
|
|
3099
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/allocation.rb', line
|
|
3104
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/allocation/split.rb', line 17</span>
|
|
3100
3105
|
|
|
3101
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='id identifier
|
|
3102
|
-
<span class='kw'>unless</span>
|
|
3103
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span>
|
|
3104
|
-
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>quantity must be an integer > 0</span><span class='tstring_end'>'</span></span>
|
|
3105
|
-
<span class='kw'>end</span>
|
|
3106
|
+
<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
|
+
<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>
|
|
3106
3108
|
|
|
3107
|
-
<span class='id identifier rubyid_fraction'>fraction</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
|
|
3108
|
-
<span class='id identifier rubyid_allocate_left_over
|
|
3109
|
-
|
|
3109
|
+
<span class='id identifier rubyid_fraction'>fraction</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_slices'>slices</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_currency'>currency</span><span class='period'>.</span><span class='id identifier rubyid_subunit'>subunit</span><span class='rparen'>)</span>
|
|
3110
|
+
<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
|
+
<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>
|
|
3110
3112
|
<span class='kw'>end</span></pre>
|
|
3111
3113
|
</td>
|
|
3112
3114
|
</tr>
|
|
@@ -3157,7 +3159,7 @@ Enables standard ranges and stepping (e.g. <code>1.dollar..10.dollars</code>).</
|
|
|
3157
3159
|
25</pre>
|
|
3158
3160
|
</td>
|
|
3159
3161
|
<td>
|
|
3160
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics.rb', line 25</span>
|
|
3162
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/arithmetics/methods.rb', line 25</span>
|
|
3161
3163
|
|
|
3162
3164
|
<span class='kw'>def</span> <span class='id identifier rubyid_succ'>succ</span> <span class='op'>=</span> <span class='id identifier rubyid_mint'>mint</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>
|
|
3163
3165
|
</td>
|
|
@@ -3761,18 +3763,17 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3761
3763
|
62
|
|
3762
3764
|
63
|
|
3763
3765
|
64
|
|
3764
|
-
65
|
|
3765
|
-
66</pre>
|
|
3766
|
+
65</pre>
|
|
3766
3767
|
</td>
|
|
3767
3768
|
<td>
|
|
3768
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/
|
|
3769
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/format/to_s.rb', line 46</span>
|
|
3769
3770
|
|
|
3770
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>
|
|
3771
3772
|
<span class='kw'>case</span> <span class='id identifier rubyid_format'>format</span>
|
|
3772
|
-
<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
|
|
3773
|
-
<span class='kw'>when</span> <span class='const'>Hash</span>
|
|
3774
|
-
<span class='kw'>when</span> <span class='const'>String</span> <span class='
|
|
3775
|
-
|
|
3773
|
+
<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
|
+
<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>
|
|
3775
|
+
<span class='kw'>when</span> <span class='const'>String</span> <span class='kw'>then</span> <span class='id identifier rubyid_format'>format</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>positive:</span> <span class='id identifier rubyid_format'>format</span> <span class='rbrace'>}</span>
|
|
3776
|
+
<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>
|
|
3776
3777
|
<span class='kw'>end</span>
|
|
3777
3778
|
|
|
3778
3779
|
<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>
|
|
@@ -3785,8 +3786,7 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3785
3786
|
</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>
|
|
3786
3787
|
<span class='kw'>end</span>
|
|
3787
3788
|
|
|
3788
|
-
<span class='id identifier
|
|
3789
|
-
<span class='id identifier rubyid_formatted'>formatted</span>
|
|
3789
|
+
<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>
|
|
3790
3790
|
<span class='kw'>end</span></pre>
|
|
3791
3791
|
</td>
|
|
3792
3792
|
</tr>
|
|
@@ -3804,7 +3804,7 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3804
3804
|
|
|
3805
3805
|
</h3><div class="docstring">
|
|
3806
3806
|
<div class="discussion">
|
|
3807
|
-
|
|
3807
|
+
<p>Returns true if amount is zero.</p>
|
|
3808
3808
|
|
|
3809
3809
|
</div>
|
|
3810
3810
|
</div>
|
|
@@ -3820,6 +3820,9 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3820
3820
|
|
|
3821
3821
|
|
|
3822
3822
|
|
|
3823
|
+
—
|
|
3824
|
+
<div class='inline'><p>true if amount is zero</p></div>
|
|
3825
|
+
|
|
3823
3826
|
</li>
|
|
3824
3827
|
|
|
3825
3828
|
</ul>
|
|
@@ -3830,10 +3833,10 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3830
3833
|
<pre class="lines">
|
|
3831
3834
|
|
|
3832
3835
|
|
|
3833
|
-
|
|
3836
|
+
48</pre>
|
|
3834
3837
|
</td>
|
|
3835
3838
|
<td>
|
|
3836
|
-
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line
|
|
3839
|
+
<pre class="code"><span class="info file"># File 'lib/minting/money/comparable.rb', line 48</span>
|
|
3837
3840
|
|
|
3838
3841
|
<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>
|
|
3839
3842
|
</td>
|
|
@@ -3846,9 +3849,9 @@ is empty, or the Hash contains an unrecognised key.</p></div>
|
|
|
3846
3849
|
</div>
|
|
3847
3850
|
|
|
3848
3851
|
<div id="footer">
|
|
3849
|
-
Generated on
|
|
3852
|
+
Generated on Sun Jun 14 21:57:01 2026 by
|
|
3850
3853
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
3851
|
-
0.9.44 (ruby-4.0.
|
|
3854
|
+
0.9.44 (ruby-4.0.5).
|
|
3852
3855
|
</div>
|
|
3853
3856
|
|
|
3854
3857
|
</div>
|