minting 1.0.1 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2e9f992fc49846276b49db3b06639ed38a2037dceb3762ffac27d1bc03b4d37
4
- data.tar.gz: 12fdb933a6cd61b2fa2dc61455ac3932f71fdd7822dd04261d5b0b8ec0fa4ba8
3
+ metadata.gz: ef2574a0bffcbccb882faba1a839ef37369e047b23becf1ce405d2c1b883322a
4
+ data.tar.gz: 19ec197c01ceb083a2f6dcf2c6898b38f80ba7679749154b74b3d9fb2f2ffeda
5
5
  SHA512:
6
- metadata.gz: 3013fca2971566d9503f2375aa1330f191e3467cdd2c442d92a83cd5b493e2778a7ef97dfc6248166af9be4002990a31eb2cbd3df38dcd1508407e12829d2515
7
- data.tar.gz: ff7261f4c1fd93586833feb391fd8c95c90a1c1de7f6d5410a4ba406d40f4fcb536684e01ecbd725c87a1c9ef53caa29371a17bf05a6fc7d65320f5c255bb39b
6
+ metadata.gz: e8680da52ba5417cbe89f2c36615247fa1cc7302088c7d087aa782b6d1958bcd124a38f2b1027cd164810f9f04b02974cf8ac68cb61047d204c9189bf1943a6d
7
+ data.tar.gz: e85e786f6cb1f98b10e75742097651013e9fe57ddad4896a70fd85b836709e2eecfe26d0f0854b05423f931b1b5fc17b46dfa63c0e25f1a86ffa024de3748d05
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gilson Ferraz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -59,6 +59,16 @@ ten == 10.dollars #=> true
59
59
  ten == Mint.money(10, 'EUR') #=> false
60
60
  ten > Mint.money(9.99, 'USD') #=> true
61
61
 
62
+ # Zero equality semantics
63
+ # Any zero amount is treated as equal, regardless of currency
64
+ Mint.money(0, 'USD') == Mint.money(0, 'EUR') #=> true
65
+ Mint.money(0, 'USD') == 0 #=> true
66
+ Mint.money(0, 'USD') == 0.0 #=> true
67
+ Mint.money(0, 'USD') == 0r #=> true
68
+
69
+ # Non-zero numerics are not equal to Money objects
70
+ Mint.money(10, 'USD') == 10 #=> false
71
+
62
72
  # Format (uses Kernel.format internally)
63
73
  price = Mint.money(9.99, 'USD')
64
74
 
@@ -93,6 +103,22 @@ ten.allocate([1, 2, 3]) #=> [[USD 1.67], [USD 3.33], [USD 5.00]]
93
103
 
94
104
  ```
95
105
 
106
+ ## API notes
107
+
108
+ **Module names** — Require the `minting` gem; the public API lives under `Mint`.
109
+
110
+ **Exact amounts** — Amounts are stored as `Rational` and rounded to the currency subunit.
111
+
112
+ **Refinements** — `10.dollars` and similar helpers require `using Mint` in the current scope (see Usage above).
113
+
114
+ **Division** — `money / 5` returns new `Money`; `money / other_money` returns a numeric ratio, not money.
115
+
116
+ **Zero equality** — Any zero amount is considered equal across currencies and to numeric zero `Mint.money(0, 'USD') == Mint.money(0, 'EUR')` is intentionally `true`. Non-zero amounts must match currency and value.
117
+
118
+ **Custom currencies** — `Mint.register_currency` returns the existing entry if the code is already registered; use `register_currency!` to detect duplicates.
119
+
120
+ **Built-in currencies** — ISO-style codes ship in `lib/minting/data/currencies.yaml` and load when the registry is first accessed.
121
+
96
122
  ## Installation
97
123
 
98
124
  Option 1: Via bundler command
@@ -126,11 +152,25 @@ Option 3: Install it yourself with:
126
152
  gem install minting
127
153
  ```
128
154
 
155
+ ## Parsing strings
156
+
157
+ ```ruby
158
+ Mint::Money.parse('$19.99') #=> [USD 19.99]
159
+ Mint::Money.parse('19,99 €') #=> [EUR 19.99]
160
+ Mint::Money.parse('1.234,56', 'EUR') #=> [EUR 1234.56]
161
+ Mint::Money.parse('USD 1,234.56') #=> [USD 1234.56]
162
+ ```
163
+
164
+ - Pass a currency code when the string has no symbol or code.
165
+ - 1,234 means 1.234, not 1234, because one comma is treated as decimal.
166
+ - 1,234.00 is unambiguous thousands-plus-decimal.
167
+ - accounting negatives like ($1.23) are unsupported.
168
+ - ambiguous symbols like $ resolve by priority, currently USD.
169
+
129
170
  ## Roadmap
130
171
 
131
172
  - Improve formatting features
132
173
  - Localization (I18n-aware formatting)
133
- - `Mint.parse` for parsing human strings into money
134
174
  - Basic exchange-rate conversions
135
175
 
136
176
  ## Contributing
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rubocop/rake_task'
3
3
  require 'rake/testtask'
4
+ require 'yard'
4
5
 
5
- CLOBBER.include %w[tmp]
6
+ CLOBBER.include %w[doc tmp .yardoc]
6
7
 
7
8
  Rake::TestTask.new(:test) do |t|
8
9
  t.libs << 'test'
@@ -39,4 +40,10 @@ task 'bench:all' => ['bench', 'bench:performance']
39
40
 
40
41
  RuboCop::RakeTask.new(:cop)
41
42
 
43
+ YARD::Rake::YardocTask.new do |t|
44
+ t.files = ['lib/**/*.rb'] # optional
45
+ t.options = [] # optional
46
+ t.stats_options = ['--list-undoc'] # optional
47
+ end
48
+
42
49
  task default: :test