Class: Twb::Util::TwbDashesSheetDataDotBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/util/twbdashessheetdatadotbuilder.rb

Constant Summary collapse

@@dotHeader =
<<-DOTHEADER
digraph g {
    graph [rankdir="LR" splines="line"];
    node  [shape="box"  width="2"];
      "Tableau Tools generated Workbook map" [color="white" border="0"];
DOTHEADER
@@dotFooter =
<<-DOTFOOTER
  }
     subgraph cluster_0 {
    color=white;
    node [shape="box3d"  style="filled" ];
    "Workbook" -> "Dashboard" -> "Worksheet" -> "Data Source"
    "Workbook"    "Dashboard";
    "Worksheet";
    "Data Source";
   }
  }
DOTFOOTER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(twb) ⇒ TwbDashesSheetDataDotBuilder

Returns a new instance of TwbDashesSheetDataDotBuilder.


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 46

def initialize twb
  @workbook = if twb.instance_of?(Twb::Workbook)
              then twb
              else Twb::Workbook.new(twb)
              end
  @dashboards =  @workbook.dashboards
  @dashboards.each do |dash|
    initDot
  end
  buildBody(pairs)
  sameRank([@workbook.name]           )
  sameRank( @workbook.dashboardNames  )
  sameRank( @workbook.worksheetNames  )
  sameRank( @workbook.datasourceNames )
  buildHeader
  labelDataSources
  closeDot
end

Instance Attribute Details

#dashCountObject (readonly)

Returns the value of attribute dashCount


44
45
46
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 44

def dashCount
  @dashCount
end

#dashesDotFilesObject (readonly)

Returns the value of attribute dashesDotFiles


44
45
46
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 44

def dashesDotFiles
  @dashesDotFiles
end

#dataSourceCountObject (readonly)

Returns the value of attribute dataSourceCount


44
45
46
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 44

def dataSourceCount
  @dataSourceCount
end

#dotFileNameObject (readonly)

Returns the value of attribute dotFileName


44
45
46
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 44

def dotFileName
  @dotFileName
end

#sheetCountObject (readonly)

Returns the value of attribute sheetCount


44
45
46
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 44

def sheetCount
  @sheetCount
end

#workbookObject (readonly)

Returns the value of attribute workbook


44
45
46
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 44

def workbook
  @workbook
end

Instance Method Details

#buildBody(pairs) ⇒ Object


71
72
73
74
75
76
77
78
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 71

def buildBody(pairs)
  @dotFile.puts "\n   subgraph cluster_1 {"
  @dotFile.puts "       color= grey;"
  @dotFile.puts ""
  pairs.each { |pair| @dotFile.puts "      \"#{pair[0]}\" -> \"#{pair[1]}\" " }
  @dotFile.puts ""
  @dotFile.puts "   }"
end

#buildHeaderObject


88
89
90
91
92
93
94
95
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 88

def buildHeader
 @dotFile.puts ''
 @dotFile.puts '   subgraph cluster_0 {'
 @dotFile.puts '     color=white;'
 @dotFile.puts '     node [shape="box3d"  style="filled" ];'
 @dotFile.puts '     "Workbook" -> "Dashboard" -> "Worksheet" -> "Data Source"'
 @dotFile.puts '   }'
end

#closeDotObject


105
106
107
108
109
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 105

def closeDot
 @dotFile.puts ' '
 @dotFile.puts '}'
 @dotFile.close
end

#initDotObject


65
66
67
68
69
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 65

def initDot
  @dotFileName = @workbook.name + '.dot'
  @dotFile = File.open(@dotFileName,'w')
  @dotFile.puts @@dotHeader
end

#labelDataSourcesObject


97
98
99
100
101
102
103
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 97

def labelDataSources
  @dotFile.puts " "
  @workbook.datasources.each do |ds|
    name = ds.name
    @dotFile.puts "  \"#{name}\" [label=\"#{ds.uiname}\"];"
  end
end

#processDashboardsObject


111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 111

def processDashboards
  pairs = []
  @workbook.dashboards.each do |dash|
    dashName = dash.name
    pairs          << [@workbook.name,dashName]
    dash.worksheets.each do |sheet|
      sheetName = sheet.name
      pairs << [dashName,sheetName]
      @worksheets.delete sheetName
    end
  end
  return pairs
end

#processOrphansObject


138
139
140
141
142
143
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 138

def processOrphans
  pairs = []
  @datasources.each { |dsn| pairs << [@workbook.name,dsn] }
  @worksheets.each  { |wsn| pairs << [@workbook.name,wsn] }
  return pairs
end

#processWorksheetsObject


125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 125

def processWorksheets
  pairs = []
  @workbook.worksheets.each do |sheet|
    sheetName   = sheet.name
    sheet.datasources.each do |ds|
      dsName = ds.name
      pairs  << [sheetName,ds.name]
      @datasources.delete ds.uiname
    end
  end
  return pairs
end

#sameRank(elements) ⇒ Object


80
81
82
83
84
85
86
# File 'lib/twb/util/twbdashessheetdatadotbuilder.rb', line 80

def sameRank(elements)
  @dotFile.puts "\n  {rank=same "
  elements.each do |e|
    @dotFile.puts "     \"#{e}\""
  end
  @dotFile.puts "  }"
end