minting 1.8.0 → 1.8.2
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 +12 -16
- data/Rakefile +15 -4
- data/lib/minting/data/world-currencies.yaml +1 -2
- data/lib/minting/mint/dsl/numeric.rb +4 -4
- data/lib/minting/mint/dsl/string.rb +1 -1
- data/lib/minting/mint/registry/zeros.rb +1 -1
- data/lib/minting/money/constructors.rb +9 -0
- data/lib/minting/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 531ae60785c01288f3c5b6ffe222c86582c49e368770e8ac1dc89bfae675f279
|
|
4
|
+
data.tar.gz: 3fd0d185d01ed315ea0bd5e89f8c923d5d1712ec571041cd678a7749fbf3ab44
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e0799f5c93aac8f065d1b213e848d4ec650278b93e475431ca7c6f71cc69cece2525c51fa4b7d2a54e6317f27befb68cfbf362b3c74960ce51a962cd0178d86c
|
|
7
|
+
data.tar.gz: ae2121c6b9d7115b3ef40dbef4761ac0257cfea1770141543c87c741c0c49f8e5d60ef95970042dffe895ec948cc5c1dbf6ccf644aa34f401407003303c10744
|
data/README.md
CHANGED
|
@@ -21,29 +21,19 @@ total.to_s #=> "$21.59"
|
|
|
21
21
|
total.currency_code #=> "USD"
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
| | Minting |
|
|
27
|
-
|--------------------|-------------------------------------------|
|
|
28
|
-
| **Precision** | Rational-based, zero floating-point error |
|
|
29
|
-
| **Performance** | **2× faster** (10×+ formatting) |
|
|
30
|
-
| **Ruby support** | 3.3+ (including Ruby 4.0) |
|
|
31
|
-
| **Rails** | Dedicated companion gem |
|
|
32
|
-
| **Code quality** | 100% coverage, 93/100 RubyCritic |
|
|
33
|
-
|
|
34
|
-
### 🎯 Exact precision
|
|
24
|
+
### Exact precision
|
|
35
25
|
Amounts are stored as `Rational` and rounded to the currency subunit. No floating-point surprises, ever.
|
|
36
26
|
|
|
37
|
-
###
|
|
38
|
-
Minting is
|
|
27
|
+
### Blazing performance
|
|
28
|
+
Minting is faster than the Money gem for everyday operations and **over 10× faster for formatting**. See full benchmarks in the [Performance Guide](test/performance/README.md).
|
|
39
29
|
|
|
40
|
-
###
|
|
30
|
+
### Clean, modern API
|
|
41
31
|
Intuitive interface, descriptive error messages, and sensible defaults. Works the way you expect.
|
|
42
32
|
|
|
43
|
-
###
|
|
33
|
+
### Rails-ready
|
|
44
34
|
Use with the [minting-rails](https://github.com/gferraz/minting-rails) companion gem for drop-in ActiveRecord type casting, validators, and form helpers.
|
|
45
35
|
|
|
46
|
-
###
|
|
36
|
+
### Quality code
|
|
47
37
|
- **100% test coverage** — every line exercised
|
|
48
38
|
- **93/100 RubyCritic score** — clean, maintainable code
|
|
49
39
|
- **CI-tested on Ruby 3.3 and 4.0**
|
|
@@ -131,6 +121,12 @@ Mint::Money.from_fractional(999, 'USD') #=> [USD 9.99]
|
|
|
131
121
|
Mint::Money.from_fractional(1234, 'JPY') #=> [JPY 1234] # subunit 0 -> no scaling
|
|
132
122
|
|
|
133
123
|
|
|
124
|
+
# No currency (ISO 4217 XXX)
|
|
125
|
+
|
|
126
|
+
Mint::Money.no_currency(100) #=> [XXX 100]
|
|
127
|
+
Mint::Money.no_currency(0) #=> [XXX 0]
|
|
128
|
+
|
|
129
|
+
|
|
134
130
|
# Proportional allocation and split
|
|
135
131
|
|
|
136
132
|
ten.split(3) #=> [[USD 3.34], [USD 3.33], [USD 3.33]]
|
data/Rakefile
CHANGED
|
@@ -16,7 +16,7 @@ end
|
|
|
16
16
|
|
|
17
17
|
Rake::TestTask.new('bench:all') do |t|
|
|
18
18
|
t.libs = %w[lib test]
|
|
19
|
-
t.pattern = 'test/performance
|
|
19
|
+
t.pattern = 'test/performance/{core,memory,regression,competitive/money}/*_benchmark.rb'
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
Rake::TestTask.new('bench:core') do |t|
|
|
@@ -34,9 +34,20 @@ Rake::TestTask.new('bench:regression') do |t|
|
|
|
34
34
|
t.pattern = 'test/performance/regression/*_benchmark.rb'
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
desc 'Run competitive benchmarks (Money gem)'
|
|
38
|
+
task 'bench:competitive' do
|
|
39
|
+
sh 'bundle exec ruby -Ilib -Itest -e "Dir[File.join(__dir__, \"test/performance/competitive/money/**/*_benchmark.rb\")].each { |f| require f }"'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
desc 'Run competitive benchmarks (Shopify Money)'
|
|
43
|
+
task 'bench:competitive:shopify' do
|
|
44
|
+
sh 'BUNDLE_WITHOUT=money_bench bundle exec ruby -Ilib -Itest -e "Dir[File.join(__dir__, \"test/performance/competitive/shopify/**/*_benchmark.rb\")].each { |f| require f }"'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
desc 'Run all competitive benchmarks (both Money and Shopify)'
|
|
48
|
+
task 'bench:competitive:all' do
|
|
49
|
+
sh 'bundle exec ruby -Ilib -Itest -e "Dir[File.join(__dir__, \"test/performance/competitive/money/**/*_benchmark.rb\")].each { |f| require f }"'
|
|
50
|
+
sh 'BUNDLE_WITHOUT=money_bench bundle exec ruby -Ilib -Itest -e "Dir[File.join(__dir__, \"test/performance/competitive/shopify/**/*_benchmark.rb\")].each { |f| require f }"'
|
|
40
51
|
end
|
|
41
52
|
|
|
42
53
|
desc 'Run core benchmarks and update the baseline'
|
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
module Mint
|
|
5
5
|
refine Numeric do
|
|
6
6
|
# @return [Money] self interpreted as BRL
|
|
7
|
-
def reais = Mint.
|
|
7
|
+
def reais = Mint::Money.from(self, 'BRL')
|
|
8
8
|
|
|
9
9
|
# @return [Money] self interpreted as USD
|
|
10
|
-
def dollars = Mint.
|
|
10
|
+
def dollars = Mint::Money.from(self, 'USD')
|
|
11
11
|
|
|
12
12
|
# @return [Money] self interpreted as EUR
|
|
13
|
-
def euros = Mint.
|
|
13
|
+
def euros = Mint::Money.from(self, 'EUR')
|
|
14
14
|
|
|
15
15
|
# @param currency [String, Symbol, Currency] target currency
|
|
16
16
|
# @return [Money] self interpreted as the given currency
|
|
17
|
-
def to_money(currency) = Mint.
|
|
17
|
+
def to_money(currency) = Mint::Money.from(self, currency)
|
|
18
18
|
|
|
19
19
|
alias_method :dollar, :dollars
|
|
20
20
|
alias_method :euro, :euros
|
|
@@ -16,6 +16,15 @@ module Mint
|
|
|
16
16
|
amount.zero? ? currency.zero : new(amount, currency)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
# Creates a new Money without a currency (ISO 4217 XXX — "No Currency").
|
|
20
|
+
#
|
|
21
|
+
# @param amount [Numeric] The monetary amount
|
|
22
|
+
# @return [Money] a Money instance with the XXX currency
|
|
23
|
+
# @raise [ArgumentError] If amount is not numeric
|
|
24
|
+
# @example
|
|
25
|
+
# Money.no_currency(100) #=> [XXX 100]
|
|
26
|
+
def self.no_currency(amount) = from(amount, 'XXX')
|
|
27
|
+
|
|
19
28
|
# Parses a human-readable money string into a {Money} object.
|
|
20
29
|
#
|
|
21
30
|
# Returns +nil+ when the input is invalid or currency cannot be determined.
|
data/lib/minting/version.rb
CHANGED