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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a027eb400724db0164db62cc9d76ce371b73a538d4b5713f85a917b31c43330a
4
- data.tar.gz: cf7bb6b476300f02f39992dab1e7ecbff9e7d14974dbf8c33fc89dd1c093e20e
3
+ metadata.gz: 531ae60785c01288f3c5b6ffe222c86582c49e368770e8ac1dc89bfae675f279
4
+ data.tar.gz: 3fd0d185d01ed315ea0bd5e89f8c923d5d1712ec571041cd678a7749fbf3ab44
5
5
  SHA512:
6
- metadata.gz: 9274bdfeb0ffdb3a8e22366a71d02265008bdabcf18abdbc68ec70c4e92768e1c9fdbb58bd243c2f3ad8e3094f3e5cfc45e876756a9a93720a428cc0a42210a1
7
- data.tar.gz: d0647ee4aa7e9f28dc5cc6d7698639830edabff5b4a0b14c108f55f4bd6a8004e603dccfdcb934c5d404a670f4baf7e2269440643a586bab1c6e2dc71314b7b7
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
- ## Why Minting?
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
- ### Blazing performance
38
- Minting is **2× 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).
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
- ### 🧼 Clean, modern API
30
+ ### Clean, modern API
41
31
  Intuitive interface, descriptive error messages, and sensible defaults. Works the way you expect.
42
32
 
43
- ### 🚆 Rails-ready
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
- ### 🏆 Quality you can trust
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/**/*_benchmark.rb'
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
- Rake::TestTask.new('bench:competitive') do |t|
38
- t.libs = %w[lib test]
39
- t.pattern = 'test/performance/competitive/**/*_benchmark.rb'
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'
@@ -873,7 +873,7 @@
873
873
  priority: 1
874
874
  - code: XXX
875
875
  country: null
876
- subunit: 0
876
+ subunit: 4
877
877
  symbol: ¤
878
878
  name: No Currency
879
879
  priority: 0
@@ -991,4 +991,3 @@
991
991
  symbol: SDR
992
992
  name: Special Drawing Rights
993
993
  priority: 0
994
-
@@ -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.money(self, 'BRL')
7
+ def reais = Mint::Money.from(self, 'BRL')
8
8
 
9
9
  # @return [Money] self interpreted as USD
10
- def dollars = Mint.money(self, 'USD')
10
+ def dollars = Mint::Money.from(self, 'USD')
11
11
 
12
12
  # @return [Money] self interpreted as EUR
13
- def euros = Mint.money(self, 'EUR')
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.money(self, currency)
17
+ def to_money(currency) = Mint::Money.from(self, currency)
18
18
 
19
19
  alias_method :dollar, :dollars
20
20
  alias_method :euro, :euros
@@ -7,6 +7,6 @@ module Mint
7
7
  #
8
8
  # @param currency [String, Symbol, Currency] target currency
9
9
  # @return [Money]
10
- def to_money(currency) = Mint.money(to_r, currency)
10
+ def to_money(currency) = Mint::Money.from(to_r, currency)
11
11
  end
12
12
  end
@@ -13,7 +13,7 @@ module Mint
13
13
 
14
14
  MUTEX.synchronize do
15
15
  @zeros ||= {}
16
- @zeros[currency] ||= Mint::Money.send(:new, 0, currency)
16
+ @zeros[currency] ||= Mint::Money.send(:new, 0r, currency)
17
17
  end
18
18
  end
19
19
  end
@@ -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.
@@ -3,5 +3,5 @@
3
3
  # Root namespace for the Minting library.
4
4
  module Minting
5
5
  # Current version of the Minting gem.
6
- VERSION = '1.8.0'
6
+ VERSION = '1.8.2'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minting
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilson Ferraz