money 6.13.0 → 6.13.1

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
  SHA1:
3
- metadata.gz: 7929d62cf482b5ad0876b0ff4950440cec3051ff
4
- data.tar.gz: 8b40765349b517c8182f20de9378ad14b76eb863
3
+ metadata.gz: 4981b9f6d6c9b7162e5df6692e81cac6440edcca
4
+ data.tar.gz: 96d7be00c3f275c0b8731807f4fa8955fade71bb
5
5
  SHA512:
6
- metadata.gz: 1bc3a9c7fc84b6c4cd7e78d2dbe7bd666ab25f0715523953751984405f0ae858396e20e7bf0d8199b50c1d94d5947a1d3b0308094f3f2b347f07c93b655b28f1
7
- data.tar.gz: 1a1dae32b195ccb6a93125fd2526e1c60e24c794cdd26fc08eb6254a1e6f8f4c0aef270ac215d1606b5163f7a1690443230161a75a5e522f72aa824b1f6f2efd
6
+ metadata.gz: 4943cebf00d5abf48ca73b52ffd18cc2324287ffada6513357a1d4146b52fc7f4742dd95937efe499f96989c853939543ba857e8af32346f65852cbb71e0c3dd
7
+ data.tar.gz: 7b87dfa829e29eb266083e1b8d7df418c519273fb5fcab0095d6426b54cee22319303aa122825aa6f23ff635d32a28eb1644efa4f608c697c869c7b37405af0f
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.13.1
4
+ - Add bolívar soberano (VES)
5
+ - Deprecate bolívar fuerte (VEF)
6
+ - Deprecate old `#format` rules passed as a symbol
7
+ - Clarify `use_i18n` deprecation
8
+ - Add `:currency` locale_backend for explicit per-currency localization
9
+
3
10
  ## 6.13.0
4
11
  - Add :format option to the Formatter
5
12
  - Add ruby 2.6.0 support
data/README.md CHANGED
@@ -434,6 +434,48 @@ If you wish to disable this feature and use defaults instead:
434
434
  Money.locale_backend = nil
435
435
  ```
436
436
 
437
+ ### Deprecation
438
+
439
+ The current default behaviour always checks the I18n locale first, falling back to "per currency"
440
+ localization. This is now deprecated and will be removed in favour of explicitly defined behaviour
441
+ in the next major release.
442
+
443
+ If you would like to use I18n localization (formatting depends on the locale):
444
+
445
+ ```ruby
446
+ Money.locale_backend = :i18n
447
+
448
+ # example (using default localization from rails-i18n):
449
+ I18n.locale = :en
450
+ Money.new(10_000_00, 'USD').format # => $10,000.00
451
+ Money.new(10_000_00, 'EUR').format # => €10,000.00
452
+
453
+ I18n.locale = :es
454
+ Money.new(10_000_00, 'USD').format # => $10.000,00
455
+ Money.new(10_000_00, 'EUR').format # => €10.000,00
456
+ ```
457
+
458
+ For the legacy behaviour of "per currency" localization (formatting depends only on currency):
459
+
460
+ ```ruby
461
+ Money.locale_backend = :currency
462
+
463
+ # example:
464
+ Money.new(10_000_00, 'USD').format # => $10,000.00
465
+ Money.new(10_000_00, 'EUR').format # => €10.000,00
466
+ ```
467
+
468
+ In case you don't need localization and would like to use default values (can be redefined using
469
+ `Money.default_formatting_rules`):
470
+
471
+ ```ruby
472
+ Money.locale_backend = nil
473
+
474
+ # example:
475
+ Money.new(10_000_00, 'USD').format # => $10000.00
476
+ Money.new(10_000_00, 'EUR').format # => €10000.00
477
+ ```
478
+
437
479
  ## Collection
438
480
 
439
481
  In case you're working with collections of `Money` instances, have a look at [money-collection](https://github.com/RubyMoney/money-collection)
@@ -169,5 +169,20 @@
169
169
  "thousands_separator": ",",
170
170
  "iso_numeric": "935",
171
171
  "smallest_denomination": 100
172
+ },
173
+ "vef": {
174
+ "priority": 100,
175
+ "iso_code": "VEF",
176
+ "name": "Venezuelan Bolívar",
177
+ "symbol": "Bs.F",
178
+ "alternate_symbols": ["Bs"],
179
+ "subunit": "Céntimo",
180
+ "subunit_to_unit": 100,
181
+ "symbol_first": true,
182
+ "html_entity": "",
183
+ "decimal_mark": ",",
184
+ "thousands_separator": ".",
185
+ "iso_numeric": "937",
186
+ "smallest_denomination": 1
172
187
  }
173
188
  }
@@ -2271,19 +2271,19 @@
2271
2271
  "iso_numeric": "860",
2272
2272
  "smallest_denomination": 100
2273
2273
  },
2274
- "vef": {
2274
+ "ves": {
2275
2275
  "priority": 100,
2276
- "iso_code": "VEF",
2277
- "name": "Venezuelan Bolívar",
2276
+ "iso_code": "VES",
2277
+ "name": "Venezuelan Bolívar Soberano",
2278
2278
  "symbol": "Bs",
2279
- "alternate_symbols": ["Bs.F"],
2279
+ "alternate_symbols": ["Bs.S"],
2280
2280
  "subunit": "Céntimo",
2281
2281
  "subunit_to_unit": 100,
2282
2282
  "symbol_first": true,
2283
2283
  "html_entity": "",
2284
2284
  "decimal_mark": ",",
2285
2285
  "thousands_separator": ".",
2286
- "iso_numeric": "937",
2286
+ "iso_numeric": "928",
2287
2287
  "smallest_denomination": 1
2288
2288
  },
2289
2289
  "vnd": {
@@ -0,0 +1,11 @@
1
+ require 'money/locale_backend/base'
2
+
3
+ class Money
4
+ module LocaleBackend
5
+ class Currency < Base
6
+ def lookup(key, currency)
7
+ currency.public_send(key) if currency.respond_to?(key)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -9,9 +9,9 @@ class Money
9
9
  end
10
10
 
11
11
  def lookup(key, currency)
12
- if Money.use_i18n
13
- warn '[DEPRECATION] `use_i18n` is deprecated - use `Money.locale_backend = :i18n` instead'
12
+ warn '[DEPRECATION] You are using the default localization behaviour that will change in the next major release. Find out more - https://github.com/RubyMoney/money#deprecation'
14
13
 
14
+ if Money.use_i18n
15
15
  i18n_backend.lookup(key, nil) || currency.public_send(key)
16
16
  else
17
17
  currency.public_send(key)
@@ -149,7 +149,9 @@ class Money
149
149
 
150
150
  def self.use_i18n=(value)
151
151
  if value
152
- warn '[DEPRECATION] `use_i18n` is deprecated - use `Money.locale_backend = :i18n` instead'
152
+ warn '[DEPRECATION] `use_i18n` is deprecated - use `Money.locale_backend = :i18n` instead for locale based formatting'
153
+ else
154
+ warn '[DEPRECATION] `use_i18n` is deprecated - use `Money.locale_backend = :currency` instead for currency based formatting'
153
155
  end
154
156
 
155
157
  @use_i18n = value
@@ -204,6 +204,9 @@ class Money
204
204
  # # CAD: "CAD$"
205
205
  # Money.new(10000, "CAD").format(translate: true) #=> "CAD$100.00"
206
206
  #
207
+ # @option rules [Boolean] :drop_trailing_zeros (false) Ignore trailing zeros after
208
+ # the decimal mark
209
+ #
207
210
  # @example
208
211
  # Money.new(89000, :btc).format(drop_trailing_zeros: true) #=> B⃦0.00089
209
212
  # Money.new(110, :usd).format(drop_trailing_zeros: true) #=> $1.1
@@ -38,14 +38,21 @@ class Money
38
38
  rules = {}
39
39
  elsif rules.size == 1
40
40
  rules = rules.pop
41
- rules = { rules => true } if rules.is_a?(Symbol)
41
+
42
+ if rules.is_a?(Symbol)
43
+ warn '[DEPRECATION] Use Hash when passing rules to Money#format.'
44
+ rules = { rules => true }
45
+ end
42
46
  end
47
+
43
48
  if !rules.include?(:decimal_mark) && rules.include?(:separator)
44
49
  rules[:decimal_mark] = rules[:separator]
45
50
  end
51
+
46
52
  if !rules.include?(:thousands_separator) && rules.include?(:delimiter)
47
53
  rules[:thousands_separator] = rules[:delimiter]
48
54
  end
55
+
49
56
  rules
50
57
  end
51
58
 
@@ -3,12 +3,14 @@
3
3
  require 'money/locale_backend/errors'
4
4
  require 'money/locale_backend/legacy'
5
5
  require 'money/locale_backend/i18n'
6
+ require 'money/locale_backend/currency'
6
7
 
7
8
  class Money
8
9
  module LocaleBackend
9
10
  BACKENDS = {
10
11
  legacy: Money::LocaleBackend::Legacy,
11
- i18n: Money::LocaleBackend::I18n
12
+ i18n: Money::LocaleBackend::I18n,
13
+ currency: Money::LocaleBackend::Currency
12
14
  }.freeze
13
15
 
14
16
  def self.find(name)
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = '6.13.0'
2
+ VERSION = '6.13.1'
3
3
  end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ describe Money::LocaleBackend::Currency do
4
+ describe '#lookup' do
5
+ let(:currency) { Money::Currency.new('EUR') }
6
+
7
+ it 'returns thousands_separator as defined in currency' do
8
+ expect(subject.lookup(:thousands_separator, currency)).to eq('.')
9
+ end
10
+
11
+ it 'returns decimal_mark based as defined in currency' do
12
+ expect(subject.lookup(:decimal_mark, currency)).to eq(',')
13
+ end
14
+ end
15
+ end
@@ -136,6 +136,10 @@ describe Money, "formatting" do
136
136
  end
137
137
 
138
138
  describe "#format" do
139
+ it 'supports the old formatting options' do
140
+ expect(Money.zero.format(:display_free)).to eq('free')
141
+ end
142
+
139
143
  context "Locale :ja" do
140
144
  before { @_locale = I18n.locale; I18n.locale = :ja }
141
145
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.13.0
4
+ version: 6.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-01 00:00:00.000000000 Z
11
+ date: 2018-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -129,6 +129,7 @@ files:
129
129
  - lib/money/currency/heuristics.rb
130
130
  - lib/money/currency/loader.rb
131
131
  - lib/money/locale_backend/base.rb
132
+ - lib/money/locale_backend/currency.rb
132
133
  - lib/money/locale_backend/errors.rb
133
134
  - lib/money/locale_backend/i18n.rb
134
135
  - lib/money/locale_backend/legacy.rb
@@ -148,6 +149,7 @@ files:
148
149
  - spec/currency/heuristics_spec.rb
149
150
  - spec/currency/loader_spec.rb
150
151
  - spec/currency_spec.rb
152
+ - spec/locale_backend/currency_spec.rb
151
153
  - spec/locale_backend/i18n_spec.rb
152
154
  - spec/locale_backend/legacy_spec.rb
153
155
  - spec/money/allocation_spec.rb
@@ -193,6 +195,7 @@ test_files:
193
195
  - spec/currency/heuristics_spec.rb
194
196
  - spec/currency/loader_spec.rb
195
197
  - spec/currency_spec.rb
198
+ - spec/locale_backend/currency_spec.rb
196
199
  - spec/locale_backend/i18n_spec.rb
197
200
  - spec/locale_backend/legacy_spec.rb
198
201
  - spec/money/allocation_spec.rb