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.
42 43 44 |
# File 'lib/rbase/columns.rb', line 42 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
40 41 42 |
# File 'lib/rbase/columns.rb', line 40 def decimal @decimal end |
#name ⇒ Object (readonly)
Column name
31 32 33 |
# File 'lib/rbase/columns.rb', line 31 def name @name end |
#offset ⇒ Object (readonly)
Column offset from the beginning of the record
34 35 36 |
# File 'lib/rbase/columns.rb', line 34 def offset @offset end |
#size ⇒ Object (readonly)
Column size in characters
37 38 39 |
# File 'lib/rbase/columns.rb', line 37 def size @size end |
Class Method Details
.column_for(type) ⇒ Object
Returns column type class that correspond to given column type string
15 16 17 18 |
# File 'lib/rbase/columns.rb', line 15 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
9 10 11 12 |
# File 'lib/rbase/columns.rb', line 9 def self.column_type(type) @type = type @@types[type] = self end |
.type ⇒ Object
Returns column type as 1 character string
21 22 23 |
# File 'lib/rbase/columns.rb', line 21 def self.type @type end |
Instance Method Details
#attach_to(table) ⇒ Object
47 48 49 |
# File 'lib/rbase/columns.rb', line 47 def attach_to(table) @table = table end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/rbase/columns.rb', line 61 def inspect "#{name}(type=#{type}, size=#{size})" end |
#pack(value) ⇒ Object
Packs column value for storing it in XBase file.
52 53 54 |
# File 'lib/rbase/columns.rb', line 52 def pack(value) throw "Not implemented" end |
#type ⇒ Object
Returns column type as 1 character string
26 27 28 |
# File 'lib/rbase/columns.rb', line 26 def type self.class.type end |
#unpack(value) ⇒ Object
Unpacks stored in XBase column data into appropriate Ruby form.
57 58 59 |
# File 'lib/rbase/columns.rb', line 57 def unpack(value) throw "Not implemented" end |