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.



44
45
46
# File 'lib/rbase/columns.rb', line 44

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



42
43
44
# File 'lib/rbase/columns.rb', line 42

def decimal
  @decimal
end

#nameObject (readonly)

Column name



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

def name
  @name
end

#offsetObject (readonly)

Column offset from the beginning of the record



36
37
38
# File 'lib/rbase/columns.rb', line 36

def offset
  @offset
end

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

.typeObject

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

#inspectObject



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

#typeObject

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