Class: Twb::Util::CSVRecordsAtomizer
- Inherits:
-
Object
- Object
- Twb::Util::CSVRecordsAtomizer
- Includes:
- TabTool
- Defined in:
- lib/twb/util/csvrecordsatomizer.rb
Constant Summary collapse
- @@ttlogfile =
'AtomizeCSVRecords.ttlog'
- @@csvFileName =
'AtomizedCSVRecords.csv'
- @@atomFields =
['Record #', 'Field Name', 'Field Value']
Instance Attribute Summary collapse
-
#ttdocdir ⇒ Object
Returns the value of attribute ttdocdir.
Attributes included from TabTool
#alerts, #docDir, #docfiles, #funcdoc, #id, #licensed, #logfilename, #logger, #loglevel, #properties, #type, #uuid
Instance Method Summary collapse
-
#initialize(**args) ⇒ CSVRecordsAtomizer
constructor
A new instance of CSVRecordsAtomizer.
- #processFile(fileName) ⇒ Object
Methods included from TabTool
#addDocFile, #alert, #closeDocFiles, #config, #docFile, #docFileMaxNameLen, #docfilesdoc, #docfilesdocto_s, #emit, #emitCSV, #finis, #hasConfig, #init, #initCSV, #initDocDir, #initLogger, #license=, #licensed?, #loadConfig
Constructor Details
#initialize(**args) ⇒ CSVRecordsAtomizer
Returns a new instance of CSVRecordsAtomizer.
32 33 34 35 36 37 38 39 40 41 |
# 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 |
Instance Attribute Details
#ttdocdir ⇒ Object
Returns the value of attribute ttdocdir.
26 27 28 |
# File 'lib/twb/util/csvrecordsatomizer.rb', line 26 def ttdocdir @ttdocdir end |
Instance Method Details
#processFile(fileName) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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 |