Class: Twb::Analysis::AnnotatedFieldsCSVEmitter

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

Constant Summary collapse

@@csvHeader =
['Record #',
 'Workbook',           
 'Workbook Dir',
 'Data Source',
 'Field',
 'Doc Type',
 'Doc Line #',
 'Doc Line'
]
@@csvFileType =
'TwbAnnotatedFields'
@@csvFileName =
@@csvFileType + '.csv'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAnnotatedFieldsCSVEmitter

Returns a new instance of AnnotatedFieldsCSVEmitter.



39
40
41
42
43
44
45
46
47
48
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 39

def initialize
  # puts "AnnotatedFieldsCSVEmitter - initializing"
  @csvFile     = CSV.open(@@csvFileName,'w')
  @csvFile     << @@csvHeader
  @csvRecords  = Set.new
  # --
  @recNum    = 0
  @dsCount   = 0
  @fieldNum  = 0
end

Instance Attribute Details

#csvFileNameObject (readonly)

Returns the value of attribute csvFileName.



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

def csvFileName
  @csvFileName
end

#csvRecordsObject (readonly)

Returns the value of attribute csvRecords.



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

def csvRecords
  @csvRecords
end

#dsCountObject (readonly)

Returns the value of attribute dsCount.



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

def dsCount
  @dsCount
end

#fieldsCountObject (readonly)

Returns the value of attribute fieldsCount.



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

def fieldsCount
  @fieldsCount
end

Class Method Details

.csvFileNaameObject



58
59
60
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 58

def self.csvFileNaame
  @@csvFileName
end

.csvFileTypeObject



54
55
56
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 54

def self.csvFileType
  @@csvFileType
end

.csvHeaderObject



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

def self.csvHeader
  @@csvHeader
end

Instance Method Details

#cleanupObject



178
179
180
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 178

def cleanup
  @csvFile.close unless @csvFile.nil?
end

#emitFields(fields) ⇒ Object

def recordField fields, field, props

# puts "%-65s  :: %s " % [fieldName,props]
return if field.uiname.nil?
if fields.has_key? field.uiname
  fields[field.uiname].merge! field.properties
else
  fields[field.uiname] = field.properties
end

end



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 125

def emitFields fields
  fields.each do |fieldName,props|
    # puts "FIELD::  %-40s  :: %s" % [fieldName,props.inspect]
    # class = props[]
    csvRec = [ @recNum+=1,
               @twb.name,
               @twb.dir,
               @dsname,
               fieldName,
               props[:type],
               props['hidden'],
               props[:columnField],
               props[:calculatedField],
               props[:dbField],
               props[:mappedField],
               props[:metadataField]
             ]
    @csvFile << csvRec
    @csvRecords.add csvRec
  end
end

#emitTech(dataSource, fieldName, type, properties) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 162

def emitTech dataSource, fieldName, type, properties
  # puts "XX #{dataSource.uiname} :: #{fieldName} #{}  :: #{type} :: #{properties}"
  @recNum+=1
  properties.each do |name,value|
    @csvFileTech << [ @recNum,
                      @twb.name,
                      @twb.dir,
                      dataSource.uiname,
                      fieldName,
                      type,
                      name,
                      value
                    ]
  end
end

#processTwb(twb) ⇒ Object

Raises:

  • (ArgumentError)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 62

def processTwb twb
  @twb = nil
  @twb         = twb                    if twb.instance_of? Twb::Workbook
  @twb         = Twb::Workbook.new(twb) if twb.instance_of? String
  raise ArgumentError.new("ERROR in Workbok processing: '#{twb}' must be a Workbook (class) or the name of a Workbook (String), is a #{twb.class} \n ") unless @twb.is_a? Twb::Workbook
  # puts "Processing #{@twb.name}"
  # --
  dss = @twb.datasources
  dss.each do |ds|
    @dsname = ds.uiname
    # puts "\n    -- #{ds.uiname} "
    # tables = Set.new
    fields = {}
    @dsCount += 1
    ds.columnFields.each do |field|
      recordField field
    end
  end
end

#recordField(field) ⇒ Object

def processTwb twb



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
111
112
113
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 82

def recordField field
  # puts "- #{field.uiname} :: #{field} ::: #{field.node}"
  @fieldNum += 1
  @lineNum   = 0
  field.comment.each do |line|
    # dispLine = if ''.eql?(line) the ? '' : line
    @csvFile << [ @recNum+=1,
                  @twb.name,
                  @twb.dir,
                  @dsname,
                  field.uiname,
                  'Comment',
                  @lineNum+=1,
                  # ''.eql?(line) ? " " : line
                  line
                ]
  end
  unless field.calcField.nil?
    @lineNum   = 0
    field.calcField.formulaResolvedLines.each do |line|
      @csvFile << [ @recNum+=1,
                    @twb.name,
                    @twb.dir,
                    @dsname,
                    field.uiname,
                    'Formula',
                    @lineNum+=1,
                    line
                  ]
    end
  end
end

#recordTech(field, type) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/twb/analysis/annotatedfieldscsvemitter.rb', line 147

def recordTech field, type
  @recNum+=1
  field.properties.each do |name,value|
    @csvFileTech << [ @recNum,
                      @twb.name,
                      @twb.dir,
                      @dsname,
                      field.uiname,
                      type,
                      name,
                      value
                    ]
  end
end