minting 1.7.3 → 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 +25 -8
- data/doc/Mint/Currency.html +535 -18
- data/doc/Mint/Money.html +659 -185
- data/doc/Mint/RangeStepPatch.html +1 -1
- data/doc/Mint/Registry.html +19 -2
- data/doc/Mint/Rounding.html +495 -0
- data/doc/Mint/UnknownCurrency.html +1 -1
- data/doc/Mint.html +187 -399
- data/doc/Minting.html +2 -2
- data/doc/_index.html +8 -1
- data/doc/agents/api_review-2026-06-15.md +0 -13
- data/doc/agents/copilot-instructions.md +70 -0
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +19 -9
- data/doc/index.html +19 -9
- data/doc/method_list.html +130 -42
- data/doc/top-level-namespace.html +1 -1
- data/lib/minting/currency/currency.rb +41 -2
- data/lib/minting/mint/dsl/range.rb +1 -0
- data/lib/minting/mint/mint.rb +10 -37
- data/lib/minting/mint/parser/parser.rb +50 -15
- data/lib/minting/mint/parser/separators.rb +10 -8
- data/lib/minting/mint/registry/zeros.rb +2 -0
- data/lib/minting/mint/rounding.rb +51 -0
- data/lib/minting/mint.rb +1 -0
- 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 +60 -12
- data/lib/minting/money/money.rb +0 -6
- data/lib/minting/version.rb +1 -1
- metadata +4 -1
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
|
@@ -176,12 +176,12 @@ Notes:
|
|
|
176
176
|
|
|
177
177
|
```ruby
|
|
178
178
|
# By ISO code (direct hash lookup, string only)
|
|
179
|
-
Mint.
|
|
179
|
+
Mint::Currency.for_code('USD') #=> #<Currency code="USD" ...>
|
|
180
180
|
|
|
181
181
|
# By display symbol (highest-priority currency for ambiguous symbols)
|
|
182
|
-
Mint.
|
|
183
|
-
Mint.
|
|
184
|
-
Mint.
|
|
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
185
|
|
|
186
186
|
```
|
|
187
187
|
|
|
@@ -189,15 +189,25 @@ Mint.currency_for_symbol('€') #=> #<Currency code="EUR" ...>
|
|
|
189
189
|
|
|
190
190
|
**Exact amounts** — Amounts are stored as `Rational` and rounded to the currency subunit.
|
|
191
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
|
+
|
|
192
202
|
**Refinements** — `10.dollars` and similar helpers require `using Mint` in the current scope (see Usage above).
|
|
193
203
|
|
|
194
204
|
**Division** — `money / 5` returns new `Money`; `money / other_money` returns a numeric ratio, not money.
|
|
195
205
|
|
|
196
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.
|
|
197
207
|
|
|
198
|
-
**Zero helper** — `
|
|
208
|
+
**Zero helper** — `Currency.zero('USD')` returns a frozen zero-Money, useful as a default value for discounts, totals, or counters.
|
|
199
209
|
|
|
200
|
-
**Registered currencies** — `
|
|
210
|
+
**Registered currencies** — `Currency.register(code:, subunit:, symbol:, priority:)` adds custom currencies. Only registered codes and symbols are recognized by the parser.
|
|
201
211
|
|
|
202
212
|
**Built-in currencies** — 150+ ISO-4217 world currencies ship in `lib/minting/data/currencies.yaml` and load when the registry is first accessed.
|
|
203
213
|
|
|
@@ -216,11 +226,18 @@ Or at runtime:
|
|
|
216
226
|
Minting.use_top_level_constants!
|
|
217
227
|
```
|
|
218
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
|
+
|
|
219
236
|
After opting in:
|
|
220
237
|
|
|
221
238
|
```ruby
|
|
222
|
-
price = Money.
|
|
223
|
-
tax = Money.
|
|
239
|
+
price = Money.from(10, "USD") # equivalent to Mint::Money.from
|
|
240
|
+
tax = Money.from(2.50, "USD")
|
|
224
241
|
cur = Currency.new(code: "EUR", symbol: "€", subunit: 2, priority: 0)
|
|
225
242
|
```
|
|
226
243
|
|