minting 1.7.2 → 1.7.3
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 +16 -1
- data/doc/Mint/Currency.html +285 -31
- data/doc/Mint/Money.html +79 -56
- data/doc/Mint/RangeStepPatch.html +1 -1
- data/doc/Mint/Registry.html +842 -0
- data/doc/Mint/UnknownCurrency.html +1 -1
- data/doc/Mint.html +345 -51
- data/doc/Minting.html +2 -2
- data/doc/_index.html +8 -8
- data/doc/agents/api_review-2026-06-15.md +342 -0
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +13 -2
- data/doc/index.html +13 -2
- data/doc/method_list.html +100 -36
- data/doc/top-level-namespace.html +1 -1
- data/lib/minting/currency/currency.rb +31 -0
- data/lib/minting/mint/locale_backend.rb +29 -0
- data/lib/minting/mint/mint.rb +23 -21
- data/lib/minting/mint/parser/parser.rb +3 -7
- data/lib/minting/mint/registry/registration.rb +33 -0
- data/lib/minting/mint/registry/registry.rb +38 -0
- data/lib/minting/mint/registry/symbols.rb +49 -0
- data/lib/minting/mint/registry/zeros.rb +18 -0
- data/lib/minting/mint.rb +13 -25
- data/lib/minting/money/constructors.rb +6 -11
- data/lib/minting/money/format/formatting.rb +16 -0
- data/lib/minting/money/format/to_s.rb +13 -4
- data/lib/minting/money/money.rb +12 -0
- data/lib/minting/version.rb +1 -1
- metadata +13 -8
- data/lib/minting/currency/currency_registry.rb +0 -67
- data/lib/minting/currency/world_currencies.rb +0 -16
- /data/doc/agents/{AGENTS.md → expired/AGENTS.md} +0 -0
- /data/doc/agents/{copilot-instructions.md → expired/copilot-instructions.md} +0 -0
- /data/doc/agents/{gemini_gem_evaluation.md → expired/gemini_gem_evaluation.md} +0 -0
- /data/doc/agents/{recommendations.md → expired/recommendations.md} +0 -0
- /data/doc/agents/{rubocop-issues.md → expired/rubocop-issues.md} +0 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
# Minting gem API review
|
|
2
|
+
|
|
3
|
+
**Data:** 2026-06-15
|
|
4
|
+
**Author:** Wave AI (via Wave Terminal assistant)
|
|
5
|
+
|
|
6
|
+
## 1. Top-level API surface (Mint / Money / Currency)
|
|
7
|
+
|
|
8
|
+
### What’s good
|
|
9
|
+
|
|
10
|
+
- `Mint.money(10, 'USD')` is clear and discoverable.
|
|
11
|
+
- Refinements (`10.dollars`, `4.to_money('USD')`) are modern and opt-in.
|
|
12
|
+
- Optional `minting/dsl` with `Money` / `Currency` constants is a good compromise for ergonomics vs. gem conflicts.
|
|
13
|
+
|
|
14
|
+
### Suggestions
|
|
15
|
+
|
|
16
|
+
1. **Tighten constructor story (too many verbs)**
|
|
17
|
+
Right now you have:
|
|
18
|
+
- `Mint.money(amount, code)`
|
|
19
|
+
- `Mint.zero(currency)`
|
|
20
|
+
- `Mint::Money.create(amount, currency)`
|
|
21
|
+
- `Mint::Money.from_fractional(fractional, currency)`
|
|
22
|
+
- `Money.create` / `Money.from_fractional` / `price.mint(new_amount)` (instance)
|
|
23
|
+
|
|
24
|
+
Consider a simpler, more opinionated set:
|
|
25
|
+
|
|
26
|
+
- **Class side:**
|
|
27
|
+
- `Money.from(amount, currency)` (instead of `create`)
|
|
28
|
+
- `Money.from_fractional(fractional, currency)`
|
|
29
|
+
- **Module side:**
|
|
30
|
+
- `Mint.money(amount, currency)` (delegates to `Money.from`)
|
|
31
|
+
- `Mint.from_fractional(fractional, currency)` (delegates to `Money.from_fractional`)
|
|
32
|
+
- `Mint.zero(currency)`
|
|
33
|
+
|
|
34
|
+
And **remove / de-emphasize** `Money.create` from public docs (keep as private alias if needed).
|
|
35
|
+
|
|
36
|
+
2. **Rename `mint(new_amount)` → clearer “copy with” semantics**
|
|
37
|
+
|
|
38
|
+
`price.mint(15.00)` is cute but not self-describing. Consider:
|
|
39
|
+
|
|
40
|
+
- `price.with_amount(15.00)`
|
|
41
|
+
- or `price.change(amount: 15.00)`
|
|
42
|
+
- or `price.rebuild(15.00)` (less good, but at least indicates a copy)
|
|
43
|
+
|
|
44
|
+
And surface this in README (“Immutability helpers”).
|
|
45
|
+
|
|
46
|
+
3. **Top-level constants: make the opt-in path prominent, but one-liner**
|
|
47
|
+
|
|
48
|
+
You already have:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
require "minting"
|
|
52
|
+
require "minting/dsl" # opt-in top‑level Money / Currency
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For Rails developers, you might recommend in README:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
# config/initializers/minting.rb
|
|
59
|
+
require "minting/dsl"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
And add a short “Rails setup” snippet, since that’s what competing gems usually highlight first.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 2. Money semantics & naming
|
|
67
|
+
|
|
68
|
+
### Zero equality semantics
|
|
69
|
+
|
|
70
|
+
You do something non-standard and powerful:
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
Mint.money(0, 'USD') == Mint.money(0, 'EUR') # => true
|
|
74
|
+
Mint.money(0, 'USD') == 0 # => true
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This is very nice for totals, but surprising vs. `money` gem.
|
|
78
|
+
|
|
79
|
+
**Changes:**
|
|
80
|
+
|
|
81
|
+
1. **Make this a named feature, with an escape hatch**
|
|
82
|
+
|
|
83
|
+
- Give it a name in docs: e.g. “currency-agnostic zero”.
|
|
84
|
+
- Provide an **explicit predicate or helper**:
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
price.zero? # usual predicate
|
|
88
|
+
price.strictly_zero_in?('USD') # same_currency? + zero?
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- Consider a **config flag** or alternate comparator:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
Mint.strict_zero_comparison = true
|
|
95
|
+
# or
|
|
96
|
+
price.eql_in_currency?(other_price)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
2. **Docs: add a clear “Gotchas” section**
|
|
100
|
+
Call out at the bottom of README “Behavior that differs from `money` gem”, starting with zero. This directly addresses “gap to competitors” and reduces surprises.
|
|
101
|
+
|
|
102
|
+
### `same_currency?`
|
|
103
|
+
|
|
104
|
+
Current doc:
|
|
105
|
+
|
|
106
|
+
```ruby
|
|
107
|
+
# @param other [Currency] the target currency to compare
|
|
108
|
+
def same_currency?(other) = other.currency == currency
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This is odd: the param type is a `Currency` in the docs, but you call `other.currency` which implies it’s actually `Money`.
|
|
112
|
+
|
|
113
|
+
**Change:**
|
|
114
|
+
|
|
115
|
+
- Decide on the intent; then:
|
|
116
|
+
- If it compares two `Money` objects, define:
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
# @param other [Money]
|
|
120
|
+
def same_currency?(other) = other.currency == currency
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- Or if you want both forms, accept either and update docs:
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
def same_currency?(other)
|
|
127
|
+
other_currency =
|
|
128
|
+
case other
|
|
129
|
+
when Mint::Money then other.currency
|
|
130
|
+
when Mint::Currency then other
|
|
131
|
+
else
|
|
132
|
+
Currency.resolve!(other)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
other_currency == currency
|
|
136
|
+
end
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- Consider renaming to `same_currency_as?(other)` to better match Ruby predicate idioms and feel less “type-ish”.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 3. Parsing API
|
|
144
|
+
|
|
145
|
+
`Mint.parse` is already strong. To beat competitors, lean into this.
|
|
146
|
+
|
|
147
|
+
### Suggestions
|
|
148
|
+
|
|
149
|
+
1. **Return type & error modes**
|
|
150
|
+
|
|
151
|
+
- Document explicitly that `Mint.parse` returns `Mint::Money`.
|
|
152
|
+
- Add **two modes**:
|
|
153
|
+
- `Mint.parse!(...)` – raises on failure.
|
|
154
|
+
- `Mint.parse(...)` – returns `nil` on failure or perhaps `Result` object in future, but nil is sufficient initially.
|
|
155
|
+
|
|
156
|
+
2. **Expose configuration hooks**
|
|
157
|
+
|
|
158
|
+
Even if not fully implemented yet, define the shape:
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
Mint.parser.default_currency = 'USD'
|
|
162
|
+
Mint.parser.symbol_priority = %w[USD CAD AUD]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
That gives you a path to match/beat `monetize` / `money` ecosystem flexibility.
|
|
166
|
+
|
|
167
|
+
3. **Quality-of-life alias**
|
|
168
|
+
|
|
169
|
+
- `Mint.money_from(str, currency_code = nil)`
|
|
170
|
+
- Or a class method: `Mint::Money.parse(str, currency: nil)`
|
|
171
|
+
|
|
172
|
+
That keeps “all money stuff under Money” for folks who avoid module functions.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 4. Formatting API
|
|
177
|
+
|
|
178
|
+
Current:
|
|
179
|
+
|
|
180
|
+
- `to_s(format: '%<symbol>s%<amount>f')`
|
|
181
|
+
- Hash format for per-sign: `{ negative: '(%<symbol>s%<amount>f)' }`
|
|
182
|
+
|
|
183
|
+
This is powerful but low-level. Competing gems typically offer higher-level presets and localization.
|
|
184
|
+
|
|
185
|
+
### Suggestions
|
|
186
|
+
|
|
187
|
+
1. **Named formats / shortcuts**
|
|
188
|
+
|
|
189
|
+
Something like:
|
|
190
|
+
|
|
191
|
+
```ruby
|
|
192
|
+
price.format # same as to_s
|
|
193
|
+
price.format(:iso) # "USD 9.99"
|
|
194
|
+
price.format(:symbol) # "$9.99"
|
|
195
|
+
price.format(:code) # "9.99 USD"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Internally, use a format registry:
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
201
|
+
Mint.formats.register(:iso, '%<currency>s %<amount>f')
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
2. **Accounting format shortcut**
|
|
205
|
+
|
|
206
|
+
You already support per-sign hash formats; expose a named helper:
|
|
207
|
+
|
|
208
|
+
```ruby
|
|
209
|
+
price.to_accounting # ($1,234.56) for negatives, 0.00 for zero
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
3. **JSON / Rails integration**
|
|
213
|
+
|
|
214
|
+
You have:
|
|
215
|
+
|
|
216
|
+
```ruby
|
|
217
|
+
price.to_json # => {"currency":"USD","amount":"9.99"}
|
|
218
|
+
price.to_hash # => { currency: "USD", amount: "9.99" }
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
For better Rails DX & parity:
|
|
222
|
+
|
|
223
|
+
- Add `as_json` delegating to `to_hash`.
|
|
224
|
+
- Mention in README: “Works with Rails serialization (`as_json` implemented).”
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 5. Currency API
|
|
229
|
+
|
|
230
|
+
Current:
|
|
231
|
+
|
|
232
|
+
- `Mint.currency_for_code('USD')`
|
|
233
|
+
- `Mint.currency_for_symbol('$')`
|
|
234
|
+
- `Mint.register_currency(...)`
|
|
235
|
+
- `Mint.world_currencies` (+ internal `Registry`)
|
|
236
|
+
|
|
237
|
+
### Suggestions
|
|
238
|
+
|
|
239
|
+
1. **Consistent names & variants**
|
|
240
|
+
|
|
241
|
+
Consider:
|
|
242
|
+
|
|
243
|
+
- `Mint.currency('USD')` → primary lookup (by code; maybe symbol in future).
|
|
244
|
+
- Keep `currency_for_code` / `currency_for_symbol` as explicit variants, but guide people to the simple `currency`.
|
|
245
|
+
|
|
246
|
+
2. **Clarify custom currency lifecycle**
|
|
247
|
+
|
|
248
|
+
Competitors often have quirks here; you can win on clarity:
|
|
249
|
+
|
|
250
|
+
- Are custom currencies persisted per process?
|
|
251
|
+
- Are they thread-safe?
|
|
252
|
+
- Are they ordered by `priority` in deterministic way?
|
|
253
|
+
|
|
254
|
+
Add a small “Custom currencies” section with examples and guarantees.
|
|
255
|
+
|
|
256
|
+
3. **Expose the registry read-only**
|
|
257
|
+
|
|
258
|
+
Instead of `world_currencies` returning “the frozen world-currencies hash” (but you also have `Registry.currencies`), maybe have:
|
|
259
|
+
|
|
260
|
+
```ruby
|
|
261
|
+
Mint.currencies # => { "USD" => <Currency>, ... } (frozen hash)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
And keep `Registry` private in docs.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## 6. Error types & clarity
|
|
269
|
+
|
|
270
|
+
### UnknownCurrency
|
|
271
|
+
|
|
272
|
+
```ruby
|
|
273
|
+
# Unknown currency excpetion
|
|
274
|
+
class UnknownCurrency < StandardError; end
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
- Typo in comment (“excpetion”).
|
|
278
|
+
- Recommend renaming to `UnknownCurrencyError` for conventional Ruby style.
|
|
279
|
+
- Ensure it’s actually raised from `Currency.resolve!` (and document that).
|
|
280
|
+
|
|
281
|
+
### Validation errors
|
|
282
|
+
|
|
283
|
+
You currently raise `ArgumentError` for several things (`amount must be Numeric`, `fractional must be an Integer`).
|
|
284
|
+
|
|
285
|
+
Consider:
|
|
286
|
+
|
|
287
|
+
- Keeping `ArgumentError` but **documenting all the failure cases** in YARD and README.
|
|
288
|
+
- Or, for one level up in clarity, introduce:
|
|
289
|
+
|
|
290
|
+
```ruby
|
|
291
|
+
class InvalidMoneyArgument < ArgumentError; end
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
and use that everywhere. This is a small DX win in large apps.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## 7. Documentation structure (DX & competitiveness)
|
|
299
|
+
|
|
300
|
+
Your README is already strong. To push it over the top vs. `money` gem and friends:
|
|
301
|
+
|
|
302
|
+
1. **Add a “Comparison” section**
|
|
303
|
+
|
|
304
|
+
Not necessarily with names, but structurally:
|
|
305
|
+
|
|
306
|
+
- “What Minting does differently”
|
|
307
|
+
- Always-exact `Rational` amounts.
|
|
308
|
+
- Currency-agnostic zero.
|
|
309
|
+
- Faster formatting (link benchmarks).
|
|
310
|
+
- Separate `minting-rails` companion for clean Rails integration.
|
|
311
|
+
|
|
312
|
+
2. **Add “Common tasks” cheatsheet**
|
|
313
|
+
|
|
314
|
+
Short, scannable table:
|
|
315
|
+
|
|
316
|
+
| Task | Code |
|
|
317
|
+
|------------------------------|-----------------------------------|
|
|
318
|
+
| New amount | `Mint.money(10, 'USD')` |
|
|
319
|
+
| From cents | `Mint::Money.from_fractional(999, 'USD')` |
|
|
320
|
+
| Change amount immutably | `price.with_amount(15)` (or `mint`) |
|
|
321
|
+
| Parse user input | `Mint.parse('$19.99')` |
|
|
322
|
+
| Serialize to JSON | `price.to_hash` / `price.as_json` |
|
|
323
|
+
| Clamp to range | `price.clamp(0, 100)` |
|
|
324
|
+
| Split / allocate | `ten.split(3)` / `ten.allocate([...])` |
|
|
325
|
+
|
|
326
|
+
This directly optimizes developer experience.
|
|
327
|
+
|
|
328
|
+
3. **Prominent “Rails” heading**
|
|
329
|
+
|
|
330
|
+
Right now you just mention `minting-rails`. Make it a full section:
|
|
331
|
+
|
|
332
|
+
- How to add gem.
|
|
333
|
+
- Example migration / attribute definition (even if in the other repo, mirror one snippet here).
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## 8. Minor polish
|
|
338
|
+
|
|
339
|
+
- In `README` “Json serialization” → “JSON serialization”.
|
|
340
|
+
- Make sure `Mint::Money`’s `inspect` and `to_s` are clearly differentiated in docs:
|
|
341
|
+
- `inspect` → developer/debugging (`[USD 10.00]`).
|
|
342
|
+
- `to_s` → user-facing, configurable formatting.
|
data/doc/class_list.html
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
|
|
47
47
|
<ul id="full_list" class="class">
|
|
48
48
|
<li id="object_" class="odd"><div class="item" style="padding-left:30px"><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></div></li>
|
|
49
|
-
<li id='object_Mint' class='even'><div class='item' style='padding-left:30px'><a tabindex='0' class='toggle' role='button' aria-label='Mint child nodes' aria-expanded='false' aria-controls='object_Mint'></a> <span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span><small class='search_info'>Top Level Namespace</small></div><div aria-labelledby='object_Mint'><ul><li id='object_Mint::Currency' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span> < Data<small class='search_info'>Mint</small></div></li><li id='object_Mint::
|
|
49
|
+
<li id='object_Mint' class='even'><div class='item' style='padding-left:30px'><a tabindex='0' class='toggle' role='button' aria-label='Mint child nodes' aria-expanded='false' aria-controls='object_Mint'></a> <span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span><small class='search_info'>Top Level Namespace</small></div><div aria-labelledby='object_Mint'><ul><li id='object_Mint::Currency' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span> < Data<small class='search_info'>Mint</small></div></li><li id='object_Mint::Money' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span> < Object<small class='search_info'>Mint</small></div></li><li id='object_Mint::RangeStepPatch' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/RangeStepPatch.html" title="Mint::RangeStepPatch (module)">RangeStepPatch</a></span><small class='search_info'>Mint</small></div></li><li id='object_Mint::Registry' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Registry.html" title="Mint::Registry (module)">Registry</a></span><small class='search_info'>Mint</small></div></li><li id='object_Mint::UnknownCurrency' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/UnknownCurrency.html" title="Mint::UnknownCurrency (class)">UnknownCurrency</a></span> < StandardError<small class='search_info'>Mint</small></div></li></ul></div></li><li id='object_Minting' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Minting.html" title="Minting (module)">Minting</a></span><small class='search_info'>Top Level Namespace</small></div></li>
|
|
50
50
|
|
|
51
51
|
</ul>
|
|
52
52
|
</div>
|
data/doc/file.README.html
CHANGED
|
@@ -234,12 +234,23 @@
|
|
|
234
234
|
<li>Ambiguous symbols like <code>$</code> resolve by currency priority (currently USD).</li>
|
|
235
235
|
<li>The parser scans all uppercase words for registered codes, so spurious non-currency words before the real code are correctly ignored: <code>Mint.parse("MAX 10.00 USD")</code> yields <code>[USD 10.00]</code>.</li>
|
|
236
236
|
</ul>
|
|
237
|
+
<h2 id="Currency_lookup">Currency lookup</h2>
|
|
238
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># By ISO code (direct hash lookup, string only)
|
|
239
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency_for_code'><span class='object_link'><a href="Mint.html#currency_for_code-class_method" title="Mint.currency_for_code (method)">currency_for_code</a></span></span><span class='lparen'>(</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'>#=> #<Currency code="USD" ...>
|
|
240
|
+
</span>
|
|
241
|
+
<span class='comment'># By display symbol (highest-priority currency for ambiguous symbols)
|
|
242
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency_for_symbol'><span class='object_link'><a href="Mint.html#currency_for_symbol-class_method" title="Mint.currency_for_symbol (method)">currency_for_symbol</a></span></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='rparen'>)</span> <span class='comment'>#=> #<Currency code="USD" ...>
|
|
243
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency_for_symbol'><span class='object_link'><a href="Mint.html#currency_for_symbol-class_method" title="Mint.currency_for_symbol (method)">currency_for_symbol</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>R$</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> #<Currency code="BRL" ...>
|
|
244
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency_for_symbol'><span class='object_link'><a href="Mint.html#currency_for_symbol-class_method" title="Mint.currency_for_symbol (method)">currency_for_symbol</a></span></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='rparen'>)</span> <span class='comment'>#=> #<Currency code="EUR" ...>
|
|
245
|
+
</span>
|
|
246
|
+
</code></pre>
|
|
237
247
|
<h2 id="API_notes">API notes</h2>
|
|
238
248
|
<p><strong>Exact amounts</strong> — Amounts are stored as <code>Rational</code> and rounded to the currency subunit.</p>
|
|
239
249
|
<p><strong>Refinements</strong> — <code>10.dollars</code> and similar helpers require <code>using Mint</code> in the current scope (see Usage above).</p>
|
|
240
250
|
<p><strong>Division</strong> — <code>money / 5</code> returns new <code>Money</code>; <code>money / other_money</code> returns a numeric ratio, not money.</p>
|
|
241
251
|
<p><strong>Zero equality</strong> — Any zero amount is considered equal across currencies and to numeric zero (<code>Mint.money(0, 'USD') == Mint.money(0, 'EUR')</code> is intentionally <code>true</code>). Non-zero amounts must match currency and value.</p>
|
|
242
|
-
<p><strong>
|
|
252
|
+
<p><strong>Zero helper</strong> — <code>Mint.zero('USD')</code> returns a frozen zero-Money, useful as a default value for discounts, totals, or counters.</p>
|
|
253
|
+
<p><strong>Registered currencies</strong> — <code>Mint.register_currency(code:, subunit:, symbol:, priority:)</code> adds custom currencies. Only registered codes and symbols are recognized by the parser.</p>
|
|
243
254
|
<p><strong>Built-in currencies</strong> — 150+ ISO-4217 world currencies ship in <code>lib/minting/data/currencies.yaml</code> and load when the registry is first accessed.</p>
|
|
244
255
|
<h2 id="Optional_top_level__Money__and__Currency_">Optional top-level <code>Money</code> and <code>Currency</code></h2>
|
|
245
256
|
<p>By default, Minting keeps everything namespaced under <code>Mint</code> to coexist nicely with other gems. If you prefer shorter constants, opt in:</p>
|
|
@@ -265,7 +276,7 @@
|
|
|
265
276
|
<p>MIT</p></div></div>
|
|
266
277
|
|
|
267
278
|
<div id="footer">
|
|
268
|
-
Generated on
|
|
279
|
+
Generated on Mon Jun 15 19:57:57 2026 by
|
|
269
280
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
270
281
|
0.9.44 (ruby-4.0.5).
|
|
271
282
|
</div>
|
data/doc/index.html
CHANGED
|
@@ -234,12 +234,23 @@
|
|
|
234
234
|
<li>Ambiguous symbols like <code>$</code> resolve by currency priority (currently USD).</li>
|
|
235
235
|
<li>The parser scans all uppercase words for registered codes, so spurious non-currency words before the real code are correctly ignored: <code>Mint.parse("MAX 10.00 USD")</code> yields <code>[USD 10.00]</code>.</li>
|
|
236
236
|
</ul>
|
|
237
|
+
<h2 id="Currency_lookup">Currency lookup</h2>
|
|
238
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># By ISO code (direct hash lookup, string only)
|
|
239
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency_for_code'><span class='object_link'><a href="Mint.html#currency_for_code-class_method" title="Mint.currency_for_code (method)">currency_for_code</a></span></span><span class='lparen'>(</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'>#=> #<Currency code="USD" ...>
|
|
240
|
+
</span>
|
|
241
|
+
<span class='comment'># By display symbol (highest-priority currency for ambiguous symbols)
|
|
242
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency_for_symbol'><span class='object_link'><a href="Mint.html#currency_for_symbol-class_method" title="Mint.currency_for_symbol (method)">currency_for_symbol</a></span></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='rparen'>)</span> <span class='comment'>#=> #<Currency code="USD" ...>
|
|
243
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency_for_symbol'><span class='object_link'><a href="Mint.html#currency_for_symbol-class_method" title="Mint.currency_for_symbol (method)">currency_for_symbol</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>R$</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> #<Currency code="BRL" ...>
|
|
244
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_currency_for_symbol'><span class='object_link'><a href="Mint.html#currency_for_symbol-class_method" title="Mint.currency_for_symbol (method)">currency_for_symbol</a></span></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='rparen'>)</span> <span class='comment'>#=> #<Currency code="EUR" ...>
|
|
245
|
+
</span>
|
|
246
|
+
</code></pre>
|
|
237
247
|
<h2 id="API_notes">API notes</h2>
|
|
238
248
|
<p><strong>Exact amounts</strong> — Amounts are stored as <code>Rational</code> and rounded to the currency subunit.</p>
|
|
239
249
|
<p><strong>Refinements</strong> — <code>10.dollars</code> and similar helpers require <code>using Mint</code> in the current scope (see Usage above).</p>
|
|
240
250
|
<p><strong>Division</strong> — <code>money / 5</code> returns new <code>Money</code>; <code>money / other_money</code> returns a numeric ratio, not money.</p>
|
|
241
251
|
<p><strong>Zero equality</strong> — Any zero amount is considered equal across currencies and to numeric zero (<code>Mint.money(0, 'USD') == Mint.money(0, 'EUR')</code> is intentionally <code>true</code>). Non-zero amounts must match currency and value.</p>
|
|
242
|
-
<p><strong>
|
|
252
|
+
<p><strong>Zero helper</strong> — <code>Mint.zero('USD')</code> returns a frozen zero-Money, useful as a default value for discounts, totals, or counters.</p>
|
|
253
|
+
<p><strong>Registered currencies</strong> — <code>Mint.register_currency(code:, subunit:, symbol:, priority:)</code> adds custom currencies. Only registered codes and symbols are recognized by the parser.</p>
|
|
243
254
|
<p><strong>Built-in currencies</strong> — 150+ ISO-4217 world currencies ship in <code>lib/minting/data/currencies.yaml</code> and load when the registry is first accessed.</p>
|
|
244
255
|
<h2 id="Optional_top_level__Money__and__Currency_">Optional top-level <code>Money</code> and <code>Currency</code></h2>
|
|
245
256
|
<p>By default, Minting keeps everything namespaced under <code>Mint</code> to coexist nicely with other gems. If you prefer shorter constants, opt in:</p>
|
|
@@ -265,7 +276,7 @@
|
|
|
265
276
|
<p>MIT</p></div></div>
|
|
266
277
|
|
|
267
278
|
<div id="footer">
|
|
268
|
-
Generated on
|
|
279
|
+
Generated on Mon Jun 15 19:57:57 2026 by
|
|
269
280
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
270
281
|
0.9.44 (ruby-4.0.5).
|
|
271
282
|
</div>
|