Module: TabTool

Constant Summary collapse

@@licensed =
false
@@TTDOCDIR =
'./ttdoc'
@@loglevel =
Logger::DEBUG

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alertsObject (readonly)

Returns the value of attribute alerts


31
32
33
# File 'lib/twb/tabtool.rb', line 31

def alerts
  @alerts
end

#docDirObject

Returns the value of attribute docDir


28
29
30
# File 'lib/twb/tabtool.rb', line 28

def docDir
  @docDir
end

#docfilesObject

Returns the value of attribute docfiles


28
29
30
# File 'lib/twb/tabtool.rb', line 28

def docfiles
  @docfiles
end

#funcdocObject (readonly)

Returns the value of attribute funcdoc


31
32
33
# File 'lib/twb/tabtool.rb', line 31

def funcdoc
  @funcdoc
end

#idObject

Returns the value of attribute id


30
31
32
# File 'lib/twb/tabtool.rb', line 30

def id
  @id
end

#licensedObject (readonly)

Returns the value of attribute licensed


31
32
33
# File 'lib/twb/tabtool.rb', line 31

def licensed
  @licensed
end

#logfilenameObject

Returns the value of attribute logfilename


29
30
31
# File 'lib/twb/tabtool.rb', line 29

def logfilename
  @logfilename
end

#loggerObject

Returns the value of attribute logger


29
30
31
# File 'lib/twb/tabtool.rb', line 29

def logger
  @logger
end

#loglevelObject

Returns the value of attribute loglevel


29
30
31
# File 'lib/twb/tabtool.rb', line 29

def loglevel
  @loglevel
end

#metricsObject (readonly)

Returns the value of attribute metrics


31
32
33
# File 'lib/twb/tabtool.rb', line 31

def metrics
  @metrics
end

#propertiesObject

Returns the value of attribute properties


30
31
32
# File 'lib/twb/tabtool.rb', line 30

def properties
  @properties
end

#ttdocdirObject

Returns the value of attribute ttdocdir


28
29
30
# File 'lib/twb/tabtool.rb', line 28

def ttdocdir
  @ttdocdir
end

#typeObject

Returns the value of attribute type


30
31
32
# File 'lib/twb/tabtool.rb', line 30

def type
  @type
end

#uuidObject

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

#closeDocFilesObject


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

#docFileMaxNameLenObject


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

#finisObject


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

#initObject


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

#initDocDirObject


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

#initLoggerObject


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

Returns:

  • (Boolean)

89
90
91
# File 'lib/twb/tabtool.rb', line 89

def licensed?
  @@licensed
end

#loadConfigObject


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