Class: InCSV::Types::Decimal
- Inherits:
-
ColumnType
- Object
- ColumnType
- InCSV::Types::Decimal
- Defined in:
- lib/incsv/types/decimal.rb
Overview
Represents a fixed-precision decimal number.
Class Method Summary collapse
-
.clean_value(value) ⇒ Object
Converts values to BigDecimal format before storage.
-
.for_database ⇒ Object
What type of column to create in the database.
Instance Method Summary collapse
-
#match? ⇒ Boolean
Returns true if the supplied value is a decimal number or an integer, since integers are also valid decimals.
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
Converts values to BigDecimal format before storage.
23 24 25 |
# File 'lib/incsv/types/decimal.rb', line 23 def self.clean_value(value) BigDecimal(value.strip) end |
.for_database ⇒ Object
What type of column to create in the database.
6 7 8 |
# File 'lib/incsv/types/decimal.rb', line 6 def self.for_database "DECIMAL(15,10)" end |
Instance Method Details
#match? ⇒ Boolean
Returns true if the supplied value is a decimal number or an integer, since integers are also valid decimals.
This allows for columns that contain e.g.:
123.45 123 128.2
18 19 20 |
# File 'lib/incsv/types/decimal.rb', line 18 def match? value.strip.match(/\A[0-9]+\.?([0-9]+)?\z/) end |