Class: Twb::Analysis::DataSources::DataSourceFieldsCSVEmitter

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

Constant Summary collapse

@@csvHeader =
['Record #',
 'Workbook',           
 'Workbook Dir',
 'Data Source',
 'Field',
 'Twb Type',
 'Hidden',            # props[:hidden],

 'Type - Column',     # props[:columnField],

 'Type - Calculated', # props[:calculatedField],

 'Type - Db',         # props[:dbField],

 'Type - Mapped',     # props[:mappedField] 

 'Type - MetaData',     # props[:mappedField]  

]
@@csvFileType =
'TwbDataSourceFields'
@@csvFileName =
@@csvFileType + '.csv'
@@tallHeader =
['Field #',
 'Workbook',           
 'Workbook Dir',
 'Data Source',
 'Field',
 'Field Type',
 'Property - Name',
 'Property - Value'
]
@@fullFileType =
'TwbDataSourceFieldsDetails'
@@fullFileName =
@@fullFileType + '.csv'
@@fullHeader =
['Field #',
 'Workbook',           
 'Workbook Dir',
 'Data Source',
 'Field',
 'Field - source',
 'Field - class',
 'Field - path',
 'Property - Name',
 'Property - Value'
]
@@tallFileType =
'TwbDataSourceFieldsTech'
@@tallFileName =
@@tallFileType + '.csv'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDataSourceFieldsCSVEmitter

Returns a new instance of DataSourceFieldsCSVEmitter.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 71

def initialize
  @csvFile     = CSV.open(@@csvFileName,'w')
  @csvFile     << @@csvHeader
  @csvRecords  = Set.new
  puts "Opened: #{[email protected]?} - #{@@csvFileName}"
  # --

  @csvFileFull = CSV.open(@@fullFileName,'w')
  @csvFileFull << @@fullHeader
  puts "Opened: #{[email protected]?} - #{@@fullFileName} "
  # --

  @csvFileTech = CSV.open(@@tallFileName,'w')
  @csvFileTech << @@tallHeader
  puts "Opened: #{[email protected]?} - #{@@tallFileName}"
  # --

  @recNum      = 0
  @dsCount     = 0
  @fieldsCount = 0
end

Instance Attribute Details

#csvFileNameObject (readonly)

Returns the value of attribute csvFileName.



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

def csvFileName
  @csvFileName
end

#csvRecordsObject (readonly)

Returns the value of attribute csvRecords.



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

def csvRecords
  @csvRecords
end

#dsCountObject (readonly)

Returns the value of attribute dsCount.



26
27
28
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 26

def dsCount
  @dsCount
end

#fieldsCountObject (readonly)

Returns the value of attribute fieldsCount.



26
27
28
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 26

def fieldsCount
  @fieldsCount
end

Class Method Details

.csvFileNaameObject



98
99
100
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 98

def self.csvFileNaame
  @@csvFileName
end

.csvFileTypeObject



94
95
96
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 94

def self.csvFileType
  @@csvFileType
end

.csvHeaderObject



90
91
92
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 90

def self.csvHeader
  @@csvHeader
end

Instance Method Details

#cleanupObject



241
242
243
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 241

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

#emitFields(fields) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 188

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



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 225

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)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 102

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
    fclasses = Set.new
    ds.localFields.each do |field|
      recordFieldFull field, :local
      # recordField( fields, field, {:type=>:local,:columnField=>true,:hidden=>field.hidden} )

      # emitTech( ds,     field.uiname, 'Local', field.properties)

      # recordTech( field, 'LocalA')

    end
    ds.columnFields.each do |field|
      recordFieldFull field, :column
      # recordField( fields, field, {:type=>'column',:columnField=>true,:hidden=>field.hidden} )

      # emitTech( ds,     field.uiname, 'Column', field.properties)

      # recordTech( field, 'ColumnA')

    end
    ds.calculatedFields.each do |field|
      recordFieldFull field, :calc
      # puts "WWW #{field.class}  :: #{field} ::prop:: #{field.properties.class} :: #{field.properties}"

      # recordField( fields, field, {:type=>'calc',:calculatedField=>true,:hidden=>field.hidden} )

      # emitTech( ds,     field.uiname, 'Calculated', field.properties)

      # recordTech( field, 'CalcA')

    end
    ds.metadataFields.each do |field|
      recordFieldFull field, :metadata
      # recordField( fields, field,   {:type=>'metadata',:metadataField=>true} )

      # emitTech( ds,     field.uiname, 'MetaData', field.properties)

      # recordTech( field, 'MetadataA')

    end
    ds.dbFields.each do |field|
      recordFieldFull field, :db
      # recordField( fields, field,    {:type=>'database',:dbField=>true} )

      # emitTech( ds,     field.uiname, 'Db', field.properties)

      # recordTech( field, 'DbA')

    end
    ds.mappedFields.each do |field|
      recordFieldFull field, :mapped
      # recordField( fields, field,    {:type=>'mapped',:mappedField=>true} )

      # emitTech( ds,     field.uiname, 'Mapped', field.properties)

      # recordTech( field, 'MappedA')

    end
    emitFields(fields)
  end
end

#recordField(fields, field, props) ⇒ Object



178
179
180
181
182
183
184
185
186
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 178

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

#recordFieldFull(field, source) ⇒ Object

def processTwb twb



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 157

def recordFieldFull field, source
  # print field.properties.nil? ? '-' : ":#{field.properties.length}"

  # puts field.properties

  @recNum+=1
  field.properties.each do |name,value|
    # print name 

    @csvFileFull << [  @recNum,
                       @twb.name,
                       @twb.dir,
                       @dsname,
                       field.uiname,
                       source,
                       field.class,
                       field.node.path.to_s.gsub(/[0-9]/,'').gsub('[]',''),
                       name,
                       value
                     ]
    # @csvFileFull << csvRec

  end
end

#recordTech(field, type) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/twb/analysis/DataSources/DataSourceFieldsCSVEmitter.rb', line 210

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