money_helper 3.0.0 → 3.0.1
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/Appraisals +1 -1
- data/CHANGELOG.md +6 -2
- data/gemfiles/activesupport_edge.gemfile +1 -1
- data/lib/money_helper.rb +6 -5
- data/lib/version.rb +1 -1
- data/spec/money_helper_spec.rb +18 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 655460145cd04f3561bb2e212287b760bb0dd93c4eb97c5533a2d40b4aff8482
|
4
|
+
data.tar.gz: 904a30dd0a437daf2f93d411a3d65e456e41420af74943d716729594905df180
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3cd552b0e52f2d0ff8fc2456598aa19931932609f46eaa89e896e08e5744f00279627cd58531c9113fc236bc457af6fa5101a38ea55206168e1a33e58f8c684
|
7
|
+
data.tar.gz: 4c1298bd61b4121c8e652afda3c4f4a7247bcd790a1450927b96d7cbe3c82aee73bcb4f971647be98e7aa83f15e842b4b3dccc0ac936dd6d49f61e54705cedc6
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
### 3.0.
|
1
|
+
### 3.0.1 (Next)
|
2
2
|
|
3
|
-
* [#
|
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
4
|
* Your contribution here.
|
5
5
|
|
6
|
+
### 3.0.0 (2022-02-16)
|
7
|
+
|
8
|
+
* [#27](https://github.com/artsy/money_helper/pull/27): Update `money_to_text` to pass `format` options to `Money#format` for additional features such as `no_cents` - [@agrberg](https://github.com/agrberg).
|
9
|
+
|
6
10
|
### 2.0.0 (2021-09-20)
|
7
11
|
|
8
12
|
#### Breaking Changes
|
data/lib/money_helper.rb
CHANGED
@@ -70,17 +70,18 @@ module MoneyHelper
|
|
70
70
|
# high: (Integer) amount in minor unit
|
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
|
+
def self.money_range_to_text(low, high, currency: 'USD', delimiter: ' - ', with_currency: true)
|
74
75
|
if low.blank? && high.blank?
|
75
76
|
''
|
76
77
|
elsif low.blank?
|
77
|
-
"Under #{money_to_text(high, currency: currency)}"
|
78
|
+
"Under #{money_to_text(high, currency: currency, with_currency: with_currency)}"
|
78
79
|
elsif high.blank?
|
79
|
-
"#{money_to_text(low, currency: currency)} and up"
|
80
|
+
"#{money_to_text(low, currency: currency, with_currency: with_currency)} and up"
|
80
81
|
elsif low == high
|
81
|
-
money_to_text(low, currency: currency)
|
82
|
+
money_to_text(low, currency: currency, with_currency: with_currency)
|
82
83
|
else
|
83
|
-
formatted_low = money_to_text(low, currency: currency)
|
84
|
+
formatted_low = money_to_text(low, currency: currency, with_currency: with_currency)
|
84
85
|
formatted_high = money_to_text(high, currency: currency, with_currency: false, format: { symbol: false })
|
85
86
|
[formatted_low, formatted_high].compact.join(delimiter)
|
86
87
|
end
|
data/lib/version.rb
CHANGED
data/spec/money_helper_spec.rb
CHANGED
@@ -205,18 +205,36 @@ describe MoneyHelper do
|
|
205
205
|
expect(MoneyHelper.money_range_to_text(nil, 40_983_27, currency: 'USD')).to eql('Under USD $40,983.27')
|
206
206
|
end
|
207
207
|
|
208
|
+
it "prefixes the text 'Under ' when low amount not given and omits ISO code when with_currency is false" do
|
209
|
+
expect(MoneyHelper.money_range_to_text(nil, 40_983_27, currency: 'USD', with_currency: false)).to eql('Under $40,983.27')
|
210
|
+
end
|
211
|
+
|
208
212
|
it "appends the text ' and up' when high amount not given" do
|
209
213
|
expect(MoneyHelper.money_range_to_text(30_175_93, nil, currency: 'USD')).to eql('USD $30,175.93 and up')
|
210
214
|
end
|
211
215
|
|
216
|
+
it "appends the text ' and up' when high amount not given and omits ISO code when with_currency is false" do
|
217
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, nil, currency: 'USD', with_currency: false)).to eql('$30,175.93 and up')
|
218
|
+
end
|
219
|
+
|
212
220
|
it 'treats as a single price when low amount and high amount are identical' do
|
213
221
|
expect(MoneyHelper.money_range_to_text(30_175_93, 30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
214
222
|
end
|
215
223
|
|
224
|
+
it 'treats as a single price when low amount and high amount are identical and omits ISO code when with_currency is false' do
|
225
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 30_175_93, currency: 'USD', with_currency: false)).to eql('$30,175.93')
|
226
|
+
end
|
227
|
+
|
216
228
|
it 'returns empty string when both amounts are nil' do
|
217
229
|
expect(MoneyHelper.money_range_to_text(nil, nil, currency: 'USD')).to eql('')
|
218
230
|
end
|
219
231
|
|
232
|
+
it 'omits ISO code when with_currency is false' do
|
233
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'EUR', with_currency: false)).to eql('€30.175,93 - 40.983,27')
|
234
|
+
expect(MoneyHelper.money_range_to_text(30_175_93, 40_983_27, currency: 'AUD', with_currency: false)).to eql('$30,175.93 - 40,983.27')
|
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
|
+
end
|
237
|
+
|
220
238
|
it "raises an exception when currency can't be found" do
|
221
239
|
expect do
|
222
240
|
MoneyHelper.money_range_to_text(10_000, 20_000, currency: 'ITL')
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sahil Yakhmi
|
8
8
|
- Joey Aghion
|
9
9
|
- Matt Zikherman
|
10
10
|
- Sarah Weir
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2023-03-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -102,7 +102,7 @@ homepage: https://github.com/artsy/money_helper
|
|
102
102
|
licenses:
|
103
103
|
- MIT
|
104
104
|
metadata: {}
|
105
|
-
post_install_message:
|
105
|
+
post_install_message:
|
106
106
|
rdoc_options: []
|
107
107
|
require_paths:
|
108
108
|
- lib
|
@@ -117,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: 1.3.6
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.2
|
121
|
-
signing_key:
|
120
|
+
rubygems_version: 3.1.2
|
121
|
+
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: MoneyHelper international price formatting utility.
|
124
124
|
test_files:
|