Class: InCSV::Types::Currency
Constant Summary
collapse
- MATCH_EXPRESSION =
/\A(\$|£)([0-9,\.]+)\z/
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ColumnType
#clean_value, #initialize, name
Class Method Details
.clean_value(value) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/incsv/types/currency.rb', line 14
def self.clean_value(value)
return unless value
value.strip.match(MATCH_EXPRESSION) do |match|
BigDecimal(match[2].delete(","))
end
end
|
.for_database ⇒ Object
6
7
8
|
# File 'lib/incsv/types/currency.rb', line 6
def self.for_database
"DECIMAL(10,2)"
end
|
Instance Method Details
#match? ⇒ Boolean
10
11
12
|
# File 'lib/incsv/types/currency.rb', line 10
def match?
value.strip.match(MATCH_EXPRESSION)
end
|