monetize 1.9.4 → 1.11.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
2
  SHA256:
3
- metadata.gz: 6268692fea7908fbc268790bf98cca9795df28eed380b07d2683eed6f5dad4d1
4
- data.tar.gz: 8d795add425b915dc88ecf910505af69b7c1f340ae412083e4c230f0622c2e27
3
+ metadata.gz: 10b41ae5e40bb51d6d3fae9eb49cdd73c7be8542dd80c43467a12483f1c8e63b
4
+ data.tar.gz: 86ccb9489502a681cc271cca544eb2f1dbf9268034f1a7b83e2d1ddaa97d4f9a
5
5
  SHA512:
6
- metadata.gz: e4291ebf0a43a4bea5a2973186b1dca2d9d9fa08729acb956073efb2628d6898620f5eb1110ade3bba5dbac313894babd4ab59c0d1db92b8cb8e041974a0d402
7
- data.tar.gz: 06d080183a460c5777b9f7443655bcb00d214ee18a6294f0838a3ac4bfec95715ab1ad5704001d286a6bc1ed0966a4a031942bd946ef9d249372ea527a120785
6
+ metadata.gz: c25475d1877bc00dceb06e01cb6863e4e805e87128320b6f77f2a7847930d22e1930ec9ee7cbe0f7efc462428348c05937121b2c45830cbf8f2003fd89dcd64c
7
+ data.tar.gz: fe0a09adc661a2d4afbbc7ee7ee7327d55fef5be9045f8c54d487121e6cc7057d9b53e1fa3890abad382fb8a71e178c69da04a2d95c069cd07880ae22f5f6818
@@ -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: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
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
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.11.0
4
+ - When parsing a string assume a single separator to be a decimal mark when number starts with 0
5
+
6
+ ## 1.10.0
7
+ - 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`.
8
+
3
9
  ## 1.9.4
4
10
  - Fix symbol parsing that are surrounded by other characters
5
11
 
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'coveralls', '>= 0.8.20', require: false
4
-
5
3
  # JSON and I18n gem no longer supports ruby < 2.0.0
6
4
  if defined?(JRUBY_VERSION)
7
5
  gem 'json'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Shane Emmons
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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
 
@@ -50,7 +50,7 @@ module Monetize
50
50
 
51
51
  major, minor = extract_major_minor(num, currency)
52
52
 
53
- amount = BigDecimal([major, minor].join(DEFAULT_DECIMAL_MARK))
53
+ amount = to_big_decimal([major, minor].join(DEFAULT_DECIMAL_MARK))
54
54
  amount = apply_multiplier(multiplier_exp, amount)
55
55
  amount = apply_sign(negative, amount)
56
56
 
@@ -59,12 +59,19 @@ module Monetize
59
59
 
60
60
  private
61
61
 
62
+ def to_big_decimal(value)
63
+ BigDecimal(value)
64
+ rescue ::ArgumentError => err
65
+ fail ParseError, err.message
66
+ end
67
+
62
68
  attr_reader :input, :fallback_currency, :options
63
69
 
64
70
  def parse_currency
65
71
  computed_currency = nil
66
- computed_currency = compute_currency if assume_from_symbol?
67
- computed_currency ||= input[/[A-Z]{2,3}/]
72
+ computed_currency = input[/[A-Z]{2,3}/]
73
+ computed_currency ||= compute_currency if assume_from_symbol?
74
+
68
75
 
69
76
  computed_currency || fallback_currency || Money.default_currency
70
77
  end
@@ -119,8 +126,13 @@ module Monetize
119
126
  else
120
127
  possible_major, possible_minor = split_major_minor(num, delimiter)
121
128
 
122
- if possible_minor.length != 3 || possible_major.length > 3 || delimiter == '.'
123
- # Doesn't look like thousands separator
129
+ # Doesn't look like thousands separator
130
+ is_decimal_mark = possible_minor.length != 3 ||
131
+ possible_major.length > 3 ||
132
+ possible_major.to_i == 0 ||
133
+ delimiter == '.'
134
+
135
+ if is_decimal_mark
124
136
  [possible_major, possible_minor]
125
137
  else
126
138
  ["#{possible_major}#{possible_minor}", '00']
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Monetize
4
- VERSION = '1.9.4'
4
+ VERSION = '1.11.0'
5
5
  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
@@ -118,6 +118,10 @@ describe Monetize do
118
118
  expect(Monetize.parse('L9.99')).to eq Money.new(999, 'USD')
119
119
  end
120
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
+
121
125
  it 'ignores ZAR symbols that is part of a text' do
122
126
  expect(Monetize.parse('EUR 9.99')).to eq Money.new(999, 'EUR')
123
127
  expect(Monetize.parse('9.99 EUR')).to eq Money.new(999, 'EUR')
@@ -316,6 +320,29 @@ describe Monetize do
316
320
  expect('€8.883.331,0034'.to_money('EU4')).to eq Money.new(8_883_331_0034, 'EU4')
317
321
  # rubocop:enable Style/NumericLiterals
318
322
  end
323
+
324
+ it 'parses strings deducing a decimal mark when a single delimiter is used and major is 0' do
325
+ expect('$0,4'.to_money('BAR')).to eq Money.new(4000, 'BAR')
326
+ expect('€0.4'.to_money('EU4')).to eq Money.new(4000, 'EU4')
327
+
328
+ expect('$0,04'.to_money('BAR')).to eq Money.new(400, 'BAR')
329
+ expect('€0.04'.to_money('EU4')).to eq Money.new(400, 'EU4')
330
+
331
+ expect('$0,004'.to_money('BAR')).to eq Money.new(40, 'BAR')
332
+ expect('€0.004'.to_money('EU4')).to eq Money.new(40, 'EU4')
333
+
334
+ expect('$0,0004'.to_money('BAR')).to eq Money.new(4, 'BAR')
335
+ expect('€0.0004'.to_money('EU4')).to eq Money.new(4, 'EU4')
336
+
337
+ expect('$0,0024'.to_money('BAR')).to eq Money.new(24, 'BAR')
338
+ expect('€0.0024'.to_money('EU4')).to eq Money.new(24, 'EU4')
339
+
340
+ expect('$0,0324'.to_money('BAR')).to eq Money.new(324, 'BAR')
341
+ expect('€0.0324'.to_money('EU4')).to eq Money.new(324, 'EU4')
342
+
343
+ expect('$0,5324'.to_money('BAR')).to eq Money.new(5324, 'BAR')
344
+ expect('€0.5324'.to_money('EU4')).to eq Money.new(5324, 'EU4')
345
+ end
319
346
  end
320
347
  end
321
348
 
@@ -329,6 +356,10 @@ describe Monetize do
329
356
  it 'raises ArgumentError when unable to detect polarity' do
330
357
  expect { Monetize.parse!('-$5.95-') }.to raise_error Monetize::ParseError
331
358
  end
359
+
360
+ it 'raises ArgumentError with invalid format' do
361
+ expect { Monetize.parse!('11..0') }.to raise_error Monetize::ParseError
362
+ end
332
363
  end
333
364
 
334
365
  describe '.parse_collection' do
data/spec/spec_helper.rb CHANGED
@@ -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,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.4
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
8
  - Anthony Dmitriyev
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-07 00:00:00.000000000 Z
12
+ date: 2021-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: money
@@ -75,14 +75,13 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - ".coveralls.yml"
78
+ - ".github/workflows/ruby.yml"
79
79
  - ".gitignore"
80
80
  - ".rubocop.yml"
81
- - ".travis.yml"
82
81
  - CHANGELOG.md
83
82
  - CONTRIBUTING.md
84
83
  - Gemfile
85
- - LICENSE.txt
84
+ - LICENSE
86
85
  - README.md
87
86
  - Rakefile
88
87
  - lib/monetize.rb
@@ -107,7 +106,7 @@ metadata:
107
106
  changelog_uri: https://github.com/RubyMoney/monetize/blob/master/CHANGELOG.md
108
107
  source_code_uri: https://github.com/RubyMoney/monetize/
109
108
  bug_tracker_uri: https://github.com/RubyMoney/monetize/issues
110
- post_install_message:
109
+ post_install_message:
111
110
  rdoc_options: []
112
111
  require_paths:
113
112
  - lib
@@ -122,8 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
121
  - !ruby/object:Gem::Version
123
122
  version: '0'
124
123
  requirements: []
125
- rubygems_version: 3.0.3
126
- signing_key:
124
+ rubygems_version: 3.2.3
125
+ signing_key:
127
126
  specification_version: 4
128
127
  summary: A library for converting various objects into `Money` objects.
129
128
  test_files:
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- repo_token: pbKErt5rAW1iRYGMIAGGAAHfVRmiBzxfd
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- sudo: false
2
- language:
3
- - ruby
4
- - java
5
- rvm:
6
- - 1.9.3
7
- - 2.0.0
8
- - 2.1.10
9
- - 2.2.10
10
- - 2.3.8
11
- - 2.4.6
12
- - 2.5.5
13
- - 2.6.3
14
- - jruby-9.0.5.0
15
- jdk: openjdk8
16
- before_install:
17
- - gem install bundler --version '~> 1.17'
18
- script: bundle exec rspec spec
19
- notifications:
20
- recipients:
21
- - shane@emmons.io
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Shane Emmons
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.