Class: Twb::Analysis::DocumentedFieldsMarkdownEmitter

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/analysis/documentedfieldsmarkdownemitter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocumentedFieldsMarkdownEmitter

Returns a new instance of DocumentedFieldsMarkdownEmitter.



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

def initialize
  # puts ""
end

Instance Attribute Details

#docFileNameObject (readonly)

Returns the value of attribute docFileName.



23
24
25
# File 'lib/twb/analysis/documentedfieldsmarkdownemitter.rb', line 23

def docFileName
  @docFileName
end

Instance Method Details

#processTwb(twbName) ⇒ Object



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
# File 'lib/twb/analysis/documentedfieldsmarkdownemitter.rb', line 29

def processTwb twbName
  @twb = Twb::Workbook.new twbName
  @docFileName = '.ttdoc' + @twb.name + '.DocumentedFields.md'
  @docFile     = File.open(@docFileName,'w')
  @docFile.puts "## #{@twb.name}"
  dss = @twb.datasources
  @docFile.puts "#{dss.length} Data Source#{(dss.length>1) ? 's' : ''}"
  @docFile.puts " "
  dss.each do |ds|
    @docFile.puts "- #{ds.uiname}"
  end
  @docFile.puts " "
  dss.each do |ds|
    @docFile.puts "### #{ds.uiname}"
    columnFields = ds.columnFields  #.sort_by { |fldName,calc| fldName }
    columnFields.each do |field|
      commentLines = field.comment 
      calculation  = field.calcField
      # puts "\n#{field.uiname}"
      # puts "Comment? #{commentLines}"
      # puts "Calc   ? #{calculation}"
      @docFile.puts "\n##### #{field.uiname} "
      unless commentLines.nil?
        commentLines.each do |line|
          @docFile.puts "###### #{line}"
        end
      end
      unless calculation.nil?
        @docFile.puts "```"
          @docFile.puts calculation.formulaResolved
          @docFile.puts "\n -- Fields  --" unless calculation.calcFields.empty?
          refFields = SortedSet.new
          calculation.calcFields.each do |cf|
            fds =  if cf.dataSourceRef == :remote then "<<#{cf.dataSource}>>" else '' end
            refFields.add "#{cf.uiName} \t #{fds}"
          end
          refFields.each do |rf|
            @docFile.puts "    #{rf}"
          end
          @docFile.puts "```"
      end
    end
  end
end