Class: ADT::Column
Defined Under Namespace
Classes: LengthError, NameError
Constant Summary collapse
- TYPE_CAST_CLASS =
in use for SAGE BOB50
- 1, 3, 4, 6, 10, 11, 12, 14, 15, 17
{ 1 => ADT::ColumnType::Boolean, 3 => ADT::ColumnType::Date, 4 => ADT::ColumnType::String, 6 => ADT::ColumnType::Binary, 10 => ADT::ColumnType::Double, 11 => ADT::ColumnType::Integer, 12 => ADT::ColumnType::ShortInteger, 14 => ADT::ColumnType::DateTime, 15 => ADT::ColumnType::Integer, # In reality an "autoinc" but we don't deal with that 17 => ADT::ColumnType::CurDouble }
Instance Attribute Summary collapse
-
#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
- #downcase ⇒ Object
-
#flag(length = 0) ⇒ Object
Return the flag to decode the data.
-
#initialize(name, type, length) ⇒ Column
constructor
Initialize a new ADT::Column.
-
#to_hash ⇒ Hash
Returns a Hash with :name, :type, :length, and :decimal keys.
-
#underscored_name ⇒ String
Underscored name.
Constructor Details
#initialize(name, type, length) ⇒ Column
Initialize a new ADT::Column
33 34 35 36 37 38 39 40 |
# File 'lib/adt/column.rb', line 33 def initialize(name, type, length) @name = clean(name) @type = type @length = length validate_length validate_name end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
8 9 10 |
# File 'lib/adt/column.rb', line 8 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/adt/column.rb', line 8 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/adt/column.rb', line 8 def type @type end |
Instance Method Details
#downcase ⇒ Object
59 60 61 |
# File 'lib/adt/column.rb', line 59 def downcase name.downcase end |
#flag(length = 0) ⇒ Object
Return the flag to decode the data
45 46 47 48 49 50 |
# File 'lib/adt/column.rb', line 45 def flag(length = 0) flag = type_cast_class.flag return flag + length.to_s if flag.eql? 'A' flag end |
#to_hash ⇒ Hash
Returns a Hash with :name, :type, :length, and :decimal keys
55 56 57 |
# File 'lib/adt/column.rb', line 55 def to_hash {name: name, type: type, length: length} end |
#underscored_name ⇒ String
Underscored name
This is the column name converted to underscore format. For example, MyColumn will be returned as my_column.
69 70 71 72 73 74 75 76 77 |
# File 'lib/adt/column.rb', line 69 def underscored_name @underscored_name ||= begin name.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end end |