Class: InCSV::ColumnType

Inherits:
Object
  • Object
show all
Defined in:
lib/incsv/column_type.rb

Overview

An abstract class, inherited by all types of column. Specifies the interface that all these classes must adhere to.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ ColumnType

Returns a new instance of ColumnType.



30
31
32
# File 'lib/incsv/column_type.rb', line 30

def initialize(value)
  @value = value
end

Class Method Details

.clean_value(value) ⇒ Object

Returns a cleaned/preprocessed version of an arbitrary value.



47
48
49
# File 'lib/incsv/column_type.rb', line 47

def self.clean_value(value)
  value
end

.for_databaseObject

The type of the column from the perspective of the database. By default this is the same as the class name, so a column of type String would go into the database as a :string.

Possible column types can be found here:

sequel.jeremyevans.net/rdoc/files/doc/schema_modification_rdoc.html#label-Column+types

This can also be a string, for database-specific features or in order to specify lengths easily. Examples might be:

VARCHAR(255) DECIMAL(10, 2) BOOLEAN



26
27
28
# File 'lib/incsv/column_type.rb', line 26

def self.for_database
  self.to_s.sub(/.*::/, "").downcase.to_sym
end

.nameObject

A symbol representation of what type of data this ColumnType represents. By default this is taken from the class name (so this class would be :columntype).



8
9
10
# File 'lib/incsv/column_type.rb', line 8

def self.name
  self.to_s.sub(/.*::/, "").downcase.to_sym
end

Instance Method Details

#clean_valueObject

Returns a cleaned/preprocessed version of the given value.



42
43
44
# File 'lib/incsv/column_type.rb', line 42

def clean_value
  self.class.clean_value(@value)
end

#match?Boolean

Returns true if the given value (supplied in the constructor) is of the type represented by this column; returns false otherwise.

Returns:

  • (Boolean)


37
38
39
# File 'lib/incsv/column_type.rb', line 37

def match?
  false
end