Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions lib/monetize/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Parser
'NT$'=> 'TWD',
'₱' => 'PHP',
}


CURRENCY_SYMBOL_REGEX = /(?<![A-Z])(#{CURRENCY_SYMBOLS.keys.map { |key| Regexp.escape(key) }.join('|')})(?![A-Z])/i
MULTIPLIER_SUFFIXES = { 'K' => 3, 'M' => 6, 'B' => 9, 'T' => 12 }
MULTIPLIER_SUFFIXES.default = 0
MULTIPLIER_REGEXP = Regexp.new(format('^(.*?\d)(%s)\b([^\d]*)$', MULTIPLIER_SUFFIXES.keys.join('|')), 'i')
Expand Down Expand Up @@ -100,7 +101,7 @@ def apply_sign(negative, amount)
end

def compute_currency
match = input.match(currency_symbol_regex)
match = input.match(CURRENCY_SYMBOL_REGEX)
CURRENCY_SYMBOLS[match.to_s] if match
end

Expand Down Expand Up @@ -179,17 +180,9 @@ def extract_sign(input)
result
end

def regex_safe_symbols
CURRENCY_SYMBOLS.keys.map { |key| Regexp.escape(key) }.join('|')
end

def split_major_minor(num, delimiter)
major, minor = num.split(delimiter)
[major, minor || '00']
end

def currency_symbol_regex
/(?<![A-Z])(#{regex_safe_symbols})(?![A-Z])/i
end
end
end