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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ebe31c2ae1b9febafa3a6a4ccea1392cb089242746a933d530121b08f55cd4e
4
- data.tar.gz: 80f1eb17f62b7a7924df8b2fedb79d864bcadd5ea5e8432e5149b14fb0d9af0c
3
+ metadata.gz: a027eb400724db0164db62cc9d76ce371b73a538d4b5713f85a917b31c43330a
4
+ data.tar.gz: cf7bb6b476300f02f39992dab1e7ecbff9e7d14974dbf8c33fc89dd1c093e20e
5
5
  SHA512:
6
- metadata.gz: 44147d3523485fc36491bb62f24df5f4040fe3ddda673201d5b6fc9a5e005bda94cd3300b4e84682f4378cb9eedb851ad16c247a2dfeb9de264fd24a6b1714ca
7
- data.tar.gz: 5f41672831c8c722e47de8b8e94549bb633c48b677fc8e63eca9f10233062f32a0acd276b31271a4f0ac4417779b03db7f034a9b9afcfbd39c0cbadb16886dbf
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.currency_for_code('USD') #=> #<Currency code="USD" ...>
179
+ Mint::Currency.for_code('USD') #=> #<Currency code="USD" ...>
180
180
 
181
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" ...>
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** — `Mint.zero('USD')` returns a frozen zero-Money, useful as a default value for discounts, totals, or counters.
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** — `Mint.register_currency(code:, subunit:, symbol:, priority:)` adds custom currencies. Only registered codes and symbols are recognized by the parser.
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.create(10, "USD") # equivalent to Mint::Money.create
223
- tax = Money.money(2.50, "USD")
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