Class: DBF::Column
Defined Under Namespace
Classes: LengthError, NameError
Constant Summary collapse
- TYPE_CAST_CLASS =
rubocop:disable Style/MutableConstant
{ N: ColumnType::Number, I: ColumnType::SignedLong, F: ColumnType::Float, Y: ColumnType::Currency, D: ColumnType::Date, T: ColumnType::DateTime, L: ColumnType::Boolean, M: ColumnType::Memo, B: ColumnType::Double, G: ColumnType::General, :+ => ColumnType::SignedLong2 }
Instance Attribute Summary collapse
-
#decimal ⇒ Object
readonly
Returns the value of attribute decimal.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(table, name, type, length, decimal) ⇒ Column
constructor
Initialize a new DBF::Column.
-
#memo? ⇒ Boolean
Returns true if the column is a memo.
-
#to_hash ⇒ Hash
Returns a Hash with :name, :type, :length, and :decimal keys.
-
#underscored_name ⇒ String
Underscored name.
Constructor Details
#initialize(table, name, type, length, decimal) ⇒ Column
Initialize a new DBF::Column
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dbf/column.rb', line 40 def initialize(table, name, type, length, decimal) @encoding = table.encoding @table = table @name = clean(name) @type = type @length = length @decimal = decimal @version = table.version validate_length validate_name end |
Instance Attribute Details
#decimal ⇒ Object (readonly)
Returns the value of attribute decimal.
11 12 13 |
# File 'lib/dbf/column.rb', line 11 def decimal @decimal end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
11 12 13 |
# File 'lib/dbf/column.rb', line 11 def encoding @encoding end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
11 12 13 |
# File 'lib/dbf/column.rb', line 11 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/dbf/column.rb', line 11 def name @name end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
11 12 13 |
# File 'lib/dbf/column.rb', line 11 def table @table end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/dbf/column.rb', line 11 def type @type end |
Instance Method Details
#memo? ⇒ Boolean
Returns true if the column is a memo
57 58 59 |
# File 'lib/dbf/column.rb', line 57 def memo? @memo ||= type == 'M' end |
#to_hash ⇒ Hash
Returns a Hash with :name, :type, :length, and :decimal keys
64 65 66 |
# File 'lib/dbf/column.rb', line 64 def to_hash {name: name, type: type, length: length, decimal: decimal} end |
#underscored_name ⇒ String
Underscored name
This is the column name converted to underscore format. For example, MyColumn will be returned as my_column.
74 75 76 |
# File 'lib/dbf/column.rb', line 74 def underscored_name @underscored_name ||= name.gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase end |