money_helper 3.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fc38d5c4921667c0f06286f5058378d60658b3f991dd7a343f5ab597384560c
4
- data.tar.gz: c88db16a193d5674d9f902466aace23c8b7b1a0f71b89733589a05be7059049b
3
+ metadata.gz: bb985ae46b6f1d331cdb546b36399e4fc2feb0c8124386c8caf6d928cb219d85
4
+ data.tar.gz: a76132d24051dcd2a01e56562f85062fa1a1d7f2e90478c99ae2ed84d755f243
5
5
  SHA512:
6
- metadata.gz: 1c258cca4d8ac444695faedd9245d1f805bcb5534bcf6f864dffdcfe330bf8f54f6c10caf800e32c1c2621bc523f6277acde3821a16c6a11edf31b777cdbdc6b
7
- data.tar.gz: 8133b959081243c17b6d160ec72a802ed79648989c60ebaca8546a8509cc145b1148f89de4cc1e4ee89cc51459cc0e54fcf58f29a7d5fd412b4f1a93a85744fa
6
+ metadata.gz: 65875f337079054720b379eb8201b6c2a37168aafa60034f76e9dbf43e062cacb43c1bdf4a4e174a03a44692a64c73c676a11359f4b54766d48f15d835216301
7
+ data.tar.gz: 3f9168ad1f54e3d3b4ad333596b79de2a875cd2d1aa039ea1c2a185971b8636ff8446ba2223958104f3b4846927e928be627f4134e48c3f828f91b13c4c16998
data/Appraisals CHANGED
@@ -13,7 +13,7 @@ appraise 'activesupport_61' do
13
13
  end
14
14
 
15
15
  appraise 'activesupport_edge' do
16
- git 'git://github.com/rails/rails.git' do
16
+ git 'https://github.com/rails/rails.git', branch: 'main' do
17
17
  gem 'activesupport', require: 'active_support'
18
18
  end
19
19
  end
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
1
- ### 3.0.0 (Next)
1
+ ### X.X.X (Next)
2
2
 
3
- * [#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).
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).
10
+
11
+ ### 3.0.0 (2022-02-16)
12
+
13
+ * [#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).
5
14
 
6
15
  ### 2.0.0 (2021-09-20)
7
16
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  source 'http://rubygems.org'
6
6
 
7
- git 'git://github.com/rails/rails.git' do
7
+ git 'https://github.com/rails/rails.git', branch: 'main' do
8
8
  gem 'activesupport', require: 'active_support'
9
9
  end
10
10
 
data/lib/money_helper.rb CHANGED
@@ -70,18 +70,22 @@ 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
- def self.money_range_to_text(low, high, currency: 'USD', delimiter: ' - ')
73
+ # with_currency: (Boolean) optional flag to include ISO currency code, defaulting to true
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: {})
74
78
  if low.blank? && high.blank?
75
79
  ''
76
80
  elsif low.blank?
77
- "Under #{money_to_text(high, currency: currency)}"
81
+ "Under #{money_to_text(high, currency: currency, with_currency: with_currency, format: format)}"
78
82
  elsif high.blank?
79
- "#{money_to_text(low, currency: currency)} and up"
83
+ "#{money_to_text(low, currency: currency, with_currency: with_currency, format: format)} and up"
80
84
  elsif low == high
81
- money_to_text(low, currency: currency)
85
+ money_to_text(low, currency: currency, with_currency: with_currency, format: format)
82
86
  else
83
- formatted_low = money_to_text(low, currency: currency)
84
- 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))
85
89
  [formatted_low, formatted_high].compact.join(delimiter)
86
90
  end
87
91
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MoneyHelper
4
- VERSION = '3.0.0'
4
+ VERSION = '3.0.2'
5
5
  end
@@ -205,18 +205,49 @@ 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
+
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
+
220
251
  it "raises an exception when currency can't be found" do
221
252
  expect do
222
253
  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.0
4
+ version: 3.0.2
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: 2022-02-16 00:00:00.000000000 Z
14
+ date: 2023-03-22 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.27
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: