Class: Twb::Workbook

Inherits:
TabClass show all
Defined in:
lib/twb/workbook.rb

Overview

A Tableau Workbook and its parts.

Instance Attribute Summary collapse

Attributes inherited from TabClass

#properties, #ttlogfile, #ttlogfilename, #uuid

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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.expand_path(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

#actionsObject (readonly)

Returns the value of attribute actions.



36
37
38
# File 'lib/twb/workbook.rb', line 36

def actions
  @actions
end

#baseObject (readonly)

Returns the value of attribute base.



29
30
31
# File 'lib/twb/workbook.rb', line 29

def base
  @base
end

#buildObject (readonly)

Returns the value of attribute build.



29
30
31
# File 'lib/twb/workbook.rb', line 29

def build
  @build
end

#dashboardsObject (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

#datasourceNamesObject (readonly)

Returns the value of attribute datasourceNames.



32
33
34
# File 'lib/twb/workbook.rb', line 32

def datasourceNames
  @datasourceNames
end

#dataSourceNamesMapObject (readonly)

Returns the value of attribute dataSourceNamesMap.



32
33
34
# File 'lib/twb/workbook.rb', line 32

def dataSourceNamesMap
  @dataSourceNamesMap
end

#datasourcesObject (readonly)



31
32
33
# File 'lib/twb/workbook.rb', line 31

def datasources
  @datasources
end

#datasourceUINamesObject (readonly)

Returns the value of attribute datasourceUINames.



32
33
34
# File 'lib/twb/workbook.rb', line 32

def datasourceUINames
  @datasourceUINames
end

#dirObject (readonly)

Returns the value of attribute dir.



28
29
30
# File 'lib/twb/workbook.rb', line 28

def dir
  @dir
end

#modtimeObject (readonly)

Returns the value of attribute modtime.



28
29
30
# File 'lib/twb/workbook.rb', line 28

def modtime
  @modtime
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/twb/workbook.rb', line 28

def name
  @name
end

#ndocObject (readonly)

Returns the value of attribute ndoc.



27
28
29
# File 'lib/twb/workbook.rb', line 27

def ndoc
  @ndoc
end

#nodeObject (readonly)

Returns the value of attribute node.



27
28
29
# File 'lib/twb/workbook.rb', line 27

def node
  @node
end

#orphanDataSourcesObject (readonly)

i.e. not referenced in any Worksheet



33
34
35
# File 'lib/twb/workbook.rb', line 33

def orphanDataSources
  @orphanDataSources
end

#parametersObject (readonly)

Returns the value of attribute parameters.



36
37
38
# File 'lib/twb/workbook.rb', line 36

def parameters
  @parameters
end

#platformObject (readonly)

Returns the value of attribute platform.



29
30
31
# File 'lib/twb/workbook.rb', line 29

def platform
  @platform
end

#storyboardsObject (readonly)



35
36
37
# File 'lib/twb/workbook.rb', line 35

def storyboards
  @storyboards
end

#typeObject (readonly)

Returns the value of attribute type.



28
29
30
# File 'lib/twb/workbook.rb', line 28

def type
  @type
end

#validObject (readonly)

Returns the value of attribute valid.



37
38
39
# File 'lib/twb/workbook.rb', line 37

def valid
  @valid
end

#versionObject (readonly)

Returns the value of attribute version.



29
30
31
# File 'lib/twb/workbook.rb', line 29

def version
  @version
end

#workbooknodeObject (readonly)

Returns the value of attribute workbooknode.



27
28
29
# File 'lib/twb/workbook.rb', line 27

def workbooknode
  @workbooknode
end

#worksheetsObject (readonly)



35
36
37
# File 'lib/twb/workbook.rb', line 35

def worksheets
  @worksheets
end

Instance Method Details

#actionNamesObject



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

#dashboardNamesObject



91
92
93
# File 'lib/twb/workbook.rb', line 91

def dashboardNames
  @dashboards.keys
end

#idObject



63
64
65
# File 'lib/twb/workbook.rb', line 63

def id
    @id ||= @id = @name.hash
end

#releaseObject



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

#storyboardNamesObject



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

#worksheetNamesObject



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