Module: TabTool
- Included in:
- Twb::Analysis::CalculatedFields::DotAnalyzer, Twb::Analysis::CalculatedFields::MarkdownEmitter, Twb::Analysis::CalculatedFieldsAnalyzer, Twb::Analysis::CategoricalColorCodingAnalyzer, Twb::Analysis::DashSheetsAnalyzer, Twb::Analysis::DashboardsSummarizer, Twb::Analysis::DataSourceOriginsAnalyzer, Twb::Analysis::DataSources::DataSourceFieldsAnalyzer, Twb::Analysis::DataSources::DataSourceFieldsCSVEmitter, Twb::Analysis::DataSources::DataSourceFilesAnalyzer, Twb::Analysis::DataSources::DataSourcesEnumerator, Twb::Analysis::DataSources::ExtractsAnalyzer, Twb::Analysis::DataSources::FieldsAliasesAnalyzer, Twb::Analysis::GoogleSheetDataSourcesAnalyzer, Twb::Analysis::GroupFieldsAnalyzer, Twb::Analysis::ParametersAnalyzer, Twb::Analysis::SheetFieldsAnalyzer, Twb::Analysis::SheetFiltersAnalyzer, Twb::Analysis::SheetFiltersAnalyzerA, Twb::Analysis::SheetSourcesAnalyzer, Twb::Analysis::SheetsInTooltipAnalyzer, Twb::Analysis::WorkbookSummaryAnalyzer, Twb::Analysis::WorksheetSummarizer, Twb::CalculatedField, Twb::Connection, Twb::DataSource, Twb::FieldCalculation, Twb::GroupField, Twb::Parameter, Twb::QuickFilter, Twb::ReferencedField, Twb::TabToolTest, Twb::Util::AtomizeCSVRecords, Twb::Util::CSVRecordsAtomizer, Twb::Util::Cypher, Twb::Util::FieldDomainLoader, Twb::Util::GML, Twb::Worksheet
- Defined in:
- lib/twb/tabtool.rb
Constant Summary collapse
- @@licensed =
false
- @@TTDOCDIR =
'./ttdoc'
- @@loglevel =
Logger::DEBUG
Instance Attribute Summary collapse
-
#alerts ⇒ Object
readonly
Returns the value of attribute alerts.
-
#docDir ⇒ Object
Returns the value of attribute docDir.
-
#docfiles ⇒ Object
Returns the value of attribute docfiles.
-
#funcdoc ⇒ Object
readonly
Returns the value of attribute funcdoc.
-
#id ⇒ Object
Returns the value of attribute id.
-
#licensed ⇒ Object
readonly
Returns the value of attribute licensed.
-
#logfilename ⇒ Object
Returns the value of attribute logfilename.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#loglevel ⇒ Object
Returns the value of attribute loglevel.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#ttdocdir ⇒ Object
Returns the value of attribute ttdocdir.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #addDocFile(file, name, description) ⇒ Object
- #alert(str) ⇒ Object
- #closeDocFiles ⇒ Object
- #config(param) ⇒ Object
- #docFile(name) ⇒ Object
- #docFileMaxNameLen ⇒ Object
- #docfilesdoc(pad = ' ', desc = 'For documentation and generated data see the following:') ⇒ Object
- #docfilesdocto_s(pad = ' ', desc = 'For documentation and generated data see the following:') ⇒ Object
- #emit(local = @localEmit, stuff) ⇒ Object
- #emitCSV(csvFile, record) ⇒ Object
- #finis ⇒ Object
- #hasConfig(param) ⇒ Object
- #init ⇒ Object
-
#initCSV(fileName, desc = nil, header = nil) ⇒ Object
def metrics {} end.
- #initDocDir ⇒ Object
- #initLogger ⇒ Object
- #license=(fileName) ⇒ Object
- #licensed? ⇒ Boolean
- #loadConfig ⇒ Object
Instance Attribute Details
#alerts ⇒ Object (readonly)
Returns the value of attribute alerts.
31 32 33 |
# File 'lib/twb/tabtool.rb', line 31 def alerts @alerts end |
#docDir ⇒ Object
Returns the value of attribute docDir.
28 29 30 |
# File 'lib/twb/tabtool.rb', line 28 def docDir @docDir end |
#docfiles ⇒ Object
Returns the value of attribute docfiles.
28 29 30 |
# File 'lib/twb/tabtool.rb', line 28 def docfiles @docfiles end |
#funcdoc ⇒ Object (readonly)
Returns the value of attribute funcdoc.
31 32 33 |
# File 'lib/twb/tabtool.rb', line 31 def funcdoc @funcdoc end |
#id ⇒ Object
Returns the value of attribute id.
30 31 32 |
# File 'lib/twb/tabtool.rb', line 30 def id @id end |
#licensed ⇒ Object (readonly)
Returns the value of attribute licensed.
31 32 33 |
# File 'lib/twb/tabtool.rb', line 31 def licensed @licensed end |
#logfilename ⇒ Object
Returns the value of attribute logfilename.
29 30 31 |
# File 'lib/twb/tabtool.rb', line 29 def logfilename @logfilename end |
#logger ⇒ Object
Returns the value of attribute logger.
29 30 31 |
# File 'lib/twb/tabtool.rb', line 29 def logger @logger end |
#loglevel ⇒ Object
Returns the value of attribute loglevel.
29 30 31 |
# File 'lib/twb/tabtool.rb', line 29 def loglevel @loglevel end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
31 32 33 |
# File 'lib/twb/tabtool.rb', line 31 def metrics @metrics end |
#properties ⇒ Object
Returns the value of attribute properties.
30 31 32 |
# File 'lib/twb/tabtool.rb', line 30 def properties @properties end |
#ttdocdir ⇒ Object
Returns the value of attribute ttdocdir.
28 29 30 |
# File 'lib/twb/tabtool.rb', line 28 def ttdocdir @ttdocdir end |
#type ⇒ Object
Returns the value of attribute type.
30 31 32 |
# File 'lib/twb/tabtool.rb', line 30 def type @type end |
#uuid ⇒ Object
Returns the value of attribute uuid.
30 31 32 |
# File 'lib/twb/tabtool.rb', line 30 def uuid @uuid end |
Instance Method Details
#addDocFile(file, name, description) ⇒ Object
118 119 120 121 |
# File 'lib/twb/tabtool.rb', line 118 def addDocFile file, name, description @docfiles = [] if @docfiles.nil? @docfiles << {:file=>file, :name=>name, :description=>description} end |
#alert(str) ⇒ Object
214 215 216 217 |
# File 'lib/twb/tabtool.rb', line 214 def alert str @alerts << str emit "#{self.class} :: #{str}" end |
#closeDocFiles ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/twb/tabtool.rb', line 123 def closeDocFiles emit "Closing doc files" unless @docfiles.nil? @docfiles.each do |dfh| docfile = dfh[:file] fileName = dfh[:name] emit " -- #{dfh}" # system "ls -l '#{fileName}'" docfile.close unless docfile.nil? # system "ls -l '#{fileName}'" # emit true, " -- #{dfh[:name]}" end end emit "-----------------" end |
#config(param) ⇒ Object
102 103 104 |
# File 'lib/twb/tabtool.rb', line 102 def config param hasConfig(param) ? @configParams[param] : nil end |
#docFile(name) ⇒ Object
81 82 83 |
# File 'lib/twb/tabtool.rb', line 81 def docFile name @docDir.nil? ? name : "#{@docDir}/#{name}" end |
#docFileMaxNameLen ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/twb/tabtool.rb', line 139 def docFileMaxNameLen maxlen = 0 docfiles.each do |f| nameLen = f[:name].class == String ? [maxlen, f[:name].length].max : 0 maxlen = nameLen.nil? ? maxlen : [maxlen,nameLen].max end return maxlen end |
#docfilesdoc(pad = ' ', desc = 'For documentation and generated data see the following:') ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/twb/tabtool.rb', line 148 def docfilesdoc(pad=' ',desc='For documentation and generated data see the following:') lines = SortedSet.new paddesc = "#{pad}#{desc}" unless @docfiles.nil? || @docfiles.empty? nameLen = docFileMaxNameLen docfiles.each do |dfi| lines << "#{pad}- %-#{nameLen}s %-s " % [ dfi[:name], dfi[:description] ] end end docLines = lines.empty? || paddesc =~ /^[ ]+/ ? [] : [' ',"#{pad}#{desc}"] lines.each do |l| docLines << l end return docLines end |
#docfilesdocto_s(pad = ' ', desc = 'For documentation and generated data see the following:') ⇒ Object
164 165 166 167 168 |
# File 'lib/twb/tabtool.rb', line 164 def docfilesdocto_s(pad=' ',desc='For documentation and generated data see the following:') str = '' docfilesdoc(pad,desc).each { |l| str += "#{l}\n"} return str end |
#emit(local = @localEmit, stuff) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/twb/tabtool.rb', line 192 def emit(local=@localEmit, stuff) # if @logger.closed? # @logger.reopen # end if stuff.is_a? String then lines = stuff.split(/\n/) lines.each do |line| @logger.debug "#{@emitPrefix}#{line}" unless @logger.nil? puts "#{@emitPrefix}#{line}" if local end else @logger.debug "#{@emitPrefix}#{stuff}" unless @logger.nil? puts "#{@emitPrefix}#{stuff}" if local end end |
#emitCSV(csvFile, record) ⇒ Object
208 209 210 211 212 |
# File 'lib/twb/tabtool.rb', line 208 def emitCSV csvFile, record emit record csvFile << record unless csvFile.nil? emit "##### ALERT ##### CSV file expected, is nil" if csvFile.nil? end |
#finis ⇒ Object
219 220 221 |
# File 'lib/twb/tabtool.rb', line 219 def finis # @logger.close unless @logger.nil? || @logger.closed? end |
#hasConfig(param) ⇒ Object
97 98 99 100 |
# File 'lib/twb/tabtool.rb', line 97 def hasConfig param loadConfig if @configParams.nil? @configParams[param] ? true : false end |
#init ⇒ Object
41 42 43 44 45 |
# File 'lib/twb/tabtool.rb', line 41 def init @alerts = [] initDocDir initLogger end |
#initCSV(fileName, desc = nil, header = nil) ⇒ Object
def metrics
{}
end
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/twb/tabtool.rb', line 174 def initCSV(fileName, desc=nil, header=nil) emit "def initCSV" csvName = docFile(fileName) emit " @recordDir: #{@recordDir.nil?} \t :: #{@recordDir}" emit " header: #{@header.nil?} \t :: #{header}" emit " csvName: #{csvName.nil?} :: #{csvName}" csvFile = CSV.open(csvName, 'w') unless header.nil? if @recordDir csvFile << header.push('Workbook Directory') else csvFile << header end end addDocFile csvFile, csvName, desc return csvFile end |
#initDocDir ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/twb/tabtool.rb', line 53 def initDocDir # puts "def initDocDir" # return if @@TTDOCDIR.nil? # return if ''.eql?($ttdocdir) && ''.eql?(@@TTDOCDIR) @docDir = @ttdocdir.nil? ? @@TTDOCDIR : @ttdocdir # puts " @@TTDOCDIR: #{@@TTDOCDIR}" # puts " @ttdocdir: #{@ttdocdir}" # puts " @docDir : #{@docDir}" # puts "" return if Dir.exists?(@docDir) if File.exists? @docDir # on the off chance that the doc dir is already present as a file @docDir = '' else Dir.mkdir @docDir end return @docDir end |
#initLogger ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/twb/tabtool.rb', line 71 def initLogger @logger = nil if config(:log) logFileName = docFile("#{self.class.to_s.split('::').last}.ttlog") @logger = Logger.new(logFileName) @logger.level = Logger::DEBUG end return @logger end |
#license=(fileName) ⇒ Object
85 86 87 |
# File 'lib/twb/tabtool.rb', line 85 def license= fileName @@licensed = fileName.is_a?(String) && File.exist?(fileName) end |
#licensed? ⇒ Boolean
89 90 91 |
# File 'lib/twb/tabtool.rb', line 89 def licensed? @@licensed end |
#loadConfig ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/twb/tabtool.rb', line 106 def loadConfig @configParams = if File.exist?('./ttconfig.yml') YAML.load( File.open('./ttconfig.yml').read ) else {} end end |