lib/monetize/parser.rb in monetize-1.10.0 vs lib/monetize/parser.rb in monetize-1.11.0
- old
+ new
@@ -48,19 +48,25 @@
num.chop! if num =~ /[\.|,]$/
major, minor = extract_major_minor(num, currency)
- amount = BigDecimal([major, minor].join(DEFAULT_DECIMAL_MARK))
+ amount = to_big_decimal([major, minor].join(DEFAULT_DECIMAL_MARK))
amount = apply_multiplier(multiplier_exp, amount)
amount = apply_sign(negative, amount)
[amount, currency]
end
private
+ def to_big_decimal(value)
+ BigDecimal(value)
+ rescue ::ArgumentError => err
+ fail ParseError, err.message
+ end
+
attr_reader :input, :fallback_currency, :options
def parse_currency
computed_currency = nil
computed_currency = input[/[A-Z]{2,3}/]
@@ -118,11 +124,16 @@
# Multiple matches; treat as thousands separator
[num.gsub(delimiter, ''), '00']
else
possible_major, possible_minor = split_major_minor(num, delimiter)
- if possible_minor.length != 3 || possible_major.length > 3 || delimiter == '.'
- # Doesn't look like thousands separator
+ # Doesn't look like thousands separator
+ is_decimal_mark = possible_minor.length != 3 ||
+ possible_major.length > 3 ||
+ possible_major.to_i == 0 ||
+ delimiter == '.'
+
+ if is_decimal_mark
[possible_major, possible_minor]
else
["#{possible_major}#{possible_minor}", '00']
end
end