Class: Twb::Analysis::DataSources::ExtractsAnalyzer

Inherits:
Object
  • Object
show all
Includes:
TabTool
Defined in:
lib/twb/analysis/datasources/extractsanalyzer.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) ⇒ ExtractsAnalyzer

Returns a new instance of ExtractsAnalyzer.


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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/twb/analysis/datasources/extractsanalyzer.rb', line 29

def initialize(**args)
  @args      = args
  @recordDir = !@args.nil? && @args[:recordDir] == true
  @ttdocdir  = @args[:ttdocdir]
  @csvAdd    = !@args.nil? && args[:csvMode] == :add
  @csvMode   = @csvAdd ? 'a' : 'w'
  init
  @funcdoc   = {:class=>self.class, :blurb=>'Analyze Extracts', :description=>'Identifies Data Source Extracts & records relevant data.',}
  #--
  docFileName  = docFile('Extracts.csv')
  @extractsCSV = CSV.open(docFileName,@csvMode)
  #--
    # <extract count='-1' enabled='true' units='records'>
    #   <connection access_mode='readonly' 
    #               authentication='auth-none' 
    #               author-locale='en_US' 
    #               class='hyper' 
    #               dbname='C:/tech/Tableau/Tableau Tools/Ruby/gems/twb/lib/twb/analysis/datasources/data/Sample - World Bank Indicators (Excel).hyper' 
    #               default-settings='yes' 
    #               schema='Extract' 
    #               sslmode='' 
    #               update-time='05/17/2019 10:39:21 PM' 
    #               username='tableau_internal_user'>
    #     <relation name='Extract' table='[Extract].[Extract]' type='table' />
    #     <refresh>
    #       <refresh-event add-from-file-path='Sample - World Bank Indicators (Excel)' increment-value='%null%' refresh-type='create' rows-inserted='2354' timestamp-start='2019-05-17 22:39:21.474' />
    #     </refresh>
    #   </connection>
    # </extract>
    #--
  unless @csvAdd
    @csvHeader = [ 'Rec #', 
                   'Workbook', 
                   'Data Source',
                   'Enabled',
                   'Units',
                   'Access Mode',
                   'Authentication',
                   'Class',
                   'Extract Name (FQ)',
                   'Extract Name',
                   'Extract Directory',
                   'Default Settings',
                   'Schema',
                   'SSL Mode',
                   'Updated (UTC)',
                   'User Name'
                 ]
    if @recordDir
      @csvHeader.push 'Workbook Dir'
    end
    @extractsCSV << @csvHeader
  end
  addDocFile @extractsCSV, docFileName, "Workbooks and their Data Source Extracts."
  #--
  @twbCount     = 0
  @dsCount      = 0
  @extractCount = 0
  @recNum       = 0
end

Instance Attribute Details

#localEmitObject

Returns the value of attribute localEmit


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

def localEmit
  @localEmit
end

Instance Method Details

#metricsObject


90
91
92
93
94
95
# File 'lib/twb/analysis/datasources/extractsanalyzer.rb', line 90

def metrics
  {
    '# of Data Sources' => @dsCount,
    '# of Extracts'     => @extractCount
  }
end

#parseDataSourcesObject


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
# File 'lib/twb/analysis/datasources/extractsanalyzer.rb', line 107

def parseDataSources
  @dataSources = @twb.datasources
  @dataSources.each do |ds|
    @dsCount += 1
    emit "DATA SOURCE:: #{ds.name}"
    dsNode = ds.node
    exnode = ds.node.at_xpath('./extract')
    unless exnode.nil?
      cnNode = exnode.at_xpath('./connection')
      # emit true, cnNode
      unless cnNode.nil?
        @extractCount += 1
        dbName = cnNode['dbname']
        # emit true, "cnNode['dbname'] :: #{cnNode['dbname']}"
        # unless dbName.nil?
          exName = File.basename dbName
          exDir  = File.dirname  dbName
        # end
        recordCSV [ @twbName,
                    ds.uiname,
                    exnode['enabled'],
                    exnode['units'],
                    cnNode['access_mode'],
                    cnNode['authentication'],
                    cnNode['class'],
                    dbName,
                    exName,
                    exDir,
                    cnNode['default-settings'],
                    cnNode['schema'],
                    cnNode['sslmode'],
                    cnNode['update-time'],
                    cnNode['username']
                  ]
      end
    end
  end
end

#processTWB(twb) ⇒ Object


97
98
99
100
101
102
103
104
105
# File 'lib/twb/analysis/datasources/extractsanalyzer.rb', line 97

def processTWB twb
   @twb     = twb
   @twbName = @twb.name
   @twbDir  = @twb.dir
   emit "   -- #{@twbName}"
   @twbCount += 1
   parseDataSources
   finis
end