twb 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE.md +1 -0
- data/lib/twb/util/twbDashSheetDataDotBuilder.rb +0 -2
- data/lib/twb/util/twbDashesSheetDataDotBuilder.rb +153 -0
- data/lib/twb/workbook.rb +30 -6
- data/lib/twb.rb +1 -1
- metadata +3 -1
data/LICENSE.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
## Header
|
@@ -69,7 +69,6 @@ module Util
|
|
69
69
|
|
70
70
|
def initDot
|
71
71
|
@dotFileName = @workbook.name + '.dot'
|
72
|
-
# @dotFileName = gsub(/ /,'_')
|
73
72
|
@dotFile = File.open(@dotFileName,'w')
|
74
73
|
@dotFile.puts @@dotHeader
|
75
74
|
end
|
@@ -110,7 +109,6 @@ module Util
|
|
110
109
|
|
111
110
|
def closeDot
|
112
111
|
@dotFile.puts ' '
|
113
|
-
#@dotFile.puts '// -------------------------------------------------------------'
|
114
112
|
@dotFile.puts '}'
|
115
113
|
@dotFile.close
|
116
114
|
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# Copyright (C) 2012, 2015 Chris Gerrard
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module Twb
|
17
|
+
module Util
|
18
|
+
|
19
|
+
class TwbDashesSheetDataDotBuilder
|
20
|
+
|
21
|
+
@@dotHeader = <<-DOTHEADER
|
22
|
+
digraph g {
|
23
|
+
graph [rankdir="LR" splines="line"];
|
24
|
+
node [shape="box" width="2"];
|
25
|
+
|
26
|
+
"Tableau Tools generated Workbook map" [color="white" border="0"];
|
27
|
+
DOTHEADER
|
28
|
+
|
29
|
+
@@dotFooter = <<-DOTFOOTER
|
30
|
+
}
|
31
|
+
|
32
|
+
subgraph cluster_0 {
|
33
|
+
color=white;
|
34
|
+
node [shape="box3d" style="filled" ];
|
35
|
+
"Workbook" -> "Dashboard" -> "Worksheet" -> "Data Source"
|
36
|
+
"Workbook" "Dashboard";
|
37
|
+
"Worksheet";
|
38
|
+
"Data Source";
|
39
|
+
}
|
40
|
+
|
41
|
+
}
|
42
|
+
DOTFOOTER
|
43
|
+
|
44
|
+
attr_reader :workbook, :dotFile, :dotFileName, :dashCount, :sheetCount, :dataSourceCount
|
45
|
+
|
46
|
+
def initialize twb
|
47
|
+
@workbook = if twb.instance_of?(Twb::Workbook)
|
48
|
+
then twb
|
49
|
+
else Twb::Workbook.new(twb)
|
50
|
+
end
|
51
|
+
@dashCount = @workbook.dashboards.length
|
52
|
+
@worksheets = @workbook.worksheetNames
|
53
|
+
@sheetCount = @worksheets.length
|
54
|
+
@datasources = @workbook.datasourceUINames
|
55
|
+
@dataSourceCount = @datasources.length
|
56
|
+
pairs = processDashboards
|
57
|
+
pairs += processWorksheets
|
58
|
+
pairs += processOrphans
|
59
|
+
initDot
|
60
|
+
buildBody(pairs)
|
61
|
+
sameRank([@workbook.name] )
|
62
|
+
sameRank( @workbook.dashboardNames )
|
63
|
+
sameRank( @workbook.worksheetNames )
|
64
|
+
sameRank( @workbook.datasourceNames )
|
65
|
+
buildHeader
|
66
|
+
labelDataSources
|
67
|
+
closeDot
|
68
|
+
end
|
69
|
+
|
70
|
+
def initDot
|
71
|
+
@dotFileName = @workbook.name + '.dot'
|
72
|
+
@dotFile = File.open(@dotFileName,'w')
|
73
|
+
@dotFile.puts @@dotHeader
|
74
|
+
end
|
75
|
+
|
76
|
+
def buildBody(pairs)
|
77
|
+
@dotFile.puts "\n subgraph cluster_1 {"
|
78
|
+
@dotFile.puts " color= grey;"
|
79
|
+
@dotFile.puts ""
|
80
|
+
pairs.each { |pair| @dotFile.puts " \"#{pair[0]}\" -> \"#{pair[1]}\" " }
|
81
|
+
@dotFile.puts ""
|
82
|
+
@dotFile.puts " }"
|
83
|
+
end
|
84
|
+
|
85
|
+
def sameRank(elements)
|
86
|
+
@dotFile.puts "\n {rank=same "
|
87
|
+
elements.each do |e|
|
88
|
+
@dotFile.puts " \"#{e}\""
|
89
|
+
end
|
90
|
+
@dotFile.puts " }"
|
91
|
+
end
|
92
|
+
|
93
|
+
def buildHeader
|
94
|
+
@dotFile.puts ''
|
95
|
+
@dotFile.puts ' subgraph cluster_0 {'
|
96
|
+
@dotFile.puts ' color=white;'
|
97
|
+
@dotFile.puts ' node [shape="box3d" style="filled" ];'
|
98
|
+
@dotFile.puts ' "Workbook" -> "Dashboard" -> "Worksheet" -> "Data Source"'
|
99
|
+
@dotFile.puts ' }'
|
100
|
+
end
|
101
|
+
|
102
|
+
def labelDataSources
|
103
|
+
@dotFile.puts " "
|
104
|
+
@workbook.datasources.each do |ds|
|
105
|
+
name = ds.name
|
106
|
+
@dotFile.puts " \"#{name}\" [label=\"#{ds.uiname}\"];"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def closeDot
|
111
|
+
@dotFile.puts ' '
|
112
|
+
@dotFile.puts '}'
|
113
|
+
@dotFile.close
|
114
|
+
end
|
115
|
+
|
116
|
+
def processDashboards
|
117
|
+
pairs = []
|
118
|
+
@workbook.dashboards.each do |dash|
|
119
|
+
dashName = dash.name
|
120
|
+
pairs << [@workbook.name,dashName]
|
121
|
+
dash.worksheets.each do |sheet|
|
122
|
+
sheetName = sheet.name
|
123
|
+
pairs << [dashName,sheetName]
|
124
|
+
@worksheets.delete sheetName
|
125
|
+
end
|
126
|
+
end
|
127
|
+
return pairs
|
128
|
+
end
|
129
|
+
|
130
|
+
def processWorksheets
|
131
|
+
pairs = []
|
132
|
+
@workbook.worksheets.each do |sheet|
|
133
|
+
sheetName = sheet.name
|
134
|
+
sheet.datasources.each do |ds|
|
135
|
+
dsName = ds.name
|
136
|
+
pairs << [sheetName,ds.name]
|
137
|
+
@datasources.delete ds.uiname
|
138
|
+
end
|
139
|
+
end
|
140
|
+
return pairs
|
141
|
+
end
|
142
|
+
|
143
|
+
def processOrphans
|
144
|
+
pairs = []
|
145
|
+
@datasources.each { |dsn| pairs << [@workbook.name,dsn] }
|
146
|
+
@worksheets.each { |wsn| pairs << [@workbook.name,wsn] }
|
147
|
+
return pairs
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
data/lib/twb/workbook.rb
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
16
|
require 'nokogiri'
|
17
|
+
require 'zip'
|
17
18
|
|
18
19
|
module Twb
|
19
20
|
|
@@ -22,7 +23,8 @@ module Twb
|
|
22
23
|
#
|
23
24
|
class Workbook
|
24
25
|
|
25
|
-
attr_reader :workbooknode, :name,
|
26
|
+
attr_reader :workbooknode, :name, :dir, :modtime, :version, :build
|
27
|
+
attr_reader :datasources, :dashboards, :storyboards, :worksheets, :valid, :ndoc
|
26
28
|
|
27
29
|
# Creates a Workbook, from its file name.
|
28
30
|
#
|
@@ -31,10 +33,32 @@ module Twb
|
|
31
33
|
# The Workbook's file name
|
32
34
|
#
|
33
35
|
def initialize twbWithDir
|
34
|
-
@
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
@valid = false
|
37
|
+
if File.file?(twbWithDir) then
|
38
|
+
@name = File.basename(twbWithDir)
|
39
|
+
@dir = File.dirname(File.expand_path(twbWithDir))
|
40
|
+
@modtime = File.new(twbWithDir).mtime.strftime("%Y-%m-%d %H:%M:%S")
|
41
|
+
case File.extname(twbWithDir)
|
42
|
+
when '.twb' then processTWB(twbWithDir)
|
43
|
+
when '.twbx' then processTWBX(twbWithDir)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def processTWBX(twbxWithDir)
|
49
|
+
Zip::File.open(twbxWithDir) do |zip_file|
|
50
|
+
twb = zip_file.glob('*.twb').first
|
51
|
+
@ndoc = Nokogiri::XML(twb.get_input_stream)
|
52
|
+
processDoc
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def processTWB(twbFile)
|
57
|
+
@ndoc = Nokogiri::XML(open(twbFile))
|
58
|
+
processDoc
|
59
|
+
end
|
60
|
+
|
61
|
+
def processDoc
|
38
62
|
@workbooknode = @ndoc.at_xpath('//workbook')
|
39
63
|
@version = @ndoc.xpath('/workbook/@version')
|
40
64
|
@build = @ndoc.xpath('/workbook/comment()').text.gsub(/^[^0-9]+/,'').strip
|
@@ -43,7 +67,7 @@ module Twb
|
|
43
67
|
loadDashboards
|
44
68
|
loadStoryboards
|
45
69
|
loadWindows
|
46
|
-
|
70
|
+
@valid = true
|
47
71
|
end
|
48
72
|
|
49
73
|
def loaddatasources
|
data/lib/twb.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/twb/util/dotFileRenderer.rb
|
38
38
|
- lib/twb/util/hashtohtml.rb
|
39
39
|
- lib/twb/util/htmllistcollapsible.rb
|
40
|
+
- lib/twb/util/twbDashesSheetDataDotBuilder.rb
|
40
41
|
- lib/twb/util/twbDashSheetDataDotBuilder.rb
|
41
42
|
- lib/twb/util/twbDashSheetDataDotRenderer.rb
|
42
43
|
- lib/twb/util/xraydashboards.rb
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- test/testTwbDashSheetDataDotBuilder.rb
|
56
57
|
- test/testTwbGem.rb
|
57
58
|
- test/testTwbWrite.rb
|
59
|
+
- LICENSE.md
|
58
60
|
- README.md
|
59
61
|
- lib/twb/dashboard.txt
|
60
62
|
- LICENSE.txt
|