Class: InCSV::Types::Currency

Inherits:
ColumnType show all
Defined in:
lib/incsv/types/currency.rb

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

Constructor Details

This class inherits a constructor from InCSV::ColumnType

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_databaseObject



6
7
8
# File 'lib/incsv/types/currency.rb', line 6

def self.for_database
  "DECIMAL(10,2)"
end

Instance Method Details

#match?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/incsv/types/currency.rb', line 10

def match?
  value.strip.match(MATCH_EXPRESSION)
end