minting 1.3.0 → 1.4.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: a7530401c0a722596508aab5aa587bc53a548698308f9d09ae34fac2ec671784
4
- data.tar.gz: abe0501b11d4f9c77e2054443c12e1d4a5e2707fabbfac71f5bd4b8a7f5a3fb5
3
+ metadata.gz: 55db3e9b61e8ee1c813e313789222cc2e083f59c1070c12801cd3afd5eaf6fe6
4
+ data.tar.gz: d2d4420c40bd39e551a79a9b1ad42386f8d8ab4e9560ad8ad287909fc1a5633a
5
5
  SHA512:
6
- metadata.gz: 31db7b1c31b0f1329342162cb8f868e46d14e703df5dd36898dfeb74281d674bc0f7ba0b9b367d8568f0751c09f3a219dec172ed87cc8cc4d906606550492034
7
- data.tar.gz: 7090942000722ce81b302237a6b71850ef8a8ec477ded927bb5914f1e198552512ae11b0b1f46d38dd44ae0d6b4a2b1e7d34dab3ec35ea107b800c38e60c7a94
6
+ metadata.gz: 7aa9f93ea36aeef350308adcec126812a8e5438a95d5e305d79ca6e993f27ffbf7f27908fd4ead9fa0b3659f10f29db263b31b97c5a86fb1f689c401913401eb
7
+ data.tar.gz: c9267d2eb5e5329d7af59eca2507663bf85e4716f2dda4089946c86bd0da8f2848e4069e298e4a9a58eba4a89da203fd7116226f546ab2bf531ad0cc04ce3526
data/README.md CHANGED
@@ -8,7 +8,7 @@ Fast, precise, and developer-friendly money handling for Ruby.
8
8
 
9
9
  **Tired of floating-point errors in financial calculations?** Minting uses Rational numbers for perfect precision.
10
10
 
11
- **Need performance?** Minting is 2x faster than alternatives.
11
+ **Need performance?** Minting is faster than alternatives for high-volume operations (often 10×+ for formatting). See the [Performance](#performance) section for full benchmarks.
12
12
 
13
13
  **Want a clean API?** Minting provides an intuitive interface with helpful error messages.
14
14
 
@@ -87,15 +87,30 @@ price.to_s(format: ' %<amount>10f %<currency>s') #=> " 9.99 USD"
87
87
 
88
88
  price_in_euros.to_s(format: '%<symbol>2s%<amount>+10f') #=> " € +12.34"
89
89
 
90
+ # Per-sign Hash format (e.g. accounting parentheses for losses)
91
+ loss = Mint.money(-1234.56, 'USD')
92
+ loss.to_s(format: { negative: '(%<symbol>s%<amount>f)' }) #=> "($1,234.56)"
93
+ Mint.money(0, 'BRL').to_s(format: { zero: '--' }) #=> "--"
94
+ # All three keys at once:
95
+ fmt = { positive: '%<symbol>s%<amount>f', negative: '(%<symbol>s%<amount>f)', zero: '--' }
96
+ Mint.money(1234.56, 'USD').to_s(format: fmt) #=> "$1,234.56"
97
+
90
98
  # Json serialization
91
99
 
92
- price.to_json # => "{ "currency": "USD", "amount": "9.99" }"
100
+ price.to_json # => "{\"currency\": \"USD\", \"amount\": \"9.99\"}"
93
101
 
94
102
  # Hash conversion
95
103
 
96
104
  price.to_hash #=> {currency: "USD", amount: "9.99"}
97
105
 
98
106
 
107
+ # Fractional units (inverse of #fractional) - exact integer arithmetic
108
+
109
+ price.fractional #=> 999
110
+ Mint::Money.from_fractional(999, 'USD') #=> [USD 9.99]
111
+ Mint::Money.from_fractional(1234, 'JPY') #=> [JPY 1234] # subunit 0 -> no scaling
112
+
113
+
99
114
  # Proportional allocation and split
100
115
 
101
116
  ten.split(3) #=> [[USD 3.34], [USD 3.33], [USD 3.33]]
data/Rakefile CHANGED
@@ -44,9 +44,9 @@ end
44
44
  RuboCop::RakeTask.new(:cop)
45
45
 
46
46
  YARD::Rake::YardocTask.new do |t|
47
- t.files = ['lib/**/*.rb'] # optional
48
- t.options = [] # optional
49
- t.stats_options = ['--list-undoc'] # optional
47
+ t.files = ['lib/**/*.rb']
48
+ t.options = ['-o doc/api'] # Place the documentos in doc/api
49
+ t.stats_options = ['--list-undoc']
50
50
  end
51
51
 
52
52
  task default: :test