lib/monetize.rb in monetize-1.0.0 vs lib/monetize.rb in monetize-1.1.0
- old
+ new
@@ -19,17 +19,18 @@
# @attr_accessor [true, false] assume_from_symbol Use this to enable the
# ability to assume the currency from a passed symbol
attr_accessor :assume_from_symbol
end
- def self.parse(input, currency = Money.default_currency)
+ def self.parse(input, currency = Money.default_currency, options = {})
input = input.to_s.strip
- computed_currency = compute_currency(input)
- if not assume_from_symbol
- computed_currency = input[/[A-Z]{2,3}/] || currency
- end
+ computed_currency = if options.fetch(:assume_from_symbol) { assume_from_symbol }
+ compute_currency(input)
+ else
+ input[/[A-Z]{2,3}/]
+ end
currency = computed_currency || currency || Money.default_currency
currency = Money::Currency.wrap(currency)
fractional = extract_cents(input, currency)
@@ -167,8 +168,8 @@
Regexp.escape(key)
}.join('|')
end
def self.currency_symbol_regex
- /\A(?<symbol>#{regex_safe_symbols})/
+ /\A[\+|\-]?(?<symbol>#{regex_safe_symbols})/
end
end