Class: Twb::Analysis::CalculatedFields::MarkdownEmitter

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

Instance Attribute Summary collapse

Attributes included from TabTool

#alerts, #docDir, #docfiles, #funcdoc, #id, #licensed, #logfilename, #logger, #loglevel, #metrics, #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) ⇒ MarkdownEmitter

Returns a new instance of MarkdownEmitter.


27
28
29
30
31
32
# 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

Instance Attribute Details

#docFileNameObject (readonly)

Returns the value of attribute docFileName


25
26
27
# File 'lib/twb/analysis/calculatedfields/markdownemitter.rb', line 25

def docFileName
  @docFileName
end

Instance Method Details

#processTWB(twb) ⇒ Object


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
# 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