Class: Twb::Analysis::CalculatedFields::CSVEmitter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCSVEmitter

Returns a new instance of CSVEmitter.


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/twb/analysis/calculatedfields/csvemitter.rb', line 28

def initialize
  @calcFieldsContents = 'Calculated Fields with Formulas'
  @calcFieldsType     = 'CalculatedFieldsWithFormulas'
  @calcFieldsHeader   = ['Record #',
                         'Workbook',           'Workbook Dir',
                         'Data Source Name (tech)', 'Data Source Caption', 'Data Source Name',
                         'Field Name (tech)',  'Field Caption',       'Field Name',
                         'Data Source + Field Name (tech)',
                         'Formula (flat)',
                         'Formula Length',
                         'Formula Table Calc?',
                         'Formula LOD?',
                         'Formula LOD Code Position'
                        ]

  @refFieldsContents = 'Fields referenced in Calculated Fields Formulae'
  @refFieldsType     = 'CalculatedFieldsReferencedFields'
  @refFieldsHeader   = ['Record #',
                        'Workbook',           'Workbook Dir',
                        'Data Source Name (tech)', 'Data Source Caption', 'Data Source Name',
                        'Field Name (tech)',  'Field Caption',       'Field Name',
                        'Referenced Field',
                        'Referenced DataSource',
                        'Referenced DataSource Location'
                       ]


  @dictionary      = [
                        { :contents   => @calcFieldsContents,
                          :fileType   => @calcFieldsType,
                          :fileHeader => @calcFieldsHeader
                        },
                        { :contents   => @refFieldsContents,
                          :fileType   => @calcFieldsType,
                          :fileHeader => @calcFieldsHeader
                        }
                      ]
end

Instance Attribute Details

#calcFieldsCountObject (readonly)

Returns the value of attribute calcFieldsCount


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

def calcFieldsCount
  @calcFieldsCount
end

#calcFieldsFileObject (readonly)

Returns the value of attribute calcFieldsFile


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

def calcFieldsFile
  @calcFieldsFile
end

#calcFieldsHeaderObject (readonly)

Returns the value of attribute calcFieldsHeader


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

def calcFieldsHeader
  @calcFieldsHeader
end

#calcFieldsRecordsObject (readonly)

Returns the value of attribute calcFieldsRecords


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

def calcFieldsRecords
  @calcFieldsRecords
end

#calcFieldsTypeObject (readonly)

Returns the value of attribute calcFieldsType


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

def calcFieldsType
  @calcFieldsType
end

#csvFilesObject (readonly)

Returns the value of attribute csvFiles


26
27
28
# File 'lib/twb/analysis/calculatedfields/csvemitter.rb', line 26

def csvFiles
  @csvFiles
end

#dictionaryObject (readonly)

Returns the value of attribute dictionary


26
27
28
# File 'lib/twb/analysis/calculatedfields/csvemitter.rb', line 26

def dictionary
  @dictionary
end

#refFieldsCountObject (readonly)

Returns the value of attribute refFieldsCount


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

def refFieldsCount
  @refFieldsCount
end

#refFieldsFileObject (readonly)

Returns the value of attribute refFieldsFile


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

def refFieldsFile
  @refFieldsFile
end

#refFieldsHeaderObject (readonly)

Returns the value of attribute refFieldsHeader


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

def refFieldsHeader
  @refFieldsHeader
end

#refFieldsRecordsObject (readonly)

Returns the value of attribute refFieldsRecords


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

def refFieldsRecords
  @refFieldsRecords
end

#refFieldsTypeObject (readonly)

Returns the value of attribute refFieldsType


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

def refFieldsType
  @refFieldsType
end

Instance Method Details

#processTwb(twbFileName) ⇒ Object

def calcFieldsHeader

@refFieldsHeader

end


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
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
# File 'lib/twb/analysis/calculatedfields/csvemitter.rb', line 87

def processTwb twbFileName
   twb     = File.basename(twbFileName)
  @twb     = Twb::Workbook.new twb
  # --
  @calcFieldsFile = "#{twb}.#{@calcFieldsType}.csv"
  @csvCalcFile    = CSV.open(@calcFieldsFile,'w')
  @csvCalcFile << @calcFieldsHeader
  @calcFieldsCount   = 0
  @calcFieldsRecords = []
  # --
  @refFieldsFile = "#{twb}.#{@refFieldsType}.csv" # twb + '.CalcReferenceFields.csv'
  @csvRefFile    = CSV.open(@refFieldsFile,'w')
  @csvRefFile << @refFieldsHeader
  @refFieldsCount   = 0
  @refFieldsRecords = []
  # --
  @csvFiles = [
                { :contents => @calcFieldsContents,
                  :name     => @calcFieldsFile,
                  :records  => @calcFieldsRecords
                },
                { :contents => @refFieldsContents,
                  :name     => @refFieldsFile,
                  :records  => @refFieldsRecords
                }
              ]
  # --
  dss = @twb.datasources
  dss.each do |ds|
    calcFields = ds.calculatedFieldsMap.sort_by { |fldName,calc| fldName }
    calcFields.each do |fldname, field|
      formRecord  =  [ @calcFieldsCount += 1,
                       @twb.name,  @twb.dir,
                       ds.name,    ds.caption,    ds.uiname,
                       field.name, field.caption, field.uiname,
                       "#{ds.name}.#{field.name}",
                       field.calculation.formulaFlatResolved,
                       field.calculation.formula.length,
                       field.calculation.is_tableCalc,
                       field.calculation.is_lod,
                       field.calculation.lodCodePos
                     ]
      @calcFieldsRecords.push formRecord
      @csvCalcFile  <<  formRecord
      #--
      field.calculation.calcFields.each do |cf|
        refRecord = [ @refFieldsCount += 1,
                      @twb.name,  @twb.dir,
                      ds.name,    ds.caption,    ds.uiname,
                      field.name, field.caption, field.uiname,
                      cf.uiName,
                      cf.dataSource,  
                      cf.dataSourceRef,
                    ]
        @refFieldsRecords.push refRecord
        @csvRefFile << refRecord               
      end
    end
  end
  @csvCalcFile.close unless @csvCalcFile.nil?
  @csvRefFile.close unless @csvRefFile.nil?
end