-
Notifications
You must be signed in to change notification settings - Fork 113
Description
Malaysian ringgit, ISO code: MYR, symbol: RM.
The commit that broke our code is this one which prioritises ISO code over a symbol. It makes the incorrect assumption that the first line only matches ISO codes:
monetize/lib/monetize/parser.rb
Lines 72 to 73 in a068081
computed_currency = input[/[A-Z]{2,3}/] | |
computed_currency ||= compute_currency if assume_from_symbol? |
While it's true that the regexp doesn't match any symbols in CURRENCY_SYMBOLS
, there are a few currencies where the symbol is 2-3 capital letters
Using version 1.9.4
Monetize::Parser::CURRENCY_SYMBOLS["RM"] = "MYR"
Monetize.parse("100 RM")
=> #<Money fractional:10000 currency:MYR>
In version 1.11.0, expected same result, got
=> nil
I propose that if
computed_currency = input[/[A-Z]{2,3}/]
returns a match, the code will check if CURRENCY_SYMBOLS
contains it as a key before assuming that it's an ISO code.
As a side note: what is the recommended way of "registering" symbols that are not included in the gem? In our app we've added them to the Monetize::Parser::CURRENCY_SYMBOLS
hash, but maybe this is not recommended?