Class: Twb::Analysis::Sheets::WorksheetDataStructureCSVEmitter

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb

Constant Summary collapse

@@csvSheetPanesFileType =
'WorksheetPanes'
@@csvSheetPanesHeader =
['Record #',
 'Workbook',           
 'Workbook Dir',
 'Worksheet',
 'Pane #',
 'Pane #of',
 'Axis Type',
 'Axis Field Code',
 'Axis Field Data Source',
 'Axis Field Data Source (tech)',
 'Axis Field Prefix',
 'Axis Field Name',
 'Axis Field Suffix'
]
@@csvSheetFieldsFileType =
'WorksheetFieldsStructure'
@@csvSheetFieldsHeader =
['Record #',
 'Workbook',           
 'Workbook Dir',
 'Worksheet',
 'Pane #',
 'Data Source',
 'Data Source (tech)',
 'Function',
 'Field Code',
 'Field Name (tech)',
 'Field Prefix',
 'Field Suffix',
 'Position'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorksheetDataStructureCSVEmitter

Returns a new instance of WorksheetDataStructureCSVEmitter.


61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb', line 61

def initialize
  @csvPanesFileName = "Twb#{@@csvSheetPanesFileType}.csv"
  @csvPanesFile     = CSV.open(@csvPanesFileName,'w')
  @csvPanesFile << @@csvSheetPanesHeader
  # --
  @csvFieldsFileName = "Twb#{@@csvSheetFieldsFileType}.csv"
  @csvFieldsFile     = CSV.open(@csvFieldsFileName,'w')
  @csvFieldsFile << @@csvSheetFieldsHeader
  # --
  @twbsCnt   = 0
  @sheetsCnt = 0
  @panesCnt  = 0
  @fieldsCnt = 0
end

Instance Attribute Details

#sheetCountObject (readonly)

attr_reader :csvFieldsFileName, :csvRecords


26
27
28
# File 'lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb', line 26

def sheetCount
  @sheetCount
end

#sheetNamesObject (readonly)

attr_reader :csvFieldsFileName, :csvRecords


26
27
28
# File 'lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb', line 26

def sheetNames
  @sheetNames
end

Instance Method Details

#emitRowColFields(sheet, type, fields) ⇒ Object


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb', line 167

def emitRowColFields sheet, type, fields
  fieldPos = 0
  fields.each do |field|
    dsuiname = @twb.datasource(field.dataSource).uiname
    @csvFieldsFile << [  @fieldsCnt+=1,     # 'Record #',
                         @twb.name,         # 'Workbook',           
                         @twb.dir,          # 'Workbook Dir',
                         sheet.name,        # 'Worksheet',
                         nil,               # 'Pane #',
                         dsuiname,          # 'Data Source',
                         field.dataSource,  # 'Data Source (tech)',
                         type,              # 'Function',
                         field.code,        # 'Field Code',
                         field.name,        # 'Field Name (tech)',
                         field.prefix,      # 'Field Prefix',
                         field.suffix,      # 'Field Suffix',
                         fieldPos+=1
                      ]
  end
end

#processPaneFields(sheet, node, paneID) ⇒ Object


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb', line 135

def processPaneFields sheet, node, paneID
  encodedFields = node.xpath('.//encodings/*')
  # puts "    flds : #{encodedFields.length} "
  fieldPos = 0
  encodedFields.each do |ef|
    function = ef.name
    field    = Twb::CodedField.new(ef.attribute('column').text)
    dsuiname = @twb.datasource(field.dataSource).uiname
    # puts "      ef : <<#{function}>>  #{ef}  -> #{field} "
    @csvFieldsFile << [  @fieldsCnt+=1,     # 'Record #',
                         @twb.name,         # 'Workbook',           
                         @twb.dir,          # 'Workbook Dir',
                         sheet,             # 'Worksheet',
                         paneID,            # 'Pane #',
                         dsuiname,          # 'Data Source',
                         field.dataSource,  # 'Data Source (tech)',
                         function,          # 'Function',
                         field.code,        # 'Field Code',
                         field.name,        # 'Field Name (tech)',
                         field.prefix,      # 'Field Prefix',
                         field.suffix,      # 'Field Suffix',
                         fieldPos+=1
                      ]
  end

end

#processPanes(sheet) ⇒ Object


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
# File 'lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb', line 101

def processPanes sheet
  pnodes   = sheet.node.xpath('.//panes/pane')
  panesCnt = pnodes.length
  pnodes.each do |node|
    id = node.has_attribute?('id') ? node.attribute('id').text : '0'
    #--
    if    node.has_attribute?('x-axis-name')
      axistype  = 'x'
      field     = Twb::CodedField.new node.attribute('x-axis-name').text
    elsif node.has_attribute?('y-axis-name')
      axistype = 'y'
      field     = Twb::CodedField.new node.attribute('y-axis-name').text
    else 
      axistype  = nil
      field     = nil
    end
    #--
    @csvPanesFile << [ @panesCnt+=1,
                       @twb.name,                           # 'Workbook',           
                       @twb.dir,                            # 'Workbook Dir',
                       sheet.name,                          # 'Worksheet',
                       id,                                  # 'Pane #',
                       panesCnt,                            # 'Pane #of',
                       axistype,                            # 'Axis Type',
                       field.nil? ? ' ' : field.code,        # 'Axis Field Code',
                       field.nil? ? ' ' : field.dataSource,  # 'Axis Field Code',
                       field.nil? ? ' ' : field.prefix,      # 'Axis Field Prefix',
                       field.nil? ? ' ' : field.name,        # 'Axis Field Name',
                       field.nil? ? ' ' : field.suffix,      # 'Axis Field Suffix'
                     ]
    processPaneFields sheet.name, node, id
  end
end

#processRowsCols(sheet) ⇒ Object


162
163
164
165
# File 'lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb', line 162

def processRowsCols sheet
  emitRowColFields sheet, 'row', sheet.rowFields
  emitRowColFields sheet, 'col', sheet.colFields
end

#processTwb(twb) ⇒ Object

def self.csvFileType

@@csvFieldsFileType

end


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/twb/analysis/sheets/worksheetdatastructurecsvemitter.rb', line 84

def processTwb twb
  @twb    = case twb
            when String        then Twb::Workbook.new(twb)
            when Twb::Workbook then twb
            else raise ArgumentError.new("ERROR: #{twb} must be a String or Workbook, is a #{twb.class}")
            end
  # --
  @sheetNames = SortedSet.new
  # --
  sheets = @twb.worksheets
  sheets.each do |sheet|
    @sheetNames << sheet.name
    processPanes    sheet
    processRowsCols sheet
  end
end