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
# File 'lib/twb/analysis/AnnotatedFieldsCSVEmitter.rb', line 39

def initialize
  @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



57
58
59
# File 'lib/twb/analysis/AnnotatedFieldsCSVEmitter.rb', line 57

def self.csvFileNaame
  @@csvFileName
end

.csvFileTypeObject



53
54
55
# File 'lib/twb/analysis/AnnotatedFieldsCSVEmitter.rb', line 53

def self.csvFileType
  @@csvFileType
end

.csvHeaderObject



49
50
51
# File 'lib/twb/analysis/AnnotatedFieldsCSVEmitter.rb', line 49

def self.csvHeader
  @@csvHeader
end

Instance Method Details

#cleanupObject



175
176
177
# File 'lib/twb/analysis/AnnotatedFieldsCSVEmitter.rb', line 175

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



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/twb/analysis/AnnotatedFieldsCSVEmitter.rb', line 122

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



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/twb/analysis/AnnotatedFieldsCSVEmitter.rb', line 159

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)


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

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
  # --

  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



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/AnnotatedFieldsCSVEmitter.rb', line 80

def recordField field
  @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



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/twb/analysis/AnnotatedFieldsCSVEmitter.rb', line 144

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