Class: RBase::Columns::Column
- Inherits:
-
Object
- Object
- RBase::Columns::Column
- Defined in:
- lib/rbase/columns.rb
Overview
Base class for all column types
Direct Known Subclasses
CharacterColumn, DateColumn, FloatColumn, LogicalColumn, MemoColumn, NumberColumn
Constant Summary collapse
- @@types =
{}
Instance Attribute Summary collapse
-
#decimal ⇒ Object
readonly
Number of decimal places.
-
#name ⇒ Object
readonly
Column name.
-
#offset ⇒ Object
readonly
Column offset from the beginning of the record.
-
#size ⇒ Object
readonly
Column size in characters.
Class Method Summary collapse
-
.column_for(type) ⇒ Object
Returns column type class that correspond to given column type string.
-
.column_type(type) ⇒ Object
Assigns column type string to current class.
-
.type ⇒ Object
Returns column type as 1 character string.
Instance Method Summary collapse
- #attach_to(table) ⇒ Object
-
#initialize(name, options = {}) ⇒ Column
constructor
A new instance of Column.
- #inspect ⇒ Object
-
#pack(value) ⇒ Object
Packs column value for storing it in XBase file.
-
#type ⇒ Object
Returns column type as 1 character string.
-
#unpack(value) ⇒ Object
Unpacks stored in XBase column data into appropriate Ruby form.
Constructor Details
#initialize(name, options = {}) ⇒ Column
Returns a new instance of Column.
44 45 46 |
# File 'lib/rbase/columns.rb', line 44 def initialize(name, = {}) .merge({:name => name, :type => self.class.type}).each { |k, v| self.instance_variable_set("@#{k}", v) } end |
Instance Attribute Details
#decimal ⇒ Object (readonly)
Number of decimal places
42 43 44 |
# File 'lib/rbase/columns.rb', line 42 def decimal @decimal end |
#name ⇒ Object (readonly)
Column name
33 34 35 |
# File 'lib/rbase/columns.rb', line 33 def name @name end |
#offset ⇒ Object (readonly)
Column offset from the beginning of the record
36 37 38 |
# File 'lib/rbase/columns.rb', line 36 def offset @offset end |
#size ⇒ Object (readonly)
Column size in characters
39 40 41 |
# File 'lib/rbase/columns.rb', line 39 def size @size end |
Class Method Details
.column_for(type) ⇒ Object
Returns column type class that correspond to given column type string
17 18 19 20 |
# File 'lib/rbase/columns.rb', line 17 def self.column_for(type) throw "Unknown column type '#{type}'" unless @@types.has_key?(type) @@types[type] end |
.column_type(type) ⇒ Object
Assigns column type string to current class
11 12 13 14 |
# File 'lib/rbase/columns.rb', line 11 def self.column_type(type) @type = type @@types[type] = self end |
.type ⇒ Object
Returns column type as 1 character string
23 24 25 |
# File 'lib/rbase/columns.rb', line 23 def self.type @type end |
Instance Method Details
#attach_to(table) ⇒ Object
49 50 51 |
# File 'lib/rbase/columns.rb', line 49 def attach_to(table) @table = table end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/rbase/columns.rb', line 63 def inspect "#{name}(type=#{type}, size=#{size})" end |
#pack(value) ⇒ Object
Packs column value for storing it in XBase file.
54 55 56 |
# File 'lib/rbase/columns.rb', line 54 def pack(value) throw "Not implemented" end |
#type ⇒ Object
Returns column type as 1 character string
28 29 30 |
# File 'lib/rbase/columns.rb', line 28 def type self.class.type end |
#unpack(value) ⇒ Object
Unpacks stored in XBase column data into appropriate Ruby form.
59 60 61 |
# File 'lib/rbase/columns.rb', line 59 def unpack(value) throw "Not implemented" end |