Class: Money::Parser::Fuzzy
- Inherits:
-
Object
- Object
- Money::Parser::Fuzzy
- Defined in:
- lib/money/parser/fuzzy.rb
Direct Known Subclasses
Defined Under Namespace
Classes: MoneyFormatError
Constant Summary collapse
- MARKS =
%w[. , · ’ ˙ '] + [' ']
- ESCAPED_MARKS =
Regexp.escape(MARKS.join)
- ESCAPED_NON_SPACE_MARKS =
Regexp.escape((MARKS - [' ']).join)
- ESCAPED_NON_DOT_MARKS =
Regexp.escape((MARKS - ['.']).join)
- ESCAPED_NON_COMMA_MARKS =
Regexp.escape((MARKS - [',']).join)
- NUMERIC_REGEX =
/( [\+\-]? [\d#{ESCAPED_NON_SPACE_MARKS}][\d#{ESCAPED_MARKS}]* )/ix
- DOT_DECIMAL_REGEX =
1,234,567.89
/\A [\+\-]? (?: (?:\d+) (?:[#{ESCAPED_NON_DOT_MARKS}]\d{3})+ (?:\.\d{2,})? ) \z/ix
- COMMA_DECIMAL_REGEX =
1.234.567,89
/\A [\+\-]? (?: (?:\d+) (?:[#{ESCAPED_NON_COMMA_MARKS}]\d{3})+ (?:\,\d{2,})? ) \z/ix
- INDIAN_NUMERIC_REGEX =
12,34,567.89
/\A [\+\-]? (?: (?:\d+) (?:\,\d{2})+ (?:\,\d{3}) (?:\.\d{2})? ) \z/ix
- CHINESE_NUMERIC_REGEX =
1,1123,4567.89
/\A [\+\-]? (?: (?:\d+) (?:\,\d{4})+ (?:\.\d{2})? ) \z/ix
Class Method Summary collapse
Instance Method Summary collapse
-
#parse(input, currency = nil, strict: false) ⇒ Money
deprecated
Deprecated.
Use LocaleAware.parse or Simple.parse instead.
Class Method Details
.parse(input, currency = nil, **options) ⇒ Object
60 61 62 |
# File 'lib/money/parser/fuzzy.rb', line 60 def self.parse(input, currency = nil, **) new.parse(input, currency, **) end |
Instance Method Details
#parse(input, currency = nil, strict: false) ⇒ Money
Deprecated.
Use LocaleAware.parse or Simple.parse instead.
Parses an input string and attempts to find the decimal separator based on certain heuristics, like the amount decimals for the fractional part a currency has or the incorrect notion a currency has a defined decimal separator (this is a property of the locale). While these heuristics can lead to the expected result for some cases, the other cases can lead to surprising results such as parsed amounts being 1000x larger than intended.
74 75 76 77 78 |
# File 'lib/money/parser/fuzzy.rb', line 74 def parse(input, currency = nil, strict: false) currency = Money::Helpers.value_to_currency(currency) amount = extract_amount_from_string(input, currency, strict) Money.new(amount, currency) end |