Class: Twb::Analysis::GoogleSheetDataSourcesAnalyzer

Inherits:
Object
  • Object
show all
Includes:
TabTool
Defined in:
lib/twb/analysis/datasources/googlesheetdatasourcesanalyzer.rb

Instance Attribute Summary collapse

Attributes included from TabTool

#alerts, #docDir, #docfiles, #funcdoc, #id, #licensed, #logfilename, #logger, #loglevel, #properties, #ttdocdir, #type, #uuid

Instance Method Summary collapse

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) ⇒ GoogleSheetDataSourcesAnalyzer

Returns a new instance of GoogleSheetDataSourcesAnalyzer.


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/twb/analysis/datasources/googlesheetdatasourcesanalyzer.rb', line 30

def initialize(**args)
  @args = args
  #-- TODO move @csvAdd * #csvMode resolution to TabTool
  @csvAdd  = args[:csvMode] == :add
  @csvMode = @csvAdd ? 'a' : 'w'
  emit "@csvAdd : #{@csvAdd}" 
  emit "@csvMode: #{@csvMode}" 
  #--
  init
  #-- set up metrics
  @twbcount   = 0
  @dscount    = 0
  @filecount  = 0
  @sheetcount = 0
  #--
  @funcdoc    = {:class=>self.class, :blurb=>'Analyze Google Sheet Data Sources', :description=>nil,}
  docFileName = docFile('GoogleSheetDataSources.csv')
  @csv        = CSV.open(docFileName, 'w')
  unless @csvAdd
    @csv << ["Workbook",'Data Source','Connection','File Name','Type','Table Name','Field']
  end
  # @docfiles = [{:name=>docFileName,:description=>"CSV File containing the data relating Google Sheet-based Data Sources."}]
  addDocFile @dashSheetsCSV, docFileName, "Workbooks, Dashboards, and their Worksheets"
end

Instance Attribute Details

#localEmitObject

Returns the value of attribute localEmit


27
28
29
# File 'lib/twb/analysis/datasources/googlesheetdatasourcesanalyzer.rb', line 27

def localEmit
  @localEmit
end

#twbcountObject (readonly)

Returns the value of attribute twbcount


28
29
30
# File 'lib/twb/analysis/datasources/googlesheetdatasourcesanalyzer.rb', line 28

def twbcount
  @twbcount
end

#twbnameObject (readonly)

Returns the value of attribute twbname


28
29
30
# File 'lib/twb/analysis/datasources/googlesheetdatasourcesanalyzer.rb', line 28

def twbname
  @twbname
end

Instance Method Details

#metricsObject


94
95
96
97
98
99
100
101
# File 'lib/twb/analysis/datasources/googlesheetdatasourcesanalyzer.rb', line 94

def metrics
  {
    # '# of Workbooks'    => @twbcount,
    '# of Data Sources' => @dscount,
    '# of Google Docs'  => @filecount,
    '# of Worksheets'   => @sheetcount
  }
end

#processTWB(twb) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/twb/analysis/datasources/googlesheetdatasourcesanalyzer.rb', line 55

def processTWB twb
  if Twb::Workbook != twb.class
    @twb = Twb::Workbook.new twb
  else
    @twb = twb
  end
  @twbname = @twb.name
  emit  "Workbook:: #{@twbname}"
  @twbcount += 1
  dss        = twb.datasources
  dss.each do |ds|
      emit ds.uiname
      @dscount += 1
      conns = ds.node.xpath(".//connection[@class='google-sheets']")
      if conns.length > 0
          @relation   = ds.node.at_xpath('./connection/relation')
          @relName    = @relation.nil? ? 'n/a - no relation in connection' : @relation['name']
          @relType    = @relation.nil? ? 'n/a - no relation in connection' : @relation['type']
          @fileName   = ds.node.at_xpath('.//named-connection/connection')['filename']
          @filecount += 1
          emit "FILENAME: #{@fileName}"
          tables = ds.node.xpath(".//relation[@type='table']")
          # emit "# Tables: #{tables.length}"
          tables.each do |table|
            @sheetcount += 1
            tableName = table.attribute('name')
            columns   = table.xpath('.//column')
            columns.each do |column|
              emit    [@twbname,ds.uiname,@relName,@fileName,@relType,tableName,column.attribute('name')].to_csv
              @csv << [@twbname,ds.uiname,@relName,@fileName,@relType,tableName,column.attribute('name')]
              emit ''
            end
          end
      end
      emit " "
  end
  finis
end