monetize 1.9.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +2 -1
- data/lib/monetize.rb +1 -1
- data/lib/monetize/parser.rb +1 -1
- data/lib/monetize/version.rb +1 -1
- data/monetize.gemspec +8 -2
- data/spec/core_extensions_spec.rb +1 -1
- data/spec/monetize_spec.rb +29 -17
- metadata +14 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c921047a6f291ae61ceb19db130de7b0288d8e2
|
4
|
+
data.tar.gz: f48eb20c8582b1453ef6114df30793f9367d934e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b4a49126c30cfd92968d6fed6cd43a806e5cda807f8dfd0c8956d434e0e3a3331191d9e228e5648c4d11157f01d3c3fcdb72f72f21e52f96002ab803b70265a
|
7
|
+
data.tar.gz: 571ec0ec170014d408f4ba0208a1b40f04cdf3436b2939e7d43b922cfe2ce3e981fb5a51a6dc79eab8d07ccad4ecfbc270548e15b4293428df87dbc0c912d277
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -2,13 +2,14 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'coveralls', '>= 0.8.20', require: false
|
4
4
|
|
5
|
-
# JSON gem no longer supports ruby < 2.0.0
|
5
|
+
# JSON and I18n gem no longer supports ruby < 2.0.0
|
6
6
|
if defined?(JRUBY_VERSION)
|
7
7
|
gem 'json'
|
8
8
|
elsif RUBY_VERSION =~ /^1/
|
9
9
|
gem 'json', '~> 1.8.3'
|
10
10
|
gem 'tins', '~> 1.6.0'
|
11
11
|
gem 'term-ansicolor', '~> 1.3.0'
|
12
|
+
gem 'i18n', '~> 0.9'
|
12
13
|
end
|
13
14
|
|
14
15
|
gemspec
|
data/lib/monetize.rb
CHANGED
data/lib/monetize/parser.rb
CHANGED
@@ -152,7 +152,7 @@ module Monetize
|
|
152
152
|
|
153
153
|
def set_minor_precision(minor, currency)
|
154
154
|
if Money.infinite_precision
|
155
|
-
(BigDecimal
|
155
|
+
(BigDecimal(minor) / (10**minor.size)) * currency.subunit_to_unit
|
156
156
|
elsif minor.size < currency.decimal_places
|
157
157
|
(minor + ('0' * currency.decimal_places))[0, currency.decimal_places].to_i
|
158
158
|
elsif minor.size > currency.decimal_places
|
data/lib/monetize/version.rb
CHANGED
data/monetize.gemspec
CHANGED
@@ -21,7 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_dependency 'money', '~> 6.12'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler'
|
25
|
-
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.2'
|
26
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
|
28
|
+
if spec.respond_to?(:metadata)
|
29
|
+
spec.metadata['changelog_uri'] = 'https://github.com/RubyMoney/monetize/blob/master/CHANGELOG.md'
|
30
|
+
spec.metadata['source_code_uri'] = 'https://github.com/RubyMoney/monetize/'
|
31
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/RubyMoney/monetize/issues'
|
32
|
+
end
|
27
33
|
end
|
@@ -31,7 +31,7 @@ describe Monetize, 'core extensions' do
|
|
31
31
|
expect(money.cents).to eq 100_37
|
32
32
|
expect(money.currency).to eq Money.default_currency
|
33
33
|
|
34
|
-
money = BigDecimal
|
34
|
+
money = BigDecimal('1234').to_money
|
35
35
|
expect(money.cents).to eq 1_234_00
|
36
36
|
expect(money.currency).to eq Money.default_currency
|
37
37
|
end
|
data/spec/monetize_spec.rb
CHANGED
@@ -212,6 +212,14 @@ describe Monetize do
|
|
212
212
|
expect(Monetize.parse('-$5.95-')).to be_nil
|
213
213
|
end
|
214
214
|
|
215
|
+
it 'returns nil when more than 2 digit separators are used' do
|
216
|
+
expect(Monetize.parse("123.34,56'89 EUR")).to be_nil
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'parses correctly strings with repeated digit separator' do
|
220
|
+
expect(Monetize.parse('19.12.89', 'EUR')).to eq Money.new(191_289_00, 'EUR')
|
221
|
+
end
|
222
|
+
|
215
223
|
it 'parses correctly strings with exactly 3 decimal digits' do
|
216
224
|
expect(Monetize.parse('6,534', 'EUR')).to eq Money.new(653, 'EUR')
|
217
225
|
expect(Monetize.parse('6.534', 'EUR')).to eq Money.new(653, 'EUR')
|
@@ -234,7 +242,7 @@ describe Monetize do
|
|
234
242
|
context 'parsing an instance of Numeric class' do
|
235
243
|
let(:integer) { 10 }
|
236
244
|
let(:float) { 10.0 }
|
237
|
-
let(:big_decimal) { BigDecimal
|
245
|
+
let(:big_decimal) { BigDecimal('10') }
|
238
246
|
|
239
247
|
[:integer, :float, :big_decimal].each do |type|
|
240
248
|
it "returns a new Money object based on the #{type} input" do
|
@@ -336,6 +344,10 @@ describe Monetize do
|
|
336
344
|
expect(collection.first).to eq Monetize.parse('$4')
|
337
345
|
expect(collection.last).to eq Monetize.parse('$10')
|
338
346
|
end
|
347
|
+
|
348
|
+
it 'raises an error if argument is invalid' do
|
349
|
+
expect { Monetize.parse_collection(nil) }.to raise_error Monetize::ArgumentError
|
350
|
+
end
|
339
351
|
end
|
340
352
|
|
341
353
|
describe '.from_string' do
|
@@ -419,31 +431,31 @@ describe Monetize do
|
|
419
431
|
|
420
432
|
describe '.from_bigdecimal' do
|
421
433
|
it 'converts given amount to cents' do
|
422
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
423
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
424
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
434
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1'))).to eq Money.new(1_00)
|
435
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1'))).to eq Money.new(1_00, 'USD')
|
436
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1'), 'EUR')).to eq Money.new(1_00, 'EUR')
|
425
437
|
end
|
426
438
|
|
427
439
|
it 'respects :subunit_to_unit currency property' do
|
428
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
429
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
430
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
440
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1'), 'USD')).to eq Money.new(1_00, 'USD')
|
441
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1'), 'TND')).to eq Money.new(1_000, 'TND')
|
442
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1'), 'JPY')).to eq Money.new(1, 'JPY')
|
431
443
|
end
|
432
444
|
|
433
445
|
it 'respects rounding mode when rounding amount to the nearest cent' do
|
434
|
-
amount = BigDecimal
|
446
|
+
amount = BigDecimal('1.005')
|
435
447
|
|
436
448
|
expect(Monetize.from_bigdecimal(amount, 'USD')).to eq Money.from_amount(amount, 'USD')
|
437
449
|
end
|
438
450
|
|
439
451
|
it 'accepts a currency options' do
|
440
|
-
m = Monetize.from_bigdecimal(BigDecimal
|
452
|
+
m = Monetize.from_bigdecimal(BigDecimal('1'))
|
441
453
|
expect(m.currency).to eq Money.default_currency
|
442
454
|
|
443
|
-
m = Monetize.from_bigdecimal(BigDecimal
|
455
|
+
m = Monetize.from_bigdecimal(BigDecimal('1'), Money::Currency.wrap('EUR'))
|
444
456
|
expect(m.currency).to eq Money::Currency.wrap('EUR')
|
445
457
|
|
446
|
-
m = Monetize.from_bigdecimal(BigDecimal
|
458
|
+
m = Monetize.from_bigdecimal(BigDecimal('1'), 'EUR')
|
447
459
|
expect(m.currency).to eq Money::Currency.wrap('EUR')
|
448
460
|
end
|
449
461
|
|
@@ -457,11 +469,11 @@ describe Monetize do
|
|
457
469
|
end
|
458
470
|
|
459
471
|
it 'keeps precision' do
|
460
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
461
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
462
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
463
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
464
|
-
expect(Monetize.from_bigdecimal(BigDecimal
|
472
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1'))).to eq Money.new(100)
|
473
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1.23456'))).to eq Money.new(123.456)
|
474
|
+
expect(Monetize.from_bigdecimal(BigDecimal('-1.23456'))).to eq Money.new(-123.456)
|
475
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1.23456'))).to eq Money.new(123.456, 'USD')
|
476
|
+
expect(Monetize.from_bigdecimal(BigDecimal('1.23456'), 'EUR')).to eq Money.new(123.456, 'EUR')
|
465
477
|
|
466
478
|
expect('1'.to_money).to eq Money.new(100)
|
467
479
|
expect('1.23456'.to_money).to eq Money.new(123.456)
|
@@ -476,7 +488,7 @@ describe Monetize do
|
|
476
488
|
it 'converts given amount to cents' do
|
477
489
|
expect(Monetize.from_numeric(1)).to eq Money.new(1_00)
|
478
490
|
expect(Monetize.from_numeric(1.0)).to eq Money.new(1_00)
|
479
|
-
expect(Monetize.from_numeric(BigDecimal
|
491
|
+
expect(Monetize.from_numeric(BigDecimal('1'))).to eq Money.new(1_00)
|
480
492
|
end
|
481
493
|
|
482
494
|
it 'raises ArgumentError with unsupported argument' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monetize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.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:
|
11
|
+
date: 2019-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: money
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '10.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '10.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +101,10 @@ files:
|
|
101
101
|
homepage: https://github.com/RubyMoney/monetize
|
102
102
|
licenses:
|
103
103
|
- MIT
|
104
|
-
metadata:
|
104
|
+
metadata:
|
105
|
+
changelog_uri: https://github.com/RubyMoney/monetize/blob/master/CHANGELOG.md
|
106
|
+
source_code_uri: https://github.com/RubyMoney/monetize/
|
107
|
+
bug_tracker_uri: https://github.com/RubyMoney/monetize/issues
|
105
108
|
post_install_message:
|
106
109
|
rdoc_options: []
|
107
110
|
require_paths:
|