Method: Twb::CodedField#initialize

Defined in:
lib/twb/codedfield.rb

#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