Class: Twb::Analysis::DataSources::require_relative

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb

Constant Summary collapse

@@csvFileName =
'DataSourceTableFields.csv'
@@csvHeader =
['Record #',
 'Workbook',           
 'Workbook Dir',
 'Data Source',
 'Data Source (tech)',
 'Table',
 'Field',
 'Field (code)',
 'Field (table)',
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializerequire_relative

Returns a new instance of require_relative.



42
43
44
45
46
47
48
49
50
51
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 42

def initialize
  @csvFile = CSV.open(@@csvFileName, 'w')
  @csvFile << @@csvHeader
  @outputs = Set.new
  @outputs << @@csvFileName
  @dsCount      = 0
  @tablesCount  = 0
  @fieldsCount  = 0
  @csvRecords   = Set.new
end

Instance Attribute Details

#csvFileNameObject (readonly)

Returns the value of attribute csvFileName.



24
25
26
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 24

def csvFileName
  @csvFileName
end

#csvRecordsObject (readonly)

Returns the value of attribute csvRecords.



24
25
26
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 24

def csvRecords
  @csvRecords
end

#dsCountObject (readonly)

Returns the value of attribute dsCount.



25
26
27
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 25

def dsCount
  @dsCount
end

#fieldsCountObject (readonly)

Returns the value of attribute fieldsCount.



25
26
27
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 25

def fieldsCount
  @fieldsCount
end

#tablesCountObject (readonly)

Returns the value of attribute tablesCount.



25
26
27
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 25

def tablesCount
  @tablesCount
end

Class Method Details

.csvFileTypeObject



69
70
71
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 69

def self.csvFileType
  @@csvFileName
end

.csvHeaderObject



65
66
67
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 65

def self.csvHeader
  @@csvHeader
end

Instance Method Details

#docObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 53

def doc
  {
    :filedoc => [
                 { :file        => @@csvFileName,
                   :description => @csvFileDescription,
                   :header      => @@csvHeader 
                 }
                ],
    :outputs => @outputs
  }
end

#outputsObject



73
74
75
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 73

def outputs
  @outputs
end

#processTwb(twb) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/twb/analysis/datasources/datasourcetablefieldsanalyzer.rb', line 77

def processTwb twb
  @recNum = 0
  @twb    = twb if twb.instance_of? Twb::Workbook
  @twb    = Twb::Workbook.new(twb) if twb.instance_of? String
  # --
  dss = @twb.datasources
  dss.each do |ds|
    tables = Set.new
    @dsCount += 1
    ds.node.xpath('./connection/cols/map').each do |cnode|
      # puts cnode
      key         = cnode.attribute('key').text
      codename    = key.gsub(/^\[|\]$/,'')
      fielduiname = ds.fieldUIName(codename)
      value       = cnode.attribute('value').text.gsub(/^\[|\]$/,'')
      parts       = value.split('].[')
      # puts "%-30s  %-45s  %s \n " % [fielduiname, value, parts]
      csvRecord = [ @fieldsCount += 1,
                    @twb.name,
                    @twb.dir,
                    ds.uiname,
                    ds.name,
                    parts[0],
                    fielduiname,
                    codename,
                    parts[1] 
                  ]
      tables.add parts[0]
      @csvRecords.add csvRecord
      @csvFile << csvRecord
    end
    @tablesCount += tables.length
  end
end