class Twb::Analysis::CalculatedFields::MarkdownEmitter
Attributes
docFileName[R]
Public Class Methods
new(**args)
click to toggle source
# File lib/twb/analysis/CalculatedFields/MarkdownEmitter.rb, line 27 def initialize(**args) @args = args init @funcdoc = {:class=>self.class, :blurb=>'Create Markdown files (one per Workbook) documenting Calculated Fields', :description=>'Analyze Calculated Fields - create Markdown files, one per Workbook' } @metrics = {} end
Public Instance Methods
processTWB(twb)
click to toggle source
# File lib/twb/analysis/CalculatedFields/MarkdownEmitter.rb, line 34 def processTWB twb # twb = File.basename(twb) @twb = twb #Twb::Workbook.new twb @docFileName = './ttdoc/' + @twb.name + '.CalculatedFields.md' @docFile = File.open(@docFileName,'w') addDocFile @docFile, @docFileName, "Markdown file of Calculated fields for Workbook '#{@twb.name}'" @docFile.puts "# #{twb.name}" dsNames = @twb.datasourceUINames @docFile.puts "#{dsNames.length} Data Sources" @twb.datasources.each do |ds| @docFile.puts "## #{ds.uiname}" @docFile.puts "__has #{ds.calculatedFields.length} calculated fields__\n " cnt = 0 ds.calculatedFields.each do |cf| cnt += 1 @docFile.puts "### '#{cf.uiname}'" @docFile.puts "```" cf.formulaResolvedLines.each do |l| @docFile.puts "#{l.gsub('<<','[').gsub('>>',']')}" end @docFile.puts "```" if cf.referencedFields.length > 0 fieldsRefOrder = [] fieldsSortSet = SortedSet.new cf.referencedFields.each do |field| fieldsRefOrder.push field.uiname fieldsSortSet << field.uiname end if fieldsRefOrder != fieldsSortSet.to_a @docFile.puts "```" @docFile.puts "Fields - reference order:" fieldsRefOrder.each do |field| @docFile.puts " '#{field}'" end @docFile.puts "```" end if fieldsSortSet.length > 0 @docFile.puts "```" @docFile.puts "Fields:" fieldsSortSet.each do |field| @docFile.puts " '#{field}'" end @docFile.puts "```" end end @docFile.puts "\n " end @docFile.puts "counted #{cnt} calculated fields\n " end # twb.datasources.each if kramdownAvailable emit 'processing Markdown: kramdownAvailable' end finis end
Private Instance Methods
kramdownAvailable()
click to toggle source
# File lib/twb/analysis/CalculatedFields/MarkdownEmitter.rb, line 91 def kramdownAvailable gem_name, *gem_ver_reqs = 'kramdown', '~> 1.17.0' gdep = Gem::Dependency.new(gem_name, *gem_ver_reqs) # find latest that satisifies found_gspec = gdep.matching_specs.max_by(&:version) # instead of using Gem::Dependency, you can also do: # Gem::Specification.find_all_by_name(gem_name, *gem_ver_reqs) # if found_gspec # puts "Requirement '#{gdep}' already satisfied by #{found_gspec.name}-#{found_gspec.version}" # else # puts "Requirement '#{gdep}' not satisfied; could be installing..." # # reqs_string will be in the format: "> 1.0, < 1.2" # # reqs_string = gdep.requirements_list.join(', ') # # multi-arg is safer, to avoid injection attacks # # system('gem', 'install', gem_name, '-v', reqs_string) # end end