Class: Kladr::DBF::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/dbf/dbf/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, length, decimal) ⇒ Column

Returns a new instance of Column.

Raises:



8
9
10
11
# File 'lib/dbf/dbf/column.rb', line 8

def initialize(name, type, length, decimal)
  raise ColumnLengthError, "field length must be greater than 0" unless length > 0
  @name, @type, @length, @decimal = strip_non_ascii_chars(name), type, length, decimal
end

Instance Attribute Details

#decimalObject (readonly)

Returns the value of attribute decimal.



6
7
8
# File 'lib/dbf/dbf/column.rb', line 6

def decimal
  @decimal
end

#lengthObject (readonly)

Returns the value of attribute length.



6
7
8
# File 'lib/dbf/dbf/column.rb', line 6

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/dbf/dbf/column.rb', line 6

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/dbf/dbf/column.rb', line 6

def type
  @type
end

Instance Method Details

#schema_definitionObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dbf/dbf/column.rb', line 13

def schema_definition
  "\"#{underscore(name)}\", " + 
  case type
  when "N" # number
    if decimal > 0
      ":float"
    else
      ":integer"
    end
  when "D" # date
    ":datetime"
  when "L" # boolean
    ":boolean"
  when "M" # memo
    ":text"
  else
    ":string, :limit => #{length}"
  end + 
  "\n"
end