Top Level Namespace
Defined Under Namespace
Modules: Graph, TabTool, Twb Classes: CodedField, HashToHTMLList, There
Instance Method Summary collapse
- #emit(stuff) ⇒ Object
- #init ⇒ Object
- #localColumns(dataSource) ⇒ Object
- #metaDataRecords(dataSource) ⇒ Object
- #method_name ⇒ Object
- #proc(file) ⇒ Object
- #process(file) ⇒ Object
- #processTwb(twbName) ⇒ Object
- #relationFields(dataSource, connClass) ⇒ Object
- #showPaths ⇒ Object
Instance Method Details
#emit(stuff) ⇒ Object
26 27 28 29 |
# File 'lib/twb/finddsfields.rb', line 26 def emit stuff $pFile.puts stuff puts stuff if $localEmit end |
#init ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/twb/finddsfields.rb', line 5 def init system 'cls' $pFile = File.open('identifyFields.txt','w') sqiCSV = 'TWBFieldsByType.csv' $fieldsCSV = CSV.open(sqiCSV, 'w') $fieldsCSV << [ 'TWB', 'Data Connection - UI', 'Field Name', 'TWB Field Type', 'Data Type', 'Calc Field?', ] $path = if ARGV.empty? then '**/*.twb' else ARGV[0] end emit " " emit " Identifying fields in Tableau Workbook Data Connections (TWDCs).\n " emit " Looking for Workbooks matching: '#{$path}' - from: #{ARGV[0]}\n\n " end |
#localColumns(dataSource) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/twb/finddsfields.rb', line 80 def localColumns dataSource emit "\t localColumns " #connClass: '%s'" % [connClass] colNodes = dataSource.xpath('./column') emit " colNodes.size: #{colNodes.size}" fields = {} colNodes.each do |node| calcField = !node.at_xpath('./calculation').nil? = node.attribute('caption') name = node.attribute('name').text.gsub(/^\[/,'').gsub(/\]$/,'') type = node.attribute('datatype') emit " \t name: %s\n \t type: %s\n \t caption: %s" % [name, type, ] = name if .nil? emit " \t caption: %s \n " % [] fields[] = {'type' => type, 'calcField' => calcField} end return fields end |
#metaDataRecords(dataSource) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/twb/finddsfields.rb', line 67 def dataSource emit "\t metaDataRecords " #connClass: '%s'" % [connClass] mdNodes = dataSource.xpath('./connection/metadata-records/metadata-record[@class="column"]') emit " mdNodes.size: #{mdNodes.size}" fields = {} mdNodes.each do |node| name = node.xpath('./local-name').text.gsub(/^\[/,'').gsub(/\]$/,'') type = node.xpath('./local-type').text fields[name] = {'type' => type} end return fields end |
#method_name ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/twb/identifyfields.rb', line 23 def method_name datasources = {} dataSourcesNode = doc.at_xpath('//workbook/datasources') dataSourcesNodes = doc.xpath('//workbook/datasources/datasource').to_a puts " dsn: #{dataSourcesNodes}" datasourceNodes.each do |node| datasource = Twb::DataSource.new(node) datasources[datasource.name] = datasource end end |
#proc(file) ⇒ Object
52 53 54 |
# File 'lib/twb/identifyfields.rb', line 52 def proc file emit "\n == #{file}" end |
#process(file) ⇒ Object
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 |
# File 'lib/twb/finddsfields.rb', line 98 def process file emit "\n == #{file}" doc = Nokogiri::XML(open(file)) dataSourcesNodes = doc.xpath('//workbook/datasources/datasource') dataSourcesNodes.each do |ds| dsCaption = ds.attribute('caption') dsName = ds.attribute('name') emit "\n dsCapt: #{dsCaption}" emit " dsName: '#{dsName}'\n ---" connClass = ds.xpath('./connection/@class') emit "dsCClass: '#{connClass}'\n ---" if dsName != 'Parameters' then # relationFields ds, connClass mdFields = ds mdFields.each do |fname, payload| emit "\t " $fieldsCSV << [file, dsCaption, fname, 'metadata', payload['type'] ] emit [file, dsCaption, fname, 'metadata', payload['type'] ] end colFields = localColumns ds colFields.each do |fname, payload| emit "\t " $fieldsCSV << [file, dsCaption, fname, 'column', payload['type'], payload['calcField'] ] emit [file, dsCaption, fname, 'column', payload['type'], payload['calcField'] ] end end # $paths.each do |type, paths| # emit " type: #{type}" # emit paths['fieldXPath'] # nodes = ds.xpath(paths['fieldXPath']).to_a # nodes.each do |node| # name = node.xpath(paths['nameXPath']).text # emit " fname: #{name}" # end # end end end |
#processTwb(twbName) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/twb/listXMLNodePathsAndAttributes.rb', line 5 def processTwb twbName puts "\t - #{twbName}" twb = Twb::Workbook.new twbName nokodoc = twb.node #Nokogiri::XML(open('dataSources.xml')) # $nodePaths = SortedSet.new $csvFile = CSV.open('xmlNodesAndAttributes.csv','w') $csvFile << ['Workbook', 'Workbook Directory', 'Node Name', 'Node Path', 'Attr Name', 'Attr Value'] nodes = nokodoc.xpath('//.') nodes.each do |n| nodeName = n.name nodePath = n.path.gsub(/\[[0-9]+\]/,'') attrs = n.attributes attrs.each do |attrName,attrValue| $csvFile << [twbName, twbDir, nodeName, nodePath, attrName, attrValue] end if attrs.empty? $csvFile << [ twbName, twbDir, nodeName, nodePath, nil, nil ] end # $nodePaths << n.path.gsub(/\[[0-9]+\]/,'').gsub('/content/workbook/','') end $twbCount += 1 end |
#relationFields(dataSource, connClass) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/twb/finddsfields.rb', line 57 def relationFields dataSource, connClass emit "\t relationFields connClass: '%s'" % [connClass] xPaths = $relClassPaths[connClass] emit "\t xPaths: #{xPaths}" fnodesPath = xPaths['fieldXPath'] fnamePath = xPaths['nameXPath'] fieldNodes = dataSource.xpath(fnodesPath) end |