money_helper 2.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +2 -4
- data/.rubocop.yml +7 -5
- data/.rubocop_todo.yml +6 -4
- data/Appraisals +8 -18
- data/CHANGELOG.md +6 -1
- data/Gemfile +4 -1
- data/README.md +2 -2
- data/Rakefile +2 -0
- data/UPGRADING.md +44 -0
- data/gemfiles/activesupport_52.gemfile +4 -2
- data/gemfiles/{activesupport_40.gemfile → activesupport_60.gemfile} +4 -2
- data/gemfiles/{activesupport_41.gemfile → activesupport_61.gemfile} +4 -2
- data/gemfiles/activesupport_edge.gemfile +4 -2
- data/lib/money_helper.rb +15 -13
- data/lib/version.rb +3 -1
- data/money_helper.gemspec +2 -0
- data/spec/money_helper_spec.rb +35 -10
- data/spec/spec_helper.rb +2 -0
- data/spec/version_spec.rb +2 -0
- metadata +9 -11
- data/gemfiles/activesupport_42.gemfile +0 -8
- data/gemfiles/activesupport_50.gemfile +0 -8
- data/gemfiles/activesupport_51.gemfile +0 -8
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/.circleci/config.yml
CHANGED
@@ -38,10 +38,8 @@ workflows:
|
|
38
38
|
- test:
|
39
39
|
matrix:
|
40
40
|
parameters:
|
41
|
-
ruby_version: ["2.
|
42
|
-
activesupport_version: ["
|
41
|
+
ruby_version: ["2.6", "2.7", "3.0"]
|
42
|
+
activesupport_version: ["52", "60", "61", "edge"]
|
43
43
|
exclude:
|
44
|
-
- ruby_version: "2.5"
|
45
|
-
activesupport_version: "edge"
|
46
44
|
- ruby_version: "2.6"
|
47
45
|
activesupport_version: "edge"
|
data/.rubocop.yml
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
1
3
|
AllCops:
|
2
4
|
Exclude:
|
3
5
|
- vendor/**/*
|
4
6
|
- gemfiles/vendor/**/*
|
7
|
+
NewCops: enable
|
8
|
+
SuggestExtensions: false
|
9
|
+
|
10
|
+
Layout/LineLength:
|
11
|
+
Max: 512
|
5
12
|
|
6
13
|
Metrics:
|
7
14
|
Enabled: false
|
8
15
|
|
9
|
-
Metrics/LineLength:
|
10
|
-
Max: 512
|
11
|
-
|
12
16
|
Style/Documentation:
|
13
17
|
Enabled: false
|
14
18
|
|
@@ -17,5 +21,3 @@ Naming/MethodName:
|
|
17
21
|
|
18
22
|
Style/AsciiComments:
|
19
23
|
Enabled: false
|
20
|
-
|
21
|
-
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2021-09-21 17:26:48 UTC using RuboCop version 1.21.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
10
|
-
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
11
13
|
Exclude:
|
12
|
-
- '
|
14
|
+
- 'money_helper.gemspec'
|
data/Appraisals
CHANGED
@@ -1,29 +1,19 @@
|
|
1
|
-
|
2
|
-
gem 'activesupport', '~> 4.0.0'
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise 'activesupport_41' do
|
6
|
-
gem 'activesupport', '~> 4.1.0'
|
7
|
-
end
|
1
|
+
# frozen_string_literal: true
|
8
2
|
|
9
|
-
appraise '
|
10
|
-
gem 'activesupport', '~>
|
11
|
-
end
|
12
|
-
|
13
|
-
appraise 'activesupport_50' do
|
14
|
-
gem 'activesupport', '~> 5.0.0'
|
3
|
+
appraise 'activesupport_52' do
|
4
|
+
gem 'activesupport', '~> 5.2.6'
|
15
5
|
end
|
16
6
|
|
17
|
-
appraise '
|
18
|
-
gem 'activesupport', '~>
|
7
|
+
appraise 'activesupport_60' do
|
8
|
+
gem 'activesupport', '~> 6.0.4'
|
19
9
|
end
|
20
10
|
|
21
|
-
appraise '
|
22
|
-
gem 'activesupport', '~>
|
11
|
+
appraise 'activesupport_61' do
|
12
|
+
gem 'activesupport', '~> 6.1.4'
|
23
13
|
end
|
24
14
|
|
25
15
|
appraise 'activesupport_edge' do
|
26
|
-
git '
|
16
|
+
git 'https://github.com/rails/rails.git', branch: 'main' do
|
27
17
|
gem 'activesupport', require: 'active_support'
|
28
18
|
end
|
29
19
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
###
|
1
|
+
### 3.0.1 (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).
|
3
4
|
* Your contribution here.
|
4
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
|
+
|
5
10
|
### 2.0.0 (2021-09-20)
|
6
11
|
|
7
12
|
#### Breaking Changes
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -39,8 +39,8 @@ MIT License, see [LICENSE][license] for details.
|
|
39
39
|
|
40
40
|
(c) 2013-2018 [Artsy][artsy], [Sahil Yakhmi][sahil_yakhmi], [Joey Aghion][joey_aghion] and [contributors][contributors].
|
41
41
|
|
42
|
-
[ci_badge]: https://circleci.com/gh/artsy/money_helper/tree/
|
43
|
-
[circleci]: https://circleci.com/gh/artsy/money_helper/tree/
|
42
|
+
[ci_badge]: https://circleci.com/gh/artsy/money_helper/tree/main.svg?style=svg
|
43
|
+
[circleci]: https://circleci.com/gh/artsy/money_helper/tree/main
|
44
44
|
[#16]: https://github.com/artsy/money_helper/pull/16
|
45
45
|
[license]: LICENSE.md
|
46
46
|
[artsy]: https://github.com/artsy
|
data/Rakefile
CHANGED
data/UPGRADING.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Upgrading MoneyHelper
|
2
|
+
=====================
|
3
|
+
|
4
|
+
### Upgrading to >= 3.0.0
|
5
|
+
|
6
|
+
#### `money_to_text` format options
|
7
|
+
|
8
|
+
Prior to 3.0.0 `money_to_text` took a named argument `with_symbol`. The default value was `true` and assing `false` would omit the currency symbol.
|
9
|
+
|
10
|
+
This data was later passed to the `Money#format` method with a default `format` string of `'%u%n'`. Users of `MoneyHelper` could not modify the format string or utilize additional format options, such as `no_cents: false`.
|
11
|
+
|
12
|
+
In 3.0.0 this was changed so `money_to_text` can take an optional `format` argument which is eventually passed to `Money#format` with only the slight modification of adding in `format: '%u%n'` if this key is not present.
|
13
|
+
|
14
|
+
### Upgrading to >= 2.0.0
|
15
|
+
|
16
|
+
#### `money_to_text` amount is now given in minor units
|
17
|
+
|
18
|
+
Prior to 2.0.0 `money_to_text` took an amount in a currency's major units and converted this value internally before passing to `Money#new` which expects values in their minor unit (i.e. For USD the major unit is Dollars and the minor unit is Cents). This version removes the autoscaling so `money_to_text` can take amounts in their minor units.
|
19
|
+
|
20
|
+
Additionally, `currency`, `number_only`, and `options` were removed as postional arguments and replaced with named arguments `currency`, `with_currency`, and `with_symbol` with `'USD'`, `true` and `true` as their default arguments respectively.
|
21
|
+
|
22
|
+
One minor difference is that `currency` can be omited completely where as in < 2.0.0 `''` or `nil` was required to be passed for the default of `'USD'` to be used.
|
23
|
+
|
24
|
+
Finally the automatic omission of certain currency codes (USD, GBP, EUR, and MYR) is no longer supported. To replicate this behavior you must explicitly specify `with_currency: false`.
|
25
|
+
|
26
|
+
The following illustrates the primary difference in usage.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# Before 2.0.0
|
30
|
+
|
31
|
+
MoneyHelper.money_to_text(123, 'USD')
|
32
|
+
# => $123
|
33
|
+
|
34
|
+
# After 2.0.0
|
35
|
+
|
36
|
+
MoneyHelper.money_to_text(123) # `currency: 'USD'` is the default
|
37
|
+
# => USD $1.23
|
38
|
+
|
39
|
+
# to replicate previous behavior almost exactly
|
40
|
+
MoneyHelper.money_to_text(12300, with_currency: false)
|
41
|
+
# => $123.00
|
42
|
+
|
43
|
+
# Note the inclusion of the cents. The ability to remove this was added in 3.0.0 as another breaking change
|
44
|
+
```
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file was generated by Appraisal
|
2
4
|
|
3
5
|
source 'http://rubygems.org'
|
4
6
|
|
5
|
-
git '
|
7
|
+
git 'https://github.com/rails/rails.git', branch: 'main' do
|
6
8
|
gem 'activesupport', require: 'active_support'
|
7
9
|
end
|
8
10
|
|
9
|
-
gem 'rubocop', '
|
11
|
+
gem 'rubocop', '1.21.0'
|
10
12
|
|
11
13
|
gemspec path: '../'
|
data/lib/money_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'version'
|
2
4
|
|
3
5
|
require 'active_support/core_ext/object/blank'
|
@@ -27,16 +29,15 @@ module MoneyHelper
|
|
27
29
|
# amount_minor: (Integer) amount in minor unit
|
28
30
|
# currency: (String) optional ISO currency code, defaulting to USD
|
29
31
|
# with_currency: (Boolean) optional flag to include ISO currency code, defaulting to true
|
30
|
-
#
|
31
|
-
|
32
|
+
# format: (Hash) optional formatting options to pass to `Money#format` e.g.:
|
33
|
+
# no_cents: (Boolean) optional flag to exclude cents, defaulting to false
|
34
|
+
# symbol: (Boolean) optional flag to include currency symbol, defaulting to true
|
35
|
+
def self.money_to_text(amount_minor, currency: 'USD', with_currency: true, format: {})
|
32
36
|
return '' if amount_minor.blank?
|
33
37
|
|
34
|
-
|
35
|
-
format: '%u%n',
|
36
|
-
symbol: with_symbol
|
37
|
-
}
|
38
|
+
format_options = { format: '%u%n' }.merge(format)
|
38
39
|
|
39
|
-
formatted_amount = Money.new(amount_minor, currency).format(
|
40
|
+
formatted_amount = Money.new(amount_minor, currency).format(format_options)
|
40
41
|
formatted_currency = with_currency ? currency.upcase : ''
|
41
42
|
|
42
43
|
"#{formatted_currency} #{formatted_amount}".strip
|
@@ -69,18 +70,19 @@ module MoneyHelper
|
|
69
70
|
# high: (Integer) amount in minor unit
|
70
71
|
# currency: (String) optional ISO currency code, defaulting to USD
|
71
72
|
# delimiter: (String) optional
|
72
|
-
|
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)
|
73
75
|
if low.blank? && high.blank?
|
74
76
|
''
|
75
77
|
elsif low.blank?
|
76
|
-
|
78
|
+
"Under #{money_to_text(high, currency: currency, with_currency: with_currency)}"
|
77
79
|
elsif high.blank?
|
78
|
-
money_to_text(low, currency: currency
|
80
|
+
"#{money_to_text(low, currency: currency, with_currency: with_currency)} and up"
|
79
81
|
elsif low == high
|
80
|
-
money_to_text(low, currency: currency)
|
82
|
+
money_to_text(low, currency: currency, with_currency: with_currency)
|
81
83
|
else
|
82
|
-
formatted_low = money_to_text(low, currency: currency)
|
83
|
-
formatted_high = money_to_text(high, currency: currency, with_currency: false,
|
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 })
|
84
86
|
[formatted_low, formatted_high].compact.join(delimiter)
|
85
87
|
end
|
86
88
|
end
|
data/lib/version.rb
CHANGED
data/money_helper.gemspec
CHANGED
data/spec/money_helper_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe MoneyHelper do
|
@@ -137,18 +139,23 @@ describe MoneyHelper do
|
|
137
139
|
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false)).to eql('؋30,175.93')
|
138
140
|
end
|
139
141
|
|
140
|
-
it 'omits symbol when
|
141
|
-
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR',
|
142
|
-
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD',
|
143
|
-
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD',
|
144
|
-
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN',
|
142
|
+
it 'omits symbol when `format: symbol:` is false' do
|
143
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', format: { symbol: false })).to eql('EUR 30.175,93')
|
144
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', format: { symbol: false })).to eql('AUD 30,175.93')
|
145
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', format: { symbol: false })).to eql('AMD 30,175.93')
|
146
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', format: { symbol: false })).to eql('AFN 30,175.93')
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'omits ISO code and symbol when both `with_currency` and `format: symbol:` are false' do
|
150
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false, format: { symbol: false })).to eql('30.175,93')
|
151
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_currency: false, format: { symbol: false })).to eql('30,175.93')
|
152
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_currency: false, format: { symbol: false })).to eql('30,175.93')
|
153
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false, format: { symbol: false })).to eql('30,175.93')
|
145
154
|
end
|
146
155
|
|
147
|
-
it 'omits
|
148
|
-
expect(MoneyHelper.money_to_text(30_175_93,
|
149
|
-
expect(MoneyHelper.money_to_text(30_175_93, currency: '
|
150
|
-
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_currency: false, with_symbol: false)).to eql('30,175.93')
|
151
|
-
expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_currency: false, with_symbol: false)).to eql('30,175.93')
|
156
|
+
it 'omits cents when `format: no_cents:` is true' do
|
157
|
+
expect(MoneyHelper.money_to_text(30_175_93, with_currency: false, format: { no_cents: true, symbol: false })).to eql('30,175')
|
158
|
+
expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false, format: { no_cents: true, symbol: false })).to eql('30.175')
|
152
159
|
end
|
153
160
|
|
154
161
|
it 'returns an empty string if amount passed in is whitespace, empty string, or nil' do
|
@@ -198,18 +205,36 @@ describe MoneyHelper do
|
|
198
205
|
expect(MoneyHelper.money_range_to_text(nil, 40_983_27, currency: 'USD')).to eql('Under USD $40,983.27')
|
199
206
|
end
|
200
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
|
+
|
201
212
|
it "appends the text ' and up' when high amount not given" do
|
202
213
|
expect(MoneyHelper.money_range_to_text(30_175_93, nil, currency: 'USD')).to eql('USD $30,175.93 and up')
|
203
214
|
end
|
204
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
|
+
|
205
220
|
it 'treats as a single price when low amount and high amount are identical' do
|
206
221
|
expect(MoneyHelper.money_range_to_text(30_175_93, 30_175_93, currency: 'USD')).to eql('USD $30,175.93')
|
207
222
|
end
|
208
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
|
+
|
209
228
|
it 'returns empty string when both amounts are nil' do
|
210
229
|
expect(MoneyHelper.money_range_to_text(nil, nil, currency: 'USD')).to eql('')
|
211
230
|
end
|
212
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
|
+
|
213
238
|
it "raises an exception when currency can't be found" do
|
214
239
|
expect do
|
215
240
|
MoneyHelper.money_range_to_text(10_000, 20_000, currency: 'ITL')
|
data/spec/spec_helper.rb
CHANGED
data/spec/version_spec.rb
CHANGED
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:
|
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
|
@@ -87,12 +87,10 @@ files:
|
|
87
87
|
- README.md
|
88
88
|
- RELEASING.md
|
89
89
|
- Rakefile
|
90
|
-
-
|
91
|
-
- gemfiles/activesupport_41.gemfile
|
92
|
-
- gemfiles/activesupport_42.gemfile
|
93
|
-
- gemfiles/activesupport_50.gemfile
|
94
|
-
- gemfiles/activesupport_51.gemfile
|
90
|
+
- UPGRADING.md
|
95
91
|
- gemfiles/activesupport_52.gemfile
|
92
|
+
- gemfiles/activesupport_60.gemfile
|
93
|
+
- gemfiles/activesupport_61.gemfile
|
96
94
|
- gemfiles/activesupport_edge.gemfile
|
97
95
|
- lib/money_helper.rb
|
98
96
|
- lib/version.rb
|
@@ -104,7 +102,7 @@ homepage: https://github.com/artsy/money_helper
|
|
104
102
|
licenses:
|
105
103
|
- MIT
|
106
104
|
metadata: {}
|
107
|
-
post_install_message:
|
105
|
+
post_install_message:
|
108
106
|
rdoc_options: []
|
109
107
|
require_paths:
|
110
108
|
- lib
|
@@ -119,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
117
|
- !ruby/object:Gem::Version
|
120
118
|
version: 1.3.6
|
121
119
|
requirements: []
|
122
|
-
rubygems_version: 3.1.
|
123
|
-
signing_key:
|
120
|
+
rubygems_version: 3.1.2
|
121
|
+
signing_key:
|
124
122
|
specification_version: 4
|
125
123
|
summary: MoneyHelper international price formatting utility.
|
126
124
|
test_files:
|