monetize 1.9.0 → 1.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e26348a04058d672c804c80a19beb2c4615f9a33
4
- data.tar.gz: 68697cc2d144f4e6ce17e7784e0dcb5188a482fb
2
+ SHA256:
3
+ metadata.gz: 63f57158028647c2bde5bac4c2186e16e9a3874d6c6d756b08e091d1357fcfcc
4
+ data.tar.gz: 5dd093ceef480ffd21fbfaa3a0912cdc7421f797c4570a2a8bde9665534aa6ff
5
5
  SHA512:
6
- metadata.gz: 452be2be436b0ea57611a2a32b3230486f8f3de40cb74e4286931528a6db05fd2cddc114ca5373be7a92f4680a0f50a3992af373920b09f65c233fd0f9cb0007
7
- data.tar.gz: db4134e4c44bb2b58fd12d6c7ff2d5e3259b76ba6971215cbdd61759d715cf98b014066f165dfea5cf79ac5c7997937ca1fc3ff0ceae8ce604424c41370def1f
6
+ metadata.gz: 6b4001dd8967421873f84b9b0201bd0985d1388d89c41c2c048498db185cd2d4bdd144c581293fff70e34c5fb88aecbf68f2e3d2d086f1f278f58047e519aebe
7
+ data.tar.gz: 468cc1fd1f127eb570e8599ef20309240f5e95c5731374848c663995d4935e4bb6773ffd40691d2bd4148c58e51e641806a3d7a97d25851a5877bc74621fe059
@@ -0,0 +1,34 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby-version }}
32
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
33
+ - name: Run tests
34
+ run: bundle exec rspec spec
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.10.0
4
+ - When using the `assume_from_symbol` option, the currency in the input string will be used over the assumed currency based on symbol. For example, `$1.05 CAD` will use `CAD` instead of `USD`.
5
+
6
+ ## 1.9.4
7
+ - Fix symbol parsing that are surrounded by other characters
8
+
9
+ ## 1.9.3
10
+ - Fix input parsing when currency symbol after the amount
11
+
12
+ ## 1.9.2
13
+ - Respect Money.rounding_mode when parsing strings
14
+ - Deprecate Monetize.extract_cents
15
+
16
+ ## 1.9.1
17
+ - Ruby 2.6 support
18
+
3
19
  ## 1.9.0
4
20
  - Relax Money gem dependency to ~> 6.12
5
21
  - Refactor `Monetize::Parser`
data/Gemfile CHANGED
@@ -1,14 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'coveralls', '>= 0.8.20', require: false
4
-
5
- # JSON gem no longer supports ruby < 2.0.0
3
+ # JSON and I18n gem no longer supports ruby < 2.0.0
6
4
  if defined?(JRUBY_VERSION)
7
5
  gem 'json'
8
6
  elsif RUBY_VERSION =~ /^1/
9
7
  gem 'json', '~> 1.8.3'
10
8
  gem 'tins', '~> 1.6.0'
11
9
  gem 'term-ansicolor', '~> 1.3.0'
10
+ gem 'i18n', '~> 0.9'
12
11
  end
13
12
 
14
13
  gemspec
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/monetize.svg)](http://badge.fury.io/rb/monetize)
4
4
  [![Build Status](https://travis-ci.org/RubyMoney/monetize.svg?branch=master)](https://travis-ci.org/RubyMoney/monetize)
5
5
  [![Code Climate](https://codeclimate.com/github/RubyMoney/monetize.svg)](https://codeclimate.com/github/RubyMoney/monetize)
6
- [![Coverage Status](https://coveralls.io/repos/RubyMoney/monetize/badge.svg)](https://coveralls.io/r/RubyMoney/monetize)
7
6
  [![Dependency Status](https://gemnasium.com/RubyMoney/monetize.svg)](https://gemnasium.com/RubyMoney/monetize)
8
7
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
9
8
 
@@ -31,9 +31,9 @@ module Monetize
31
31
  return from_numeric(input, currency) if input.is_a?(Numeric)
32
32
 
33
33
  parser = Monetize::Parser.new(input, currency, options)
34
- currency_from_input = Money::Currency.wrap(parser.parse_currency)
34
+ amount, currency = parser.parse
35
35
 
36
- Money.new(parser.parse_cents(currency_from_input), currency_from_input)
36
+ Money.from_amount(amount, currency)
37
37
  rescue Money::Currency::UnknownCurrency => e
38
38
  fail ParseError, e.message
39
39
  end
@@ -43,7 +43,7 @@ module Monetize
43
43
  end
44
44
 
45
45
  def from_string(value, currency = Money.default_currency)
46
- value = BigDecimal.new(value.to_s)
46
+ value = BigDecimal(value.to_s)
47
47
  Money.from_amount(value, currency)
48
48
  end
49
49
 
@@ -66,7 +66,10 @@ module Monetize
66
66
  end
67
67
 
68
68
  def extract_cents(input, currency = Money.default_currency)
69
- Monetize::Parser.new(input).parse_cents(currency)
69
+ warn '[DEPRECATION] Monetize.extract_cents is deprecated. Use Monetize.parse().cents'
70
+
71
+ money = parse(input, currency)
72
+ money.cents if money
70
73
  end
71
74
  end
72
75
  end
@@ -29,13 +29,17 @@ module Monetize
29
29
  MULTIPLIER_SUFFIXES.default = 0
30
30
  MULTIPLIER_REGEXP = Regexp.new(format('^(.*?\d)(%s)\b([^\d]*)$', MULTIPLIER_SUFFIXES.keys.join('|')), 'i')
31
31
 
32
+ DEFAULT_DECIMAL_MARK = '.'.freeze
33
+
32
34
  def initialize(input, fallback_currency = Money.default_currency, options = {})
33
35
  @input = input.to_s.strip
34
36
  @fallback_currency = fallback_currency
35
37
  @options = options
36
38
  end
37
39
 
38
- def parse_cents(currency)
40
+ def parse
41
+ currency = Money::Currency.wrap(parse_currency)
42
+
39
43
  multiplier_exp, input = extract_multiplier
40
44
 
41
45
  num = input.gsub(/(?:^#{currency.symbol}|[^\d.,'-]+)/, '')
@@ -46,47 +50,41 @@ module Monetize
46
50
 
47
51
  major, minor = extract_major_minor(num, currency)
48
52
 
49
- major, minor = apply_multiplier(multiplier_exp, major.to_i, minor)
53
+ amount = BigDecimal([major, minor].join(DEFAULT_DECIMAL_MARK))
54
+ amount = apply_multiplier(multiplier_exp, amount)
55
+ amount = apply_sign(negative, amount)
50
56
 
51
- cents = major.to_i * currency.subunit_to_unit
57
+ [amount, currency]
58
+ end
52
59
 
53
- cents += set_minor_precision(minor, currency)
60
+ private
54
61
 
55
- apply_sign(negative, cents)
56
- end
62
+ attr_reader :input, :fallback_currency, :options
57
63
 
58
64
  def parse_currency
59
65
  computed_currency = nil
60
- computed_currency = compute_currency if assume_from_symbol?
61
- computed_currency ||= input[/[A-Z]{2,3}/]
66
+ computed_currency = input[/[A-Z]{2,3}/]
67
+ computed_currency ||= compute_currency if assume_from_symbol?
68
+
62
69
 
63
70
  computed_currency || fallback_currency || Money.default_currency
64
71
  end
65
72
 
66
- private
67
-
68
- attr_reader :input, :fallback_currency, :options
69
-
70
73
  def assume_from_symbol?
71
74
  options.fetch(:assume_from_symbol) { Monetize.assume_from_symbol }
72
75
  end
73
76
 
74
- def apply_multiplier(multiplier_exp, major, minor)
75
- major *= 10**multiplier_exp
76
- minor = minor.to_s + ('0' * multiplier_exp)
77
- shift = minor[0...multiplier_exp].to_i
78
- major += shift
79
- minor = (minor[multiplier_exp..-1] || '')
80
- [major, minor]
77
+ def apply_multiplier(multiplier_exp, amount)
78
+ amount * 10**multiplier_exp
81
79
  end
82
80
 
83
- def apply_sign(negative, cents)
84
- negative ? cents * -1 : cents
81
+ def apply_sign(negative, amount)
82
+ negative ? amount * -1 : amount
85
83
  end
86
84
 
87
85
  def compute_currency
88
- matches = input.match(currency_symbol_regex)
89
- CURRENCY_SYMBOLS[matches[:symbol]] if matches
86
+ match = input.match(currency_symbol_regex)
87
+ CURRENCY_SYMBOLS[match.to_s] if match
90
88
  end
91
89
 
92
90
  def extract_major_minor(num, currency)
@@ -150,29 +148,13 @@ module Monetize
150
148
  CURRENCY_SYMBOLS.keys.map { |key| Regexp.escape(key) }.join('|')
151
149
  end
152
150
 
153
- def set_minor_precision(minor, currency)
154
- if Money.infinite_precision
155
- (BigDecimal.new(minor) / (10**minor.size)) * currency.subunit_to_unit
156
- elsif minor.size < currency.decimal_places
157
- (minor + ('0' * currency.decimal_places))[0, currency.decimal_places].to_i
158
- elsif minor.size > currency.decimal_places
159
- if minor[currency.decimal_places, 1].to_i >= 5
160
- minor[0, currency.decimal_places].to_i + 1
161
- else
162
- minor[0, currency.decimal_places].to_i
163
- end
164
- else
165
- minor.to_i
166
- end
167
- end
168
-
169
151
  def split_major_minor(num, delimiter)
170
152
  major, minor = num.split(delimiter)
171
153
  [major, minor || '00']
172
154
  end
173
155
 
174
156
  def currency_symbol_regex
175
- /\A[\+|\-]?(?<symbol>#{regex_safe_symbols})/
157
+ /(?<![A-Z])(#{regex_safe_symbols})(?![A-Z])/i
176
158
  end
177
159
  end
178
160
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Monetize
4
- VERSION = '1.9.0'
4
+ VERSION = '1.10.0'
5
5
  end
@@ -7,8 +7,8 @@ require 'English'
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'monetize'
9
9
  spec.version = Monetize::VERSION
10
- spec.authors = ['Shane Emmons']
11
- spec.email = ['shane@emmons.io']
10
+ spec.authors = ['Shane Emmons', 'Anthony Dmitriyev']
11
+ spec.email = ['shane@emmons.io', 'anthony.dmitriyev@gmail.com']
12
12
  spec.description = 'A library for converting various objects into `Money` objects.'
13
13
  spec.summary = 'A library for converting various objects into `Money` objects.'
14
14
  spec.homepage = 'https://github.com/RubyMoney/monetize'
@@ -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', '~> 1.3'
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
@@ -7,7 +7,7 @@ require 'monetize/core_extensions'
7
7
  describe Monetize, 'core extensions' do
8
8
  describe NilClass do
9
9
  describe '#to_money' do
10
- it 'work as documented' do
10
+ it 'works as documented' do
11
11
  money = nil.to_money
12
12
  expect(money.cents).to eq 0
13
13
  expect(money.currency).to eq Money.default_currency
@@ -22,7 +22,7 @@ describe Monetize, 'core extensions' do
22
22
 
23
23
  describe Numeric do
24
24
  describe '#to_money' do
25
- it 'work as documented' do
25
+ it 'works as documented' do
26
26
  money = 1234.to_money
27
27
  expect(money.cents).to eq 1_234_00
28
28
  expect(money.currency).to eq Money.default_currency
@@ -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.new('1234').to_money
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
@@ -67,7 +67,8 @@ describe Monetize, 'core extensions' do
67
67
  '-1,000' => Money.new(-1_000_00),
68
68
  '1,000.5' => Money.new(1_000_50),
69
69
  '1,000.51' => Money.new(1_000_51),
70
- '1,000.505' => Money.new(1_000_51),
70
+ '1,000.505' => Money.new(1_000_50), # ROUND_HALF_EVEN default bankers rounding
71
+ '1,000.515' => Money.new(1_000_52), # ROUND_HALF_EVEN default bankers rounding
71
72
  '1,000.504' => Money.new(1_000_50),
72
73
  '1,000.0000' => Money.new(1_000_00),
73
74
  '1,000.5000' => Money.new(1_000_50),
@@ -149,6 +150,28 @@ describe Monetize, 'core extensions' do
149
150
  expect('1'.to_money('JPY')).to eq Money.new(1, 'JPY')
150
151
  expect('1.5'.to_money('KWD').cents).to eq 1_500
151
152
  end
153
+
154
+ it 'respects Money.rounding_mode' do
155
+ expect('1.009'.to_money).to eq(Money.new(1_01))
156
+
157
+ Money.rounding_mode(BigDecimal::ROUND_DOWN) do
158
+ expect('1.009'.to_money).to eq(Money.new(1_00))
159
+ end
160
+
161
+ expect('1.001'.to_money).to eq(Money.new(1_00))
162
+
163
+ Money.rounding_mode(BigDecimal::ROUND_UP) do
164
+ expect('1.001'.to_money).to eq(Money.new(1_01))
165
+ end
166
+ end
167
+
168
+ it 'produces results similar to Money.from_amount for all the rounding edge cases' do
169
+ (1_000..1_010).each do |amount|
170
+ amount = amount.to_f / 1000
171
+
172
+ expect(amount.to_s.to_money).to eq(Money.from_amount(amount))
173
+ end
174
+ end
152
175
  end
153
176
 
154
177
  describe '#to_currency' do
@@ -70,6 +70,10 @@ describe Monetize do
70
70
  expect(Monetize.parse("#{symbol}#{amount_in_units}")).to eq Money.new(amount, iso_code)
71
71
  end
72
72
 
73
+ it "parses formatted inputs with #{iso_code} symbol is after the amount" do
74
+ expect(Monetize.parse("#{amount_in_units}#{symbol}")).to eq Money.new(amount, iso_code)
75
+ end
76
+
73
77
  context 'prefix' do
74
78
  it 'parses formatted inputs with plus sign and currency as a symbol' do
75
79
  expect(Monetize.parse("+#{symbol}#{amount_in_units}")).to eq Money.new(amount, iso_code)
@@ -114,6 +118,15 @@ describe Monetize do
114
118
  expect(Monetize.parse('L9.99')).to eq Money.new(999, 'USD')
115
119
  end
116
120
 
121
+ it 'should use provided currency over symbol' do
122
+ expect(Monetize.parse('$1.05 CAD')).to eq Money.new(105, 'CAD')
123
+ end
124
+
125
+ it 'ignores ZAR symbols that is part of a text' do
126
+ expect(Monetize.parse('EUR 9.99')).to eq Money.new(999, 'EUR')
127
+ expect(Monetize.parse('9.99 EUR')).to eq Money.new(999, 'EUR')
128
+ end
129
+
117
130
  context 'negatives' do
118
131
  it 'ignores the ambiguous kr symbol' do
119
132
  # Could mean either of DKK, EEK, ISK, NOK, SEK
@@ -212,6 +225,14 @@ describe Monetize do
212
225
  expect(Monetize.parse('-$5.95-')).to be_nil
213
226
  end
214
227
 
228
+ it 'returns nil when more than 2 digit separators are used' do
229
+ expect(Monetize.parse("123.34,56'89 EUR")).to be_nil
230
+ end
231
+
232
+ it 'parses correctly strings with repeated digit separator' do
233
+ expect(Monetize.parse('19.12.89', 'EUR')).to eq Money.new(191_289_00, 'EUR')
234
+ end
235
+
215
236
  it 'parses correctly strings with exactly 3 decimal digits' do
216
237
  expect(Monetize.parse('6,534', 'EUR')).to eq Money.new(653, 'EUR')
217
238
  expect(Monetize.parse('6.534', 'EUR')).to eq Money.new(653, 'EUR')
@@ -234,7 +255,7 @@ describe Monetize do
234
255
  context 'parsing an instance of Numeric class' do
235
256
  let(:integer) { 10 }
236
257
  let(:float) { 10.0 }
237
- let(:big_decimal) { BigDecimal.new('10') }
258
+ let(:big_decimal) { BigDecimal('10') }
238
259
 
239
260
  [:integer, :float, :big_decimal].each do |type|
240
261
  it "returns a new Money object based on the #{type} input" do
@@ -336,6 +357,10 @@ describe Monetize do
336
357
  expect(collection.first).to eq Monetize.parse('$4')
337
358
  expect(collection.last).to eq Monetize.parse('$10')
338
359
  end
360
+
361
+ it 'raises an error if argument is invalid' do
362
+ expect { Monetize.parse_collection(nil) }.to raise_error Monetize::ArgumentError
363
+ end
339
364
  end
340
365
 
341
366
  describe '.from_string' do
@@ -419,31 +444,31 @@ describe Monetize do
419
444
 
420
445
  describe '.from_bigdecimal' do
421
446
  it 'converts given amount to cents' do
422
- expect(Monetize.from_bigdecimal(BigDecimal.new('1'))).to eq Money.new(1_00)
423
- expect(Monetize.from_bigdecimal(BigDecimal.new('1'))).to eq Money.new(1_00, 'USD')
424
- expect(Monetize.from_bigdecimal(BigDecimal.new('1'), 'EUR')).to eq Money.new(1_00, 'EUR')
447
+ expect(Monetize.from_bigdecimal(BigDecimal('1'))).to eq Money.new(1_00)
448
+ expect(Monetize.from_bigdecimal(BigDecimal('1'))).to eq Money.new(1_00, 'USD')
449
+ expect(Monetize.from_bigdecimal(BigDecimal('1'), 'EUR')).to eq Money.new(1_00, 'EUR')
425
450
  end
426
451
 
427
452
  it 'respects :subunit_to_unit currency property' do
428
- expect(Monetize.from_bigdecimal(BigDecimal.new('1'), 'USD')).to eq Money.new(1_00, 'USD')
429
- expect(Monetize.from_bigdecimal(BigDecimal.new('1'), 'TND')).to eq Money.new(1_000, 'TND')
430
- expect(Monetize.from_bigdecimal(BigDecimal.new('1'), 'JPY')).to eq Money.new(1, 'JPY')
453
+ expect(Monetize.from_bigdecimal(BigDecimal('1'), 'USD')).to eq Money.new(1_00, 'USD')
454
+ expect(Monetize.from_bigdecimal(BigDecimal('1'), 'TND')).to eq Money.new(1_000, 'TND')
455
+ expect(Monetize.from_bigdecimal(BigDecimal('1'), 'JPY')).to eq Money.new(1, 'JPY')
431
456
  end
432
457
 
433
458
  it 'respects rounding mode when rounding amount to the nearest cent' do
434
- amount = BigDecimal.new('1.005')
459
+ amount = BigDecimal('1.005')
435
460
 
436
461
  expect(Monetize.from_bigdecimal(amount, 'USD')).to eq Money.from_amount(amount, 'USD')
437
462
  end
438
463
 
439
464
  it 'accepts a currency options' do
440
- m = Monetize.from_bigdecimal(BigDecimal.new('1'))
465
+ m = Monetize.from_bigdecimal(BigDecimal('1'))
441
466
  expect(m.currency).to eq Money.default_currency
442
467
 
443
- m = Monetize.from_bigdecimal(BigDecimal.new('1'), Money::Currency.wrap('EUR'))
468
+ m = Monetize.from_bigdecimal(BigDecimal('1'), Money::Currency.wrap('EUR'))
444
469
  expect(m.currency).to eq Money::Currency.wrap('EUR')
445
470
 
446
- m = Monetize.from_bigdecimal(BigDecimal.new('1'), 'EUR')
471
+ m = Monetize.from_bigdecimal(BigDecimal('1'), 'EUR')
447
472
  expect(m.currency).to eq Money::Currency.wrap('EUR')
448
473
  end
449
474
 
@@ -457,11 +482,11 @@ describe Monetize do
457
482
  end
458
483
 
459
484
  it 'keeps precision' do
460
- expect(Monetize.from_bigdecimal(BigDecimal.new('1'))).to eq Money.new(100)
461
- expect(Monetize.from_bigdecimal(BigDecimal.new('1.23456'))).to eq Money.new(123.456)
462
- expect(Monetize.from_bigdecimal(BigDecimal.new('-1.23456'))).to eq Money.new(-123.456)
463
- expect(Monetize.from_bigdecimal(BigDecimal.new('1.23456'))).to eq Money.new(123.456, 'USD')
464
- expect(Monetize.from_bigdecimal(BigDecimal.new('1.23456'), 'EUR')).to eq Money.new(123.456, 'EUR')
485
+ expect(Monetize.from_bigdecimal(BigDecimal('1'))).to eq Money.new(100)
486
+ expect(Monetize.from_bigdecimal(BigDecimal('1.23456'))).to eq Money.new(123.456)
487
+ expect(Monetize.from_bigdecimal(BigDecimal('-1.23456'))).to eq Money.new(-123.456)
488
+ expect(Monetize.from_bigdecimal(BigDecimal('1.23456'))).to eq Money.new(123.456, 'USD')
489
+ expect(Monetize.from_bigdecimal(BigDecimal('1.23456'), 'EUR')).to eq Money.new(123.456, 'EUR')
465
490
 
466
491
  expect('1'.to_money).to eq Money.new(100)
467
492
  expect('1.23456'.to_money).to eq Money.new(123.456)
@@ -476,7 +501,7 @@ describe Monetize do
476
501
  it 'converts given amount to cents' do
477
502
  expect(Monetize.from_numeric(1)).to eq Money.new(1_00)
478
503
  expect(Monetize.from_numeric(1.0)).to eq Money.new(1_00)
479
- expect(Monetize.from_numeric(BigDecimal.new('1'))).to eq Money.new(1_00)
504
+ expect(Monetize.from_numeric(BigDecimal('1'))).to eq Money.new(1_00)
480
505
  end
481
506
 
482
507
  it 'raises ArgumentError with unsupported argument' do
@@ -508,6 +533,20 @@ describe Monetize do
508
533
  end
509
534
 
510
535
  describe '.extract_cents' do
536
+ it 'is deprecated' do
537
+ allow(Monetize).to receive(:warn)
538
+
539
+ Monetize.extract_cents('100')
540
+
541
+ expect(Monetize)
542
+ .to have_received(:warn)
543
+ .with('[DEPRECATION] Monetize.extract_cents is deprecated. Use Monetize.parse().cents')
544
+ end
545
+
546
+ it 'extracts cents from a given string' do
547
+ expect(Monetize.extract_cents('10.99')).to eq(1099)
548
+ end
549
+
511
550
  it "correctly treats pipe marks '|' in input (regression test)" do
512
551
  expect(Monetize.extract_cents('100|0')).to eq Monetize.extract_cents('100!0')
513
552
  end
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'coveralls'
3
- Coveralls.wear!
4
2
 
5
3
  require 'money'
6
4
 
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
- autorequire:
8
+ - Anthony Dmitriyev
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2018-08-11 00:00:00.000000000 Z
12
+ date: 2021-01-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: money
@@ -28,30 +29,30 @@ dependencies:
28
29
  name: bundler
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - "~>"
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: '1.3'
34
+ version: '0'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - "~>"
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
- version: '1.3'
41
+ version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rake
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ">="
46
+ - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: '0'
48
+ version: '10.2'
48
49
  type: :development
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ">="
53
+ - - "~>"
53
54
  - !ruby/object:Gem::Version
54
- version: '0'
55
+ version: '10.2'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: rspec
57
58
  requirement: !ruby/object:Gem::Requirement
@@ -69,14 +70,14 @@ dependencies:
69
70
  description: A library for converting various objects into `Money` objects.
70
71
  email:
71
72
  - shane@emmons.io
73
+ - anthony.dmitriyev@gmail.com
72
74
  executables: []
73
75
  extensions: []
74
76
  extra_rdoc_files: []
75
77
  files:
76
- - ".coveralls.yml"
78
+ - ".github/workflows/ruby.yml"
77
79
  - ".gitignore"
78
80
  - ".rubocop.yml"
79
- - ".travis.yml"
80
81
  - CHANGELOG.md
81
82
  - CONTRIBUTING.md
82
83
  - Gemfile
@@ -101,8 +102,11 @@ files:
101
102
  homepage: https://github.com/RubyMoney/monetize
102
103
  licenses:
103
104
  - MIT
104
- metadata: {}
105
- post_install_message:
105
+ metadata:
106
+ changelog_uri: https://github.com/RubyMoney/monetize/blob/master/CHANGELOG.md
107
+ source_code_uri: https://github.com/RubyMoney/monetize/
108
+ bug_tracker_uri: https://github.com/RubyMoney/monetize/issues
109
+ post_install_message:
106
110
  rdoc_options: []
107
111
  require_paths:
108
112
  - lib
@@ -117,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
121
  - !ruby/object:Gem::Version
118
122
  version: '0'
119
123
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.6.8
122
- signing_key:
124
+ rubygems_version: 3.0.3
125
+ signing_key:
123
126
  specification_version: 4
124
127
  summary: A library for converting various objects into `Money` objects.
125
128
  test_files:
@@ -1 +0,0 @@
1
- repo_token: pbKErt5rAW1iRYGMIAGGAAHfVRmiBzxfd
@@ -1,15 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.10
7
- - 2.2.10
8
- - 2.3.7
9
- - 2.4.4
10
- - 2.5.1
11
- - jruby-9.0.5.0
12
- script: bundle exec rspec spec
13
- notifications:
14
- recipients:
15
- - shane@emmons.io