monetize 1.10.0 → 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: 63f57158028647c2bde5bac4c2186e16e9a3874d6c6d756b08e091d1357fcfcc
4
- data.tar.gz: 5dd093ceef480ffd21fbfaa3a0912cdc7421f797c4570a2a8bde9665534aa6ff
3
+ metadata.gz: 10b41ae5e40bb51d6d3fae9eb49cdd73c7be8542dd80c43467a12483f1c8e63b
4
+ data.tar.gz: 86ccb9489502a681cc271cca544eb2f1dbf9268034f1a7b83e2d1ddaa97d4f9a
5
5
  SHA512:
6
- metadata.gz: 6b4001dd8967421873f84b9b0201bd0985d1388d89c41c2c048498db185cd2d4bdd144c581293fff70e34c5fb88aecbf68f2e3d2d086f1f278f58047e519aebe
7
- data.tar.gz: 468cc1fd1f127eb570e8599ef20309240f5e95c5731374848c663995d4935e4bb6773ffd40691d2bd4148c58e51e641806a3d7a97d25851a5877bc74621fe059
6
+ metadata.gz: c25475d1877bc00dceb06e01cb6863e4e805e87128320b6f77f2a7847930d22e1930ec9ee7cbe0f7efc462428348c05937121b2c45830cbf8f2003fd89dcd64c
7
+ data.tar.gz: fe0a09adc661a2d4afbbc7ee7ee7327d55fef5be9045f8c54d487121e6cc7057d9b53e1fa3890abad382fb8a71e178c69da04a2d95c069cd07880ae22f5f6818
@@ -9,9 +9,9 @@ name: Ruby
9
9
 
10
10
  on:
11
11
  push:
12
- branches: [ master ]
12
+ branches: [ main ]
13
13
  pull_request:
14
- branches: [ master ]
14
+ branches: [ main ]
15
15
 
16
16
  jobs:
17
17
  test:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
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
+
3
6
  ## 1.10.0
4
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`.
5
8
 
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.
@@ -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,6 +59,12 @@ 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
@@ -120,8 +126,13 @@ module Monetize
120
126
  else
121
127
  possible_major, possible_minor = split_major_minor(num, delimiter)
122
128
 
123
- if possible_minor.length != 3 || possible_major.length > 3 || delimiter == '.'
124
- # 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
125
136
  [possible_major, possible_minor]
126
137
  else
127
138
  ["#{possible_major}#{possible_minor}", '00']
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Monetize
4
- VERSION = '1.10.0'
4
+ VERSION = '1.11.0'
5
5
  end
@@ -320,6 +320,29 @@ describe Monetize do
320
320
  expect('€8.883.331,0034'.to_money('EU4')).to eq Money.new(8_883_331_0034, 'EU4')
321
321
  # rubocop:enable Style/NumericLiterals
322
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
323
346
  end
324
347
  end
325
348
 
@@ -333,6 +356,10 @@ describe Monetize do
333
356
  it 'raises ArgumentError when unable to detect polarity' do
334
357
  expect { Monetize.parse!('-$5.95-') }.to raise_error Monetize::ParseError
335
358
  end
359
+
360
+ it 'raises ArgumentError with invalid format' do
361
+ expect { Monetize.parse!('11..0') }.to raise_error Monetize::ParseError
362
+ end
336
363
  end
337
364
 
338
365
  describe '.parse_collection' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-17 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
@@ -81,7 +81,7 @@ files:
81
81
  - CHANGELOG.md
82
82
  - CONTRIBUTING.md
83
83
  - Gemfile
84
- - LICENSE.txt
84
+ - LICENSE
85
85
  - README.md
86
86
  - Rakefile
87
87
  - lib/monetize.rb
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubygems_version: 3.0.3
124
+ rubygems_version: 3.2.3
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: A library for converting various objects into `Money` objects.
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.