Class: Twb::DbField

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/twb/dbfield.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataSource, node, nodeType, table = nil) ⇒ DbField

Returns a new instance of DbField.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/twb/dbfield.rb', line 29

def initialize dataSource, node, nodeType, table=nil
  @node     = node
  @nodeType = nodeType
  case @nodeType
    when :map
      @uiname  = @node.attribute('key').text.gsub(/^\[|\]$/,'')
      @name    = @uiname
      fldRef   = @node.attribute('value').text.gsub(/^\[|\]$/,'')
      parts    = fldRef.split('].[')
      @dbtable = parts[0]
      @dbname  = parts[1]
    when :tableColumn
      @uiname  = @node.attribute('name').text
      @name    = @uiname
      @dbtable = table
    else
      raise ArgumentError.new("ERROR in DbField creation: invalid Node type, is #{nodeType} \n ")
  end      
  @id      = "#{dataSource}::#{dbname}::#{dbtable}::#{uiname}"
end

Instance Attribute Details

#dbnameObject (readonly)

Returns the value of attribute dbname.



27
28
29
# File 'lib/twb/dbfield.rb', line 27

def dbname
  @dbname
end

#dbtableObject (readonly)

Returns the value of attribute dbtable.



27
28
29
# File 'lib/twb/dbfield.rb', line 27

def dbtable
  @dbtable
end

#nameObject (readonly)

Returns the value of attribute name.



26
27
28
# File 'lib/twb/dbfield.rb', line 26

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



24
25
26
# File 'lib/twb/dbfield.rb', line 24

def node
  @node
end

#propertiesObject (readonly)

Returns the value of attribute properties.



25
26
27
# File 'lib/twb/dbfield.rb', line 25

def properties
  @properties
end

#uinameObject (readonly)

Returns the value of attribute uiname.



26
27
28
# File 'lib/twb/dbfield.rb', line 26

def uiname
  @uiname
end

Instance Method Details

#<=>(other) ⇒ Object



68
69
70
# File 'lib/twb/dbfield.rb', line 68

def <=>(other)
  @id <=> other.id
end

#idObject



50
51
52
# File 'lib/twb/dbfield.rb', line 50

def id
    @id ||= @id = @name.hash
end

#loadPropertiesObject



58
59
60
61
62
# File 'lib/twb/dbfield.rb', line 58

def loadProperties
  @properties = {:name=>@name,:uiname=>@uiname, :dbtable=>@dbtable}
  @properties[:dbname] = @dbname if :map == @nodeType
  return @properties
end

#to_sObject



64
65
66
# File 'lib/twb/dbfield.rb', line 64

def to_s
  @id
end