minting 1.7.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +35 -3
- data/doc/Mint/Currency.html +826 -55
- data/doc/Mint/Money.html +715 -218
- data/doc/Mint/RangeStepPatch.html +1 -1
- data/doc/Mint/Registry.html +859 -0
- data/doc/Mint/Rounding.html +495 -0
- data/doc/Mint/UnknownCurrency.html +1 -1
- data/doc/Mint.html +307 -225
- data/doc/Minting.html +2 -2
- data/doc/_index.html +15 -8
- data/doc/agents/api_review-2026-06-15.md +329 -0
- data/doc/agents/copilot-instructions.md +0 -5
- data/doc/agents/expired/copilot-instructions.md +75 -0
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +25 -4
- data/doc/index.html +25 -4
- data/doc/method_list.html +177 -25
- data/doc/top-level-namespace.html +1 -1
- data/lib/minting/currency/currency.rb +71 -1
- data/lib/minting/mint/dsl/range.rb +1 -0
- data/lib/minting/mint/locale_backend.rb +29 -0
- data/lib/minting/mint/mint.rb +13 -38
- data/lib/minting/mint/parser/parser.rb +50 -19
- data/lib/minting/mint/parser/separators.rb +10 -8
- data/lib/minting/mint/registry/registration.rb +33 -0
- data/lib/minting/mint/registry/registry.rb +38 -0
- data/lib/minting/mint/registry/symbols.rb +49 -0
- data/lib/minting/mint/registry/zeros.rb +20 -0
- data/lib/minting/mint/rounding.rb +51 -0
- data/lib/minting/mint.rb +12 -23
- data/lib/minting/money/allocation/allocation.rb +1 -2
- data/lib/minting/money/allocation/split.rb +1 -1
- data/lib/minting/money/arithmetics/methods.rb +2 -2
- data/lib/minting/money/arithmetics/operators.rb +6 -6
- data/lib/minting/money/clamp.rb +1 -1
- data/lib/minting/money/coercion.rb +1 -1
- data/lib/minting/money/comparable.rb +6 -0
- data/lib/minting/money/constructors.rb +63 -20
- data/lib/minting/money/format/formatting.rb +16 -0
- data/lib/minting/money/format/to_s.rb +13 -4
- data/lib/minting/money/money.rb +12 -6
- data/lib/minting/version.rb +1 -1
- metadata +15 -7
- data/lib/minting/currency/currency_registry.rb +0 -67
- data/lib/minting/currency/world_currencies.rb +0 -16
- /data/doc/agents/{AGENTS.md → expired/AGENTS.md} +0 -0
- /data/doc/agents/{gemini_gem_evaluation.md → expired/gemini_gem_evaluation.md} +0 -0
- /data/doc/agents/{recommendations.md → expired/recommendations.md} +0 -0
- /data/doc/agents/{rubocop-issues.md → expired/rubocop-issues.md} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a027eb400724db0164db62cc9d76ce371b73a538d4b5713f85a917b31c43330a
|
|
4
|
+
data.tar.gz: cf7bb6b476300f02f39992dab1e7ecbff9e7d14974dbf8c33fc89dd1c093e20e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9274bdfeb0ffdb3a8e22366a71d02265008bdabcf18abdbc68ec70c4e92768e1c9fdbb58bd243c2f3ad8e3094f3e5cfc45e876756a9a93720a428cc0a42210a1
|
|
7
|
+
data.tar.gz: d0647ee4aa7e9f28dc5cc6d7698639830edabff5b4a0b14c108f55f4bd6a8004e603dccfdcb934c5d404a670f4baf7e2269440643a586bab1c6e2dc71314b7b7
|
data/README.md
CHANGED
|
@@ -172,17 +172,42 @@ Notes:
|
|
|
172
172
|
- Ambiguous symbols like `$` resolve by currency priority (currently USD).
|
|
173
173
|
- The parser scans all uppercase words for registered codes, so spurious non-currency words before the real code are correctly ignored: `Mint.parse("MAX 10.00 USD")` yields `[USD 10.00]`.
|
|
174
174
|
|
|
175
|
+
## Currency lookup
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
# By ISO code (direct hash lookup, string only)
|
|
179
|
+
Mint::Currency.for_code('USD') #=> #<Currency code="USD" ...>
|
|
180
|
+
|
|
181
|
+
# By display symbol (highest-priority currency for ambiguous symbols)
|
|
182
|
+
Mint::Currency.for_symbol('$') #=> #<Currency code="USD" ...>
|
|
183
|
+
Mint::Currency.for_symbol('R$') #=> #<Currency code="BRL" ...>
|
|
184
|
+
Mint::Currency.for_symbol('€') #=> #<Currency code="EUR" ...>
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
|
|
175
188
|
## API notes
|
|
176
189
|
|
|
177
190
|
**Exact amounts** — Amounts are stored as `Rational` and rounded to the currency subunit.
|
|
178
191
|
|
|
192
|
+
**Rounding modes** — Wrap operations in `Mint.with_rounding(mode)` to change how amounts are rounded to the subunit:
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
Mint.with_rounding(:half_down) { Mint.money(1.005, 'USD') } #=> [USD 1.00]
|
|
196
|
+
Mint.with_rounding(:ceil) { Mint.money(1.001, 'USD') } #=> [USD 1.01]
|
|
197
|
+
Mint.with_rounding(:floor) { Mint.parse('1.009', 'USD') } #=> [USD 1.00]
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Modes: `:half_up` (default), `:half_down`, `:floor`, `:ceil`, `:truncate`, `:down`. Applies to construction, parsing, `change`, `split`, and `allocate`. Restores the previous mode when the block exits, even on exception.
|
|
201
|
+
|
|
179
202
|
**Refinements** — `10.dollars` and similar helpers require `using Mint` in the current scope (see Usage above).
|
|
180
203
|
|
|
181
204
|
**Division** — `money / 5` returns new `Money`; `money / other_money` returns a numeric ratio, not money.
|
|
182
205
|
|
|
183
206
|
**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.
|
|
184
207
|
|
|
185
|
-
**
|
|
208
|
+
**Zero helper** — `Currency.zero('USD')` returns a frozen zero-Money, useful as a default value for discounts, totals, or counters.
|
|
209
|
+
|
|
210
|
+
**Registered currencies** — `Currency.register(code:, subunit:, symbol:, priority:)` adds custom currencies. Only registered codes and symbols are recognized by the parser.
|
|
186
211
|
|
|
187
212
|
**Built-in currencies** — 150+ ISO-4217 world currencies ship in `lib/minting/data/currencies.yaml` and load when the registry is first accessed.
|
|
188
213
|
|
|
@@ -201,11 +226,18 @@ Or at runtime:
|
|
|
201
226
|
Minting.use_top_level_constants!
|
|
202
227
|
```
|
|
203
228
|
|
|
229
|
+
For Rails applications, you can enable the top-level constants in an initializer:
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
# config/initializers/minting.rb
|
|
233
|
+
require "minting/dsl"
|
|
234
|
+
```
|
|
235
|
+
|
|
204
236
|
After opting in:
|
|
205
237
|
|
|
206
238
|
```ruby
|
|
207
|
-
price = Money.
|
|
208
|
-
tax = Money.
|
|
239
|
+
price = Money.from(10, "USD") # equivalent to Mint::Money.from
|
|
240
|
+
tax = Money.from(2.50, "USD")
|
|
209
241
|
cur = Currency.new(code: "EUR", symbol: "€", subunit: 2, priority: 0)
|
|
210
242
|
```
|
|
211
243
|
|