Class: ADT::Column

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/adt/column.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(name, type, length) ⇒ Column

Initialize a new ADT::Column

Parameters:

  • name (String)
  • type (String)
  • length (Integer)


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

#lengthObject (readonly)

Returns the value of attribute length.



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

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#downcaseObject



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

Parameters:

  • length (Integer) (defaults to: 0)


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_hashHash

Returns a Hash with :name, :type, :length, and :decimal keys

Returns:

  • (Hash)


55
56
57
# File 'lib/adt/column.rb', line 55

def to_hash
  {name: name, type: type, length: length}
end

#underscored_nameString

Underscored name

This is the column name converted to underscore format. For example, MyColumn will be returned as my_column.

Returns:

  • (String)


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