Class: RBase::Columns::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/rbase/columns.rb

Overview

Base class for all column types

Constant Summary collapse

@@types =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  options.merge({:name => name, :type => self.class.type}).each { |k, v| self.instance_variable_set("@#{k}", v) }
end

Instance Attribute Details

#decimalObject (readonly)

Number of decimal places



40
41
42
# File 'lib/rbase/columns.rb', line 40

def decimal
  @decimal
end

#nameObject (readonly)

Column name



31
32
33
# File 'lib/rbase/columns.rb', line 31

def name
  @name
end

#offsetObject (readonly)

Column offset from the beginning of the record



34
35
36
# File 'lib/rbase/columns.rb', line 34

def offset
  @offset
end

#sizeObject (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

.typeObject

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

#inspectObject



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

#typeObject

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