Class: Twb::CodedField

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ CodedField

Returns a new instance of CodedField.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/twb/codedfield.rb', line 29

def initialize code
  # puts "...CodedField :: #{code}"
  @rawCode = code
  trimmed  = code.gsub(/^['"]|['"]$/,'').gsub(/^\[|\]$/,'').gsub(/:[0-9]+$/,'')
  # puts "      trimmed :: #{trimmed}"
  parts    = trimmed.split('].[')
 #puts "Field: #{code}  parts: #{parts.length} - #{parts.inspect}"
 #puts "   p1: #{parts[0]}"
 #puts "   p2: #{parts[1]}"
  if parts.length == 1
   #puts '==1'
    @name = parts[0]
    @techCode = "[#{@name}]"
  elsif # parts.length <> 1
   #puts '<>1'
   #puts "p[0]: #{parts[0]}"
   #puts "p[1]: #{parts[1]}"
    @dataSource  = parts[0]
    fldName = parts[1]
    if fldName.start_with?(':') && fldName.count(':') == 1
      @name = fldName
    else
      parseField fldName
    end
    @techCode   = "[#{@dataSource}].[#{@name}]"
  end
end

Instance Attribute Details

#dataSourceObject (readonly)

Returns the value of attribute dataSource.



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

def dataSource
  @dataSource
end

#functionObject (readonly)

Returns the value of attribute function.



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

def function
  @function
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#rawCodeObject (readonly)

Returns the value of attribute rawCode.



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

def rawCode
  @rawCode
end

#techCodeObject (readonly)

Returns the value of attribute techCode.



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

def techCode
  @techCode
end

Instance Method Details

#<=>(other) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/twb/codedfield.rb', line 77

def <=>(other)
  # myName    = @uiname.nil? ? '' : @uiname
  # otherName = other.uiName.nil? ? "" : other.uiName
  # ##puts "#{@uiname} / #{myName} <=>  #{otherName} / #{other.uiName}"
  # ##puts "#{@uiname.nil?} // #{other.uiName.nil?}"
  # myName <=> otherName
  @fqName <=> other.techCode
end

#idObject



69
70
71
# File 'lib/twb/codedfield.rb', line 69

def id
  @id ||= @id = "#{@dataSource}::#{@uiname}"
end

#parseField(str) ⇒ Object

initialize



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/twb/codedfield.rb', line 57

def parseField str
  # puts "parseField: #{str}"
  parts = str.split(':')
  case parts.length
  when 1
    @name     = parts[0]
  else
    @name     = parts[-2]
    @function = parts[0]
  end
end

#to_sObject



73
74
75
# File 'lib/twb/codedfield.rb', line 73

def to_s
  "ds:#{dataSource}|n:#{name}|tc:#{techCode}"
end