class DBF::Column

Constants

TYPE_CAST_CLASS

rubocop:disable Style/MutableConstant

Attributes

decimal[R]
encoding[R]
length[R]
name[R]
table[R]
type[R]

Public Class Methods

new(table, name, type, length, decimal) click to toggle source

Initialize a new DBF::Column

@param table [String] @param name [String] @param type [String] @param length [Integer] @param decimal [Integer]

# 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

Public Instance Methods

memo?() click to toggle source

Returns true if the column is a memo

@return [Boolean]

# File lib/dbf/column.rb, line 57
def memo?
  @memo ||= type == 'M'
end
to_hash() click to toggle source

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

@return [Hash]

# File lib/dbf/column.rb, line 64
def to_hash
  {name: name, type: type, length: length, decimal: decimal}
end
underscored_name() click to toggle source

Underscored name

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

@return [String]

# File lib/dbf/column.rb, line 74
def underscored_name
  @underscored_name ||= name.gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
end