Class: Twb::Workbook
Overview
A Tableau Workbook and its parts.
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#dashboards ⇒ Object
readonly
–.
-
#datasource(name) ⇒ Object
readonly
–.
-
#datasourceNames ⇒ Object
readonly
Returns the value of attribute datasourceNames.
-
#dataSourceNamesMap ⇒ Object
readonly
Returns the value of attribute dataSourceNamesMap.
-
#datasources ⇒ Object
readonly
–.
-
#datasourceUINames ⇒ Object
readonly
Returns the value of attribute datasourceUINames.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#modtime ⇒ Object
readonly
Returns the value of attribute modtime.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ndoc ⇒ Object
readonly
Returns the value of attribute ndoc.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#orphanDataSources ⇒ Object
readonly
i.e.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#storyboards ⇒ Object
readonly
–.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#workbooknode ⇒ Object
readonly
Returns the value of attribute workbooknode.
-
#worksheets ⇒ Object
readonly
–.
Attributes inherited from TabClass
#properties, #ttlogfile, #ttlogfilename, #uuid
Instance Method Summary collapse
- #actionNames ⇒ Object
-
#addDocDashboard(docDashboard) ⇒ Object
Add a new Documentation Dashboard to the TWB.
- #dashboard(name) ⇒ Object
- #dashboardNames ⇒ Object
- #id ⇒ Object
-
#initialize(twbWithDir) ⇒ Workbook
constructor
Creates a Workbook from its file name.
- #release ⇒ Object
- #storyboard(name) ⇒ Object
- #storyboardNames ⇒ Object
- #worksheet(name) ⇒ Object
- #worksheetNames ⇒ Object
-
#write(name = @name) ⇒ Object
Write the TWB to a file, with an optional name.
-
#writeAppend(str) ⇒ Object
Write the TWB to a file, appending the base name with the provided string.
Methods inherited from TabClass
#docFile, #emit, #setDocFileName
Constructor Details
#initialize(twbWithDir) ⇒ Workbook
Creates a Workbook from its file name.
Parameters:
twbWithDir
The Workbook's file name, the Workbook can be a TWB or TWBX file.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/twb/workbook.rb', line 46 def initialize twbWithDir raise ArgumentError.new("ERROR in Workbok creation: '#{twbWithDir}' must be a String, is a #{twbWithDir.class} \n ") unless twbWithDir.is_a? String raise ArgumentError.new("ERROR in Workbok creation: '#{twbWithDir}' must have an extension of .twb or .twbx \n ") unless twbWithDir.upcase.end_with?(".TWB", ".TWBX") raise ArgumentError.new("ERROR in Workbok creation: '#{twbWithDir}' must must be a file, is a Directory\\Folder \n ") if File.directory?(twbWithDir) raise ArgumentError.new("ERROR in Workbok creation: '#{twbWithDir}' cannot be found, must be a Tableau Workbook file. \n ") unless File.file?(twbWithDir) @valid = false if File.file?(twbWithDir) then @name = File.basename(twbWithDir) @dir = File.dirname(File.(twbWithDir)) @modtime = File.new(twbWithDir).mtime.strftime("%Y-%m-%d %H:%M:%S") case File.extname(twbWithDir) when '.twb' then processTWB(twbWithDir) when '.twbx' then processTWBX(twbWithDir) end end end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
36 37 38 |
# File 'lib/twb/workbook.rb', line 36 def actions @actions end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
29 30 31 |
# File 'lib/twb/workbook.rb', line 29 def base @base end |
#build ⇒ Object (readonly)
Returns the value of attribute build.
29 30 31 |
# File 'lib/twb/workbook.rb', line 29 def build @build end |
#dashboards ⇒ Object (readonly)
–
35 36 37 |
# File 'lib/twb/workbook.rb', line 35 def dashboards @dashboards end |
#datasource(name) ⇒ Object (readonly)
–
31 32 33 |
# File 'lib/twb/workbook.rb', line 31 def datasource @datasource end |
#datasourceNames ⇒ Object (readonly)
Returns the value of attribute datasourceNames.
32 33 34 |
# File 'lib/twb/workbook.rb', line 32 def datasourceNames @datasourceNames end |
#dataSourceNamesMap ⇒ Object (readonly)
Returns the value of attribute dataSourceNamesMap.
32 33 34 |
# File 'lib/twb/workbook.rb', line 32 def dataSourceNamesMap @dataSourceNamesMap end |
#datasources ⇒ Object (readonly)
–
31 32 33 |
# File 'lib/twb/workbook.rb', line 31 def datasources @datasources end |
#datasourceUINames ⇒ Object (readonly)
Returns the value of attribute datasourceUINames.
32 33 34 |
# File 'lib/twb/workbook.rb', line 32 def datasourceUINames @datasourceUINames end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
28 29 30 |
# File 'lib/twb/workbook.rb', line 28 def dir @dir end |
#modtime ⇒ Object (readonly)
Returns the value of attribute modtime.
28 29 30 |
# File 'lib/twb/workbook.rb', line 28 def modtime @modtime end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/twb/workbook.rb', line 28 def name @name end |
#ndoc ⇒ Object (readonly)
Returns the value of attribute ndoc.
27 28 29 |
# File 'lib/twb/workbook.rb', line 27 def ndoc @ndoc end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
27 28 29 |
# File 'lib/twb/workbook.rb', line 27 def node @node end |
#orphanDataSources ⇒ Object (readonly)
i.e. not referenced in any Worksheet
33 34 35 |
# File 'lib/twb/workbook.rb', line 33 def orphanDataSources @orphanDataSources end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
36 37 38 |
# File 'lib/twb/workbook.rb', line 36 def parameters @parameters end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
29 30 31 |
# File 'lib/twb/workbook.rb', line 29 def platform @platform end |
#storyboards ⇒ Object (readonly)
–
35 36 37 |
# File 'lib/twb/workbook.rb', line 35 def storyboards @storyboards end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
28 29 30 |
# File 'lib/twb/workbook.rb', line 28 def type @type end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
37 38 39 |
# File 'lib/twb/workbook.rb', line 37 def valid @valid end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
29 30 31 |
# File 'lib/twb/workbook.rb', line 29 def version @version end |
#workbooknode ⇒ Object (readonly)
Returns the value of attribute workbooknode.
27 28 29 |
# File 'lib/twb/workbook.rb', line 27 def workbooknode @workbooknode end |
#worksheets ⇒ Object (readonly)
–
35 36 37 |
# File 'lib/twb/workbook.rb', line 35 def worksheets @worksheets end |
Instance Method Details
#actionNames ⇒ Object
103 104 105 |
# File 'lib/twb/workbook.rb', line 103 def actionNames @actions.keys end |
#addDocDashboard(docDashboard) ⇒ Object
Add a new Documentation Dashboard to the TWB. Ensure that the TWB has a <dashboards> node (it may not). Make sure that the new Doc Dashboard’s name doesn’t conflict with an existing Dashboard - increment the incoming name if necessary. Add Doc Dashboard’s <dashboard> and <window> nodes to the TWB; there’s always a <windows> node in the TWB.
135 136 137 138 139 140 141 142 |
# File 'lib/twb/workbook.rb', line 135 def addDocDashboard docDashboard ensureDashboardsNodeExists ensureWindowsNodeExists title = getNewDashboardTitle(docDashboard.title) docDashboard.title=(title) unless title == docDashboard.title @dashesNode.add_child(docDashboard.dashnode) @windowsnode.add_child(docDashboard.winnode) end |
#dashboard(name) ⇒ Object
95 96 97 |
# File 'lib/twb/workbook.rb', line 95 def dashboard name @dashboards[name] end |
#dashboardNames ⇒ Object
91 92 93 |
# File 'lib/twb/workbook.rb', line 91 def dashboardNames @dashboards.keys end |
#id ⇒ Object
63 64 65 |
# File 'lib/twb/workbook.rb', line 63 def id @id ||= @id = @name.hash end |
#release ⇒ Object
71 72 73 |
# File 'lib/twb/workbook.rb', line 71 def release @build ||= loadBuild end |
#storyboard(name) ⇒ Object
127 128 129 |
# File 'lib/twb/workbook.rb', line 127 def storyboard name @storyboards[name] end |
#storyboardNames ⇒ Object
123 124 125 |
# File 'lib/twb/workbook.rb', line 123 def storyboardNames @storyboards.keys end |
#worksheet(name) ⇒ Object
79 80 81 |
# File 'lib/twb/workbook.rb', line 79 def worksheet name @worksheets[name] end |
#worksheetNames ⇒ Object
83 84 85 |
# File 'lib/twb/workbook.rb', line 83 def worksheetNames @worksheets.keys end |
#write(name = @name) ⇒ Object
Write the TWB to a file, with an optional name. Can be used to write over the existing TWB (dangerous), or to a new file (preferred).
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/twb/workbook.rb', line 146 def write(name=@name) case @type when :twb writeTwb(name) when :twbx writeTwbx(name) else emit "Cannot write this Workbook - it has an invalid type: #{@type}" raise "Cannot write this Workbook - it has an invalid type: #{@type}" end end |
#writeAppend(str) ⇒ Object
Write the TWB to a file, appending the base name with the provided string. Intended for use when making adjustments to the TWB without overwriting the original.
160 161 162 163 |
# File 'lib/twb/workbook.rb', line 160 def writeAppend(str) newName = @name.sub(/[.]twb$/,'') + str.gsub(/^[.]*/,'.') + '.twb' write newName end |