Class: Twb::Util::TwbDashSheetDataDotBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/util/twbdashsheetdatadotbuilder.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) ⇒ TwbDashSheetDataDotBuilder

Returns a new instance of TwbDashSheetDataDotBuilder.


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

def initialize twb
  @workbook = if twb.instance_of?(Twb::Workbook)
              then twb
              else Twb::Workbook.new(twb)
              end
  @dashCount       = @workbook.dashboards.length
  @worksheets      = @workbook.worksheetNames
  @sheetCount      = @worksheets.length
  @datasources     = @workbook.datasourceUINames
  @dataSourceCount = @datasources.length
  pairs  = processDashboards
  pairs += processWorksheets
  pairs += processOrphans
  initDot
  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/twbdashsheetdatadotbuilder.rb', line 44

def dashCount
  @dashCount
end

#dataSourceCountObject (readonly)

Returns the value of attribute dataSourceCount


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

def dataSourceCount
  @dataSourceCount
end

#dotFileObject (readonly)

Returns the value of attribute dotFile


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

def dotFile
  @dotFile
end

#dotFileNameObject (readonly)

Returns the value of attribute dotFileName


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

def dotFileName
  @dotFileName
end

#sheetCountObject (readonly)

Returns the value of attribute sheetCount


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

def sheetCount
  @sheetCount
end

#workbookObject (readonly)

Returns the value of attribute workbook


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

def workbook
  @workbook
end

Instance Method Details

#buildBody(pairs) ⇒ Object


76
77
78
79
80
81
82
83
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 76

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


93
94
95
96
97
98
99
100
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 93

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


110
111
112
113
114
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 110

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

#initDotObject


70
71
72
73
74
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 70

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

#labelDataSourcesObject


102
103
104
105
106
107
108
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 102

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

#processDashboardsObject


116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 116

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


143
144
145
146
147
148
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 143

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

#processWorksheetsObject


130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 130

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


85
86
87
88
89
90
91
# File 'lib/twb/util/twbdashsheetdatadotbuilder.rb', line 85

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