Class: Kladr::DBF::Column
- Inherits:
-
Object
- Object
- Kladr::DBF::Column
- Defined in:
- lib/dbf/dbf/column.rb
Instance Attribute Summary collapse
-
#decimal ⇒ Object
readonly
Returns the value of attribute decimal.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, type, length, decimal) ⇒ Column
constructor
A new instance of Column.
- #schema_definition ⇒ Object
Constructor Details
#initialize(name, type, length, decimal) ⇒ Column
Returns a new instance of Column.
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
#decimal ⇒ Object (readonly)
Returns the value of attribute decimal.
6 7 8 |
# File 'lib/dbf/dbf/column.rb', line 6 def decimal @decimal end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/dbf/dbf/column.rb', line 6 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/dbf/dbf/column.rb', line 6 def name @name end |
#type ⇒ Object (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_definition ⇒ Object
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 |