twb 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/twb/dashboard.rb CHANGED
@@ -45,7 +45,7 @@ module Twb
45
45
  end
46
46
 
47
47
  def worksheets
48
- @sheets
48
+ @sheets.values
49
49
  end
50
50
 
51
51
  def worksheetNames
@@ -73,13 +73,21 @@ module Twb
73
73
  def processFields
74
74
  # --
75
75
  @localfields = {}
76
- nodes = @node.xpath("./connection/relation/columns/column")
76
+ @metadatafields = {}
77
+ return if @connection.nil?
78
+ ## load local fields
79
+ connClass = @node.at_xpath('./connection').attribute('class').text
80
+ fxpath = case connClass
81
+ when 'dataengine' then './column'
82
+ else './connection/relation/columns/column'
83
+ end
84
+ nodes = @node.xpath(fxpath)
85
+ # puts "DATASOURCE ::=>> @node: connClass: '#{connClass.class}' ::: #{connClass.eql?('dataengine')} fxpath: #{fxpath} :: #{nodes.length}"
77
86
  nodes.each do |node|
78
87
  field = Twb::LocalField.new(node)
79
88
  @localfields[field.name] = field
80
89
  end
81
- # --
82
- @metadatafields = {}
90
+ ## load metadata fields
83
91
  nodes = @node.xpath("./connection/metadata-records/metadata-record[@class='column']")
84
92
  # note: there are other nodes "<metadata-record class='capability'>" whose nature is unclear
85
93
  # these nodes have no value for their <name node, so we're not loading them
@@ -91,4 +99,4 @@ module Twb
91
99
 
92
100
  end
93
101
 
94
- end
102
+ end
@@ -59,7 +59,7 @@ module Util
59
59
  initDot
60
60
  buildBody(pairs)
61
61
  sameRank([@workbook.name] )
62
- sameRank( @workbook.dashboards.keys )
62
+ sameRank( @workbook.dashboardNames )
63
63
  sameRank( @workbook.worksheetNames )
64
64
  sameRank( @workbook.datasourceNames )
65
65
  buildHeader
@@ -99,11 +99,11 @@ module Util
99
99
  @dotFile.puts ' "Workbook" -> "Dashboard" -> "Worksheet" -> "Data Source"'
100
100
  @dotFile.puts ' }'
101
101
  end
102
-
102
+
103
103
  def labelDataSources
104
104
  @dotFile.puts " "
105
- dataSources = @workbook.datasources
106
- dataSources.each do |name,ds|
105
+ @workbook.datasources.each do |ds|
106
+ name = ds.name
107
107
  @dotFile.puts " \"#{name}\" [label=\"#{ds.uiname}\"];"
108
108
  end
109
109
  end
@@ -117,10 +117,11 @@ module Util
117
117
 
118
118
  def processDashboards
119
119
  pairs = []
120
- @workbook.dashboards.each do |dashName,dash|
120
+ @workbook.dashboards.each do |dash|
121
+ dashName = dash.name
121
122
  pairs << [@workbook.name,dashName]
122
- sheets = dash.worksheets
123
- sheets.each do |sheetName,sheet|
123
+ dash.worksheets.each do |sheet|
124
+ sheetName = sheet.name
124
125
  pairs << [dashName,sheetName]
125
126
  @worksheets.delete sheetName
126
127
  end
@@ -130,11 +131,11 @@ module Util
130
131
 
131
132
  def processWorksheets
132
133
  pairs = []
133
- worksheets = @workbook.worksheets
134
- worksheets.each do |sheetName,sheet|
135
- datasources = sheet.datasources
136
- datasources.each do |dsName,ds|
137
- pairs << [sheetName,ds.name]
134
+ @workbook.worksheets.each do |sheet|
135
+ sheetName = sheet.name
136
+ sheet.datasources.each do |ds|
137
+ dsName = ds.name
138
+ pairs << [sheetName,ds.name]
138
139
  @datasources.delete ds.uiname
139
140
  end
140
141
  end
data/lib/twb/workbook.rb CHANGED
@@ -48,13 +48,12 @@ module Twb
48
48
 
49
49
  def loaddatasources
50
50
  @dataSourcesNode = @ndoc.at_xpath('//workbook/datasources')
51
- @datasources = {}
51
+ @datasources = {}
52
52
  @datasourceNodes = @ndoc.xpath('//workbook/datasources/datasource').to_a
53
53
  @datasourceNodes.each do |node|
54
54
  datasource = Twb::DataSource.new(node)
55
55
  @datasources[datasource.name] = datasource
56
56
  end
57
- return true
58
57
  end
59
58
 
60
59
  def loadWorksheets
@@ -99,19 +98,19 @@ module Twb
99
98
 
100
99
 
101
100
  def datasources
102
- @datasources
101
+ @datasources.values
103
102
  end
104
103
 
105
104
  def dashboards
106
- @dashboards
105
+ @dashboards.values
107
106
  end
108
107
 
109
108
  def storyboards
110
- @storyboards
109
+ @storyboards.values
111
110
  end
112
111
 
113
112
  def worksheets
114
- @worksheets
113
+ @worksheets.values
115
114
  end
116
115
 
117
116
  def datasourceNames
@@ -151,7 +150,7 @@ module Twb
151
150
  def worksheet name
152
151
  @worksheets[name]
153
152
  end
154
-
153
+
155
154
  # Make sure that the TWB has a <dashboards> node.
156
155
  # It's possible for a TWB to have no dashboards, and therefore no <dashboards> node.
157
156
  def ensureDashboardsNodeExists
@@ -178,9 +177,9 @@ module Twb
178
177
  title = getNewDashboardTitle(docDashboard.title)
179
178
  docDashboard.title=(title) unless title == docDashboard.title
180
179
  @dashesNode.add_child(docDashboard.dashnode)
181
- @windowsnode.add_child(docDashboard.winnode)
180
+ @windowsnode.add_child(docDashboard.winnode)
182
181
  end
183
-
182
+
184
183
  def getNewDashboardTitle(t)
185
184
  title = t
186
185
  if @datasources.include?(title)
@@ -206,7 +205,7 @@ module Twb
206
205
  end
207
206
  return name
208
207
  end
209
-
208
+
210
209
  # Write the TWB to a file, appending the base name with the provided string.
211
210
  # Intended for use when making adjustments to the TWB without overwriting the original.
212
211
  def writeAppend(str)
@@ -216,4 +215,4 @@ module Twb
216
215
 
217
216
  end
218
217
 
219
- end
218
+ end
data/lib/twb/worksheet.rb CHANGED
@@ -51,7 +51,11 @@ module Twb
51
51
  end
52
52
 
53
53
  def datasources
54
- @datasources
54
+ @datasources.values
55
+ end
56
+
57
+ def datasource name
58
+ @datasources[name]
55
59
  end
56
60
 
57
61
  def datasourcenames
@@ -60,4 +64,4 @@ module Twb
60
64
 
61
65
  end
62
66
 
63
- end
67
+ end
data/lib/twb.rb CHANGED
@@ -33,6 +33,5 @@ require_relative 'twb/util/xraydashboards'
33
33
  # Represents Tableau Workbooks and their contents.
34
34
  #
35
35
  module Twb
36
- VERSION = '0.3.4'
36
+ VERSION = '0.4.0'
37
37
  end
38
-
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.3.4
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: