Class: DBF::Column
- Inherits:
-
Object
- Object
- DBF::Column
- Defined in:
- lib/dbf/column.rb
Defined Under Namespace
Classes: InvalidNameError, LengthError
Constant Summary collapse
- NameError =
Deprecated alias, kept for backward compatibility. It shadowed ::NameError (without being one), so it was renamed.
InvalidNameError- 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::AutoIncrement }
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
-
#decode(raw) {|raw| ... } ⇒ Object
Decodes a raw column value, handling memo, blank, and type cast cases.
- #encoding ⇒ Object
-
#initialize(table, name, type, length, decimal) ⇒ Column
constructor
Initialize a new DBF::Column.
-
#to_hash ⇒ Hash
Returns a Hash with :name, :type, :length, and :decimal keys.
- #type_cast(value) ⇒ Object
-
#underscored_name ⇒ String
Underscored name.
Constructor Details
#initialize(table, name, type, length, decimal) ⇒ Column
Initialize a new DBF::Column
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dbf/column.rb', line 43 def initialize(table, name, type, length, decimal) @table = table @name = clean(name) @type = clean_type(type) @length = length @decimal = decimal validate_length validate_name end |
Instance Attribute Details
#decimal ⇒ Object (readonly)
Returns the value of attribute decimal.
16 17 18 |
# File 'lib/dbf/column.rb', line 16 def decimal @decimal end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
16 17 18 |
# File 'lib/dbf/column.rb', line 16 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/dbf/column.rb', line 16 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/dbf/column.rb', line 16 def type @type end |
Instance Method Details
#decode(raw) {|raw| ... } ⇒ Object
Decodes a raw column value, handling memo, blank, and type cast cases
66 67 68 |
# File 'lib/dbf/column.rb', line 66 def decode(raw, &) type_cast_class.decode(raw, &) end |
#encoding ⇒ Object
54 |
# File 'lib/dbf/column.rb', line 54 def encoding = @table.encoding |
#to_hash ⇒ Hash
Returns a Hash with :name, :type, :length, and :decimal keys
73 74 75 |
# File 'lib/dbf/column.rb', line 73 def to_hash {name:, type:, length:, decimal:} end |
#type_cast(value) ⇒ Object
57 58 59 |
# File 'lib/dbf/column.rb', line 57 def type_cast(value) type_cast_class.type_cast(value) end |
#underscored_name ⇒ String
Underscored name
This is the column name converted to underscore format. For example, MyColumn will be returned as my_column.
83 84 85 |
# File 'lib/dbf/column.rb', line 83 def underscored_name @underscored_name ||= name.gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase end |