Skip to content

Commit 1ce4de6

Browse files
authored
Merge pull request #189 from sbulat/sbulat-handle-multiple-delimeters
Improve handling multiple delimiters in input
2 parents f628456 + 5f20048 commit 1ce4de6

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Current
4+
- Fix parsing multiple delimeters in the amount, after BigDecimal updates
5+
36
## 1.13.0
47
- **Breaking change**: check ISO currency code validity when parsing strings with `to_money`
58
- Adds `expect_whole_subunits` option when fractional subunits are expected

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ elsif RUBY_VERSION =~ /^1/
1010
gem 'i18n', '~> 0.9'
1111
end
1212

13+
if RUBY_VERSION >= '3.4.0'
14+
gem 'bigdecimal'
15+
end
16+
1317
gemspec

lib/monetize/parser.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ def regex_safe_symbols
184184
end
185185

186186
def split_major_minor(num, delimiter)
187-
major, minor = num.split(delimiter)
188-
[major, minor || '00']
187+
splits = num.split(delimiter)
188+
fail ParseError, 'Invalid amount (multiple delimiters)' if splits.length > 2
189+
190+
[splits[0], splits[1] || '00']
189191
end
190192

191193
def currency_symbol_regex

0 commit comments

Comments
 (0)