money_helper 2.0.0 → 3.0.0
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/.circleci/config.yml +2 -4
- data/.rubocop.yml +7 -5
- data/.rubocop_todo.yml +6 -4
- data/Appraisals +7 -17
- data/CHANGELOG.md +2 -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 +3 -1
- data/lib/money_helper.rb +11 -10
- data/lib/version.rb +3 -1
- data/money_helper.gemspec +2 -0
- data/spec/money_helper_spec.rb +17 -10
- data/spec/spec_helper.rb +2 -0
- data/spec/version_spec.rb +2 -0
- metadata +6 -8
- 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: 8fc38d5c4921667c0f06286f5058378d60658b3f991dd7a343f5ab597384560c
|
4
|
+
data.tar.gz: c88db16a193d5674d9f902466aace23c8b7b1a0f71b89733589a05be7059049b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c258cca4d8ac444695faedd9245d1f805bcb5534bcf6f864dffdcfe330bf8f54f6c10caf800e32c1c2621bc523f6277acde3821a16c6a11edf31b777cdbdc6b
|
7
|
+
data.tar.gz: 8133b959081243c17b6d160ec72a802ed79648989c60ebaca8546a8509cc145b1148f89de4cc1e4ee89cc51459cc0e54fcf58f29a7d5fd412b4f1a93a85744fa
|
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,25 +1,15 @@
|
|
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
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
###
|
1
|
+
### 3.0.0 (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).
|
3
4
|
* Your contribution here.
|
4
5
|
|
5
6
|
### 2.0.0 (2021-09-20)
|
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,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file was generated by Appraisal
|
2
4
|
|
3
5
|
source 'http://rubygems.org'
|
@@ -6,6 +8,6 @@ git 'git://github.com/rails/rails.git' 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
|
@@ -73,14 +74,14 @@ module MoneyHelper
|
|
73
74
|
if low.blank? && high.blank?
|
74
75
|
''
|
75
76
|
elsif low.blank?
|
76
|
-
|
77
|
+
"Under #{money_to_text(high, currency: currency)}"
|
77
78
|
elsif high.blank?
|
78
|
-
money_to_text(low, currency: currency)
|
79
|
+
"#{money_to_text(low, currency: currency)} and up"
|
79
80
|
elsif low == high
|
80
81
|
money_to_text(low, currency: currency)
|
81
82
|
else
|
82
83
|
formatted_low = money_to_text(low, currency: currency)
|
83
|
-
formatted_high = money_to_text(high, currency: currency, with_currency: false,
|
84
|
+
formatted_high = money_to_text(high, currency: currency, with_currency: false, format: { symbol: false })
|
84
85
|
[formatted_low, formatted_high].compact.join(delimiter)
|
85
86
|
end
|
86
87
|
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
|
data/spec/spec_helper.rb
CHANGED
data/spec/version_spec.rb
CHANGED
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:
|
4
|
+
version: 3.0.0
|
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:
|
14
|
+
date: 2022-02-16 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
|
@@ -119,7 +117,7 @@ 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.
|
120
|
+
rubygems_version: 3.2.27
|
123
121
|
signing_key:
|
124
122
|
specification_version: 4
|
125
123
|
summary: MoneyHelper international price formatting utility.
|