money_helper 3.0.1 → 3.0.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/CHANGELOG.md +7 -2
- data/lib/money_helper.rb +9 -6
- data/lib/version.rb +1 -1
- data/spec/money_helper_spec.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb985ae46b6f1d331cdb546b36399e4fc2feb0c8124386c8caf6d928cb219d85
|
4
|
+
data.tar.gz: a76132d24051dcd2a01e56562f85062fa1a1d7f2e90478c99ae2ed84d755f243
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65875f337079054720b379eb8201b6c2a37168aafa60034f76e9dbf43e062cacb43c1bdf4a4e174a03a44692a64c73c676a11359f4b54766d48f15d835216301
|
7
|
+
data.tar.gz: 3f9168ad1f54e3d3b4ad333596b79de2a875cd2d1aa039ea1c2a185971b8636ff8446ba2223958104f3b4846927e928be627f4134e48c3f828f91b13c4c16998
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
###
|
1
|
+
### X.X.X (Next)
|
2
2
|
|
3
|
-
* [#29](https://github.com/artsy/money_helper/pull/29): Update `money_range_to_text` to receive `with_currency` parameter for optional ISO code printing - [@leamotta](https://github.com/leamotta).
|
4
3
|
* Your contribution here.
|
4
|
+
### 3.0.2 (2023-03-22)
|
5
|
+
|
6
|
+
* [#30](https://github.com/artsy/money_helper/pull/30): Update `money_range_to_text` to receive `format` parameter for optional formatting - [@leamotta](https://github.com/leamotta).
|
7
|
+
### 3.0.1 (2023-03-21)
|
8
|
+
|
9
|
+
* [#29](https://github.com/artsy/money_helper/pull/29): Update `money_range_to_text` to receive `with_currency` parameter for optional ISO code printing - [@leamotta](https://github.com/leamotta).
|
5
10
|
|
6
11
|
### 3.0.0 (2022-02-16)
|
7
12
|
|
data/lib/money_helper.rb
CHANGED
@@ -71,18 +71,21 @@ module MoneyHelper
|
|
71
71
|
# currency: (String) optional ISO currency code, defaulting to USD
|
72
72
|
# delimiter: (String) optional
|
73
73
|
# with_currency: (Boolean) optional flag to include ISO currency code, defaulting to true
|
74
|
-
|
74
|
+
# format: (Hash) optional formatting options to pass to `Money#format` e.g.:
|
75
|
+
# no_cents: (Boolean) optional flag to exclude cents, defaulting to false
|
76
|
+
# symbol: (Boolean) optional flag to include currency symbol, defaulting to true
|
77
|
+
def self.money_range_to_text(low, high, currency: 'USD', delimiter: ' - ', with_currency: true, format: {})
|
75
78
|
if low.blank? && high.blank?
|
76
79
|
''
|
77
80
|
elsif low.blank?
|
78
|
-
"Under #{money_to_text(high, currency: currency, with_currency: with_currency)}"
|
81
|
+
"Under #{money_to_text(high, currency: currency, with_currency: with_currency, format: format)}"
|
79
82
|
elsif high.blank?
|
80
|
-
"#{money_to_text(low, currency: currency, with_currency: with_currency)} and up"
|
83
|
+
"#{money_to_text(low, currency: currency, with_currency: with_currency, format: format)} and up"
|
81
84
|
elsif low == high
|
82
|
-
money_to_text(low, currency: currency, with_currency: with_currency)
|
85
|
+
money_to_text(low, currency: currency, with_currency: with_currency, format: format)
|
83
86
|
else
|
84
|
-
formatted_low = money_to_text(low, currency: currency, with_currency: with_currency)
|
85
|
-
formatted_high = money_to_text(high, currency: currency, with_currency: false, format: { symbol: false })
|
87
|
+
formatted_low = money_to_text(low, currency: currency, with_currency: with_currency, format: format)
|
88
|
+
formatted_high = money_to_text(high, currency: currency, with_currency: false, format: { symbol: false }.merge(format))
|
86
89
|
[formatted_low, formatted_high].compact.join(delimiter)
|
87
90
|
end
|
88
91
|
end
|
data/lib/version.rb
CHANGED
data/spec/money_helper_spec.rb
CHANGED
@@ -235,6 +235,19 @@ describe MoneyHelper do
|
|
235
235
|
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AMD', with_currency: false)).to eql('դր.30,175.93 - 40,983.27')
|
236
236
|
end
|
237
237
|
|
238
|
+
it 'omits cents when `format: no_cents:` is true' do
|
239
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, with_currency: false, format: { no_cents: true })).to eql('$30,175 - 40,983')
|
240
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'EUR', with_currency: false, format: { no_cents: true })).to eql('€30.175 - 40.983')
|
241
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 30_175_93, currency: 'EUR', with_currency: false, format: { no_cents: true })).to eql('€30.175')
|
242
|
+
expect(MoneyHelper.money_range_to_text(nil, 30_175_93, currency: 'EUR', with_currency: false, format: { no_cents: true })).to eql('Under €30.175')
|
243
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, nil, currency: 'EUR', with_currency: false, format: { no_cents: true })).to eql('€30.175 and up')
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'omits cents when `format: no_cents:` is true, omits symbol when `format: symbol:` is false' do
|
247
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, with_currency: false, format: { no_cents: true, symbol: false })).to eql('30,175 - 40,983')
|
248
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'EUR', with_currency: false, format: { no_cents: true, symbol: false })).to eql('30.175 - 40.983')
|
249
|
+
end
|
250
|
+
|
238
251
|
it "raises an exception when currency can't be found" do
|
239
252
|
expect do
|
240
253
|
MoneyHelper.money_range_to_text(10_000, 20_000, currency: 'ITL')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sahil Yakhmi
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2023-03-
|
14
|
+
date: 2023-03-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|