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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -3
  3. data/doc/Mint/Currency.html +826 -55
  4. data/doc/Mint/Money.html +715 -218
  5. data/doc/Mint/RangeStepPatch.html +1 -1
  6. data/doc/Mint/Registry.html +859 -0
  7. data/doc/Mint/Rounding.html +495 -0
  8. data/doc/Mint/UnknownCurrency.html +1 -1
  9. data/doc/Mint.html +307 -225
  10. data/doc/Minting.html +2 -2
  11. data/doc/_index.html +15 -8
  12. data/doc/agents/api_review-2026-06-15.md +329 -0
  13. data/doc/agents/copilot-instructions.md +0 -5
  14. data/doc/agents/expired/copilot-instructions.md +75 -0
  15. data/doc/class_list.html +1 -1
  16. data/doc/file.README.html +25 -4
  17. data/doc/index.html +25 -4
  18. data/doc/method_list.html +177 -25
  19. data/doc/top-level-namespace.html +1 -1
  20. data/lib/minting/currency/currency.rb +71 -1
  21. data/lib/minting/mint/dsl/range.rb +1 -0
  22. data/lib/minting/mint/locale_backend.rb +29 -0
  23. data/lib/minting/mint/mint.rb +13 -38
  24. data/lib/minting/mint/parser/parser.rb +50 -19
  25. data/lib/minting/mint/parser/separators.rb +10 -8
  26. data/lib/minting/mint/registry/registration.rb +33 -0
  27. data/lib/minting/mint/registry/registry.rb +38 -0
  28. data/lib/minting/mint/registry/symbols.rb +49 -0
  29. data/lib/minting/mint/registry/zeros.rb +20 -0
  30. data/lib/minting/mint/rounding.rb +51 -0
  31. data/lib/minting/mint.rb +12 -23
  32. data/lib/minting/money/allocation/allocation.rb +1 -2
  33. data/lib/minting/money/allocation/split.rb +1 -1
  34. data/lib/minting/money/arithmetics/methods.rb +2 -2
  35. data/lib/minting/money/arithmetics/operators.rb +6 -6
  36. data/lib/minting/money/clamp.rb +1 -1
  37. data/lib/minting/money/coercion.rb +1 -1
  38. data/lib/minting/money/comparable.rb +6 -0
  39. data/lib/minting/money/constructors.rb +63 -20
  40. data/lib/minting/money/format/formatting.rb +16 -0
  41. data/lib/minting/money/format/to_s.rb +13 -4
  42. data/lib/minting/money/money.rb +12 -6
  43. data/lib/minting/version.rb +1 -1
  44. metadata +15 -7
  45. data/lib/minting/currency/currency_registry.rb +0 -67
  46. data/lib/minting/currency/world_currencies.rb +0 -16
  47. /data/doc/agents/{AGENTS.md → expired/AGENTS.md} +0 -0
  48. /data/doc/agents/{gemini_gem_evaluation.md → expired/gemini_gem_evaluation.md} +0 -0
  49. /data/doc/agents/{recommendations.md → expired/recommendations.md} +0 -0
  50. /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: 849f4b46ee6f731be672f7e6adb274174233294d7be293c8c875eaa0ace5b744
4
- data.tar.gz: b3f3a822c55e7fd9fdddcfcf7be59069b66ea441d73ab61e2e202563173a8675
3
+ metadata.gz: a027eb400724db0164db62cc9d76ce371b73a538d4b5713f85a917b31c43330a
4
+ data.tar.gz: cf7bb6b476300f02f39992dab1e7ecbff9e7d14974dbf8c33fc89dd1c093e20e
5
5
  SHA512:
6
- metadata.gz: 5f4d42d03f31c941fcd591e27c463341be2c31498c7d854c3b98f85445a8ca55dfa692c3124f187000c83b97b0abc21e6e7276ea5bb3cd1090e82619e6fcc451
7
- data.tar.gz: '0854273f42d05dee2b2d91830110d9f59074821abd81c76a14860a0969c4bd2cd48c56164c5fd2b65fcdfe32f537860958b108cd53eadfc53a2c33215f35c5cd'
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
- **Registered currencies** — `Mint.register_currency`. Only registered currency codes and symbols are recognized by the parser.
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.create(10, "USD") # equivalent to Mint::Money.create
208
- tax = Money.money(2.50, "USD")
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