money_helper 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df602a2214fc58f6ccf9041f9cce6cc87ba22609f6d8314b6a497b5802de48ff
4
- data.tar.gz: 46e3888d004f525559bf11b657e7cb504eb9c12f5dcaed61a56b18f1469a1e64
3
+ metadata.gz: 8fc38d5c4921667c0f06286f5058378d60658b3f991dd7a343f5ab597384560c
4
+ data.tar.gz: c88db16a193d5674d9f902466aace23c8b7b1a0f71b89733589a05be7059049b
5
5
  SHA512:
6
- metadata.gz: 1b5f70766be6b1091e40266cb5c3cbcb34d0457e37511e60537935bc4408dada70693d0141e3c95840894f3a3d34658a99cd1354c413b58c97484047448dcecc
7
- data.tar.gz: 7eb7051305203fed98bed96d14c2651c989fc498c58859802a85bdd26e7dda11792cef78ad9c0290530b3cd7bd69d4c94c2664cfc0bb4f487584c68e86016e25
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.5", "2.6", "2.7"]
42
- activesupport_version: ["40", "41", "42", "50", "51", "52", "edge"]
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 2019-04-19 14:01:54 -0400 using RuboCop version 0.67.2.
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: 3
10
- Lint/IneffectiveAccessModifier:
9
+ # Offense count: 1
10
+ # Configuration parameters: Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
11
13
  Exclude:
12
- - 'lib/money_helper.rb'
14
+ - 'money_helper.gemspec'
data/Appraisals CHANGED
@@ -1,25 +1,15 @@
1
- appraise 'activesupport_40' do
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 'activesupport_42' do
10
- gem 'activesupport', '~> 4.2.0'
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 'activesupport_51' do
18
- gem 'activesupport', '~> 5.1.0'
7
+ appraise 'activesupport_60' do
8
+ gem 'activesupport', '~> 6.0.4'
19
9
  end
20
10
 
21
- appraise 'activesupport_52' do
22
- gem 'activesupport', '~> 5.2.1'
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
- ### 2.0.1 (Next)
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
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
- gem 'rubocop', '0.67.2'
7
+ # pinned so that the lock files stay in sync
8
+ gem 'rubocop', '1.21.0'
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/master.svg?style=shield
43
- [circleci]: https://circleci.com/gh/artsy/money_helper/tree/master
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler'
3
5
  require 'bundler/gem_tasks'
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,8 +1,10 @@
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
- gem 'activesupport', '~> 5.2.1'
6
- gem 'rubocop', '0.59.2'
7
+ gem 'activesupport', '~> 5.2.6'
8
+ gem 'rubocop', '1.21.0'
7
9
 
8
10
  gemspec path: '../'
@@ -1,8 +1,10 @@
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
- gem 'activesupport', '~> 4.0.0'
6
- gem 'rubocop', '0.59.2'
7
+ gem 'activesupport', '~> 6.0.4'
8
+ gem 'rubocop', '1.21.0'
7
9
 
8
10
  gemspec path: '../'
@@ -1,8 +1,10 @@
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
- gem 'activesupport', '~> 4.1.0'
6
- gem 'rubocop', '0.59.2'
7
+ gem 'activesupport', '~> 6.1.4'
8
+ gem 'rubocop', '1.21.0'
7
9
 
8
10
  gemspec path: '../'
@@ -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', '0.59.2'
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
- # with_symbol: (Boolean) optional flag to include currency symbol, defaulting to true
31
- def self.money_to_text(amount_minor, currency: 'USD', with_currency: true, with_symbol: true)
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
- money_options = {
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(money_options)
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
- 'Under ' + money_to_text(high, currency: currency)
77
+ "Under #{money_to_text(high, currency: currency)}"
77
78
  elsif high.blank?
78
- money_to_text(low, currency: currency) + ' and up'
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, with_symbol: 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MoneyHelper
2
- VERSION = '2.0.0'.freeze
4
+ VERSION = '3.0.0'
3
5
  end
data/money_helper.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.push File.expand_path('lib', __dir__)
2
4
  require 'version'
3
5
 
@@ -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 with_symbol is false' do
141
- expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_symbol: false)).to eql('EUR 30.175,93')
142
- expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_symbol: false)).to eql('AUD 30,175.93')
143
- expect(MoneyHelper.money_to_text(30_175_93, currency: 'AMD', with_symbol: false)).to eql('AMD 30,175.93')
144
- expect(MoneyHelper.money_to_text(30_175_93, currency: 'AFN', with_symbol: false)).to eql('AFN 30,175.93')
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 ISO code and symbol when both with_currency and with_symbol are false' do
148
- expect(MoneyHelper.money_to_text(30_175_93, currency: 'EUR', with_currency: false, with_symbol: false)).to eql('30.175,93')
149
- expect(MoneyHelper.money_to_text(30_175_93, currency: 'AUD', with_currency: false, with_symbol: false)).to eql('30,175.93')
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
2
4
 
3
5
  require 'rubygems'
data/spec/version_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
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: 2.0.0
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: 2021-09-20 00:00:00.000000000 Z
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
- - gemfiles/activesupport_40.gemfile
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.1.4
120
+ rubygems_version: 3.2.27
123
121
  signing_key:
124
122
  specification_version: 4
125
123
  summary: MoneyHelper international price formatting utility.
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source 'http://rubygems.org'
4
-
5
- gem 'activesupport', '~> 4.2.0'
6
- gem 'rubocop', '0.59.2'
7
-
8
- gemspec path: '../'
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source 'http://rubygems.org'
4
-
5
- gem 'activesupport', '~> 5.0.0'
6
- gem 'rubocop', '0.59.2'
7
-
8
- gemspec path: '../'
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source 'http://rubygems.org'
4
-
5
- gem 'activesupport', '~> 5.1.0'
6
- gem 'rubocop', '0.59.2'
7
-
8
- gemspec path: '../'