class Twb::Util::CSVRecordsAtomizer
Attributes
metrics[R]
ttdocdir[RW]
Public Class Methods
new(**args)
click to toggle source
# File lib/twb/util/csvrecordsatomizer.rb, line 32 def initialize(**args) @args = args @ttdocdir = @args[:ttdocdir] @csvAdd = @args[:csvMode] == :add @csvMode = @csvAdd ? 'a' : 'w' init @funcdoc = {:class=>self.class, :blurb=>'Analyze Calculated Fields', :description=>'Calculated fields can be complex, this tool provides robust coverage.'} # -- @executed = false end
Public Instance Methods
processFile(fileName)
click to toggle source
# File lib/twb/util/csvrecordsatomizer.rb, line 43 def processFile fileName emit true, "#{self.class} - processFile: #{fileName} :: #{fileName.class}" # -- srcFields = Set.new CSV.open(fileName, 'r:bom|utf-8', &:readline) emit true, "\t Inspecting these #{srcFields.length} #{srcFields.class} fields: " keyFields = loadFields(fileName, :keyfields) excludeFields = loadFields(fileName, :excludefields) recordFields = (srcFields - keyFields - excludeFields).to_a emit true, "\t Using these key fields: #{keyFields.inspect}" emit true, "\t Excluding these fields: #{excludeFields.inspect}" emit true, "\t Recording these fields: #{recordFields.inspect}" # -- atomizedFields = keyFields.to_a + @@atomFields dataBaseName = File.basename(fileName, ".*") atomizedCSVFile = "#{dataBaseName}.Atomized.csv" atomizedCSVFile = CSV.open(atomizedCSVFile,'w') atomizedCSVFile << keyFields.to_a + @@atomFields # -- @recNum = 0 CSV.open(fileName, 'r:bom|utf-8', headers: true) do |csv| csv.each do |row| @recNum += 1 atomRec = [] keyFields.each do |kf| atomRec << row.fetch(kf) end atomRec << @recNum recordFields.each do |rf| atomizedCSVFile << atomRec + [rf, row.fetch(rf)] end end end end
Private Instance Methods
loadFields(fileName, type)
click to toggle source
# File lib/twb/util/csvrecordsatomizer.rb, line 79 def loadFields fileName, type puts "\n\n\t loadFields -#{fileName}- -#{type}-" fields = Set.new auxFile = "#{fileName}.#{type}" isAuxFile = File.exist?(auxFile) emit true, "\t\t Loading auxilary data: %-12s %7s %-s" % [type, isAuxFile, auxFile] if isAuxFile # file = File.open(fileName) File.open(auxFile).each_line { |line| fields.add line.chomp } end return fields.to_a end
loadMetrics()
click to toggle source
# File lib/twb/util/csvrecordsatomizer.rb, line 101 def loadMetrics @metrics = { '# of Data Sources' => @dataSourcesCount, '# of Calculated Fields' => @calculatedFieldsCount, '# of Referenced Fields' => @referencedFieldsCount, } end
processData(fileName)
click to toggle source
# File lib/twb/util/csvrecordsatomizer.rb, line 94 def processData fileName end