Class: Twb::Worksheet

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/worksheet.rb

Constant Summary collapse

@@hasher =
Digest::SHA256.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sheetNode) ⇒ Worksheet

Returns a new instance of Worksheet.



29
30
31
32
33
34
35
# File 'lib/twb/worksheet.rb', line 29

def initialize sheetNode
  @node    = sheetNode
  @name    = @node.attr('name')
  loadDataSourceNames
  loadFields
  return self
end

Instance Attribute Details

#colFieldsObject (readonly)

Returns the value of attribute colFields.



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

def colFields
  @colFields
end

#datasourceFieldsObject (readonly)

Returns the value of attribute datasourceFields.



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

def datasourceFields
  @datasourceFields
end

#datasourcenamesObject (readonly)

Returns the value of attribute datasourcenames.



25
26
27
# File 'lib/twb/worksheet.rb', line 25

def datasourcenames
  @datasourcenames
end

#datasourcesObject (readonly)

Returns the value of attribute datasources.



25
26
27
# File 'lib/twb/worksheet.rb', line 25

def datasources
  @datasources
end

#fieldsObject (readonly)

Returns the value of attribute fields.



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

def fields
  @fields
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/twb/worksheet.rb', line 25

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



25
26
27
# File 'lib/twb/worksheet.rb', line 25

def node
  @node
end

#paneFieldsObject (readonly)

Returns the value of attribute paneFields.



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

def paneFields
  @paneFields
end

#panesCountObject (readonly)

Returns the value of attribute panesCount.



26
27
28
# File 'lib/twb/worksheet.rb', line 26

def panesCount
  @panesCount
end

#rowFieldsObject (readonly)

Returns the value of attribute rowFields.



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

def rowFields
  @rowFields
end

Instance Method Details

#addDSFields(fields, usage) ⇒ Object



85
86
87
88
# File 'lib/twb/worksheet.rb', line 85

def addDSFields fields, usage
  fields.each do  
  end
end

#datasource(name) ⇒ Object



50
51
52
# File 'lib/twb/worksheet.rb', line 50

def datasource name
  @datasources[name]
end

#loadDataSourceNamesObject



37
38
39
40
41
42
43
44
# File 'lib/twb/worksheet.rb', line 37

def loadDataSourceNames
  @datasources = {}
  dsNodes = @node.xpath('.//datasource')
  dsNodes.each do |dsn|
    ds = WorksheetDataSource.new dsn
    @datasources[ds.name] = ds
  end
end

#loadFieldsObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/twb/worksheet.rb', line 63

def loadFields
  # puts "WORKSHEET loadFields"
  @fields = {}
  @datasourceFields = {}
  dsNodes = @node.xpath('.//datasource-dependencies')
  dsNodes.each do |dsn|
    dsName     = dsn.attribute('datasource').text
    dsFields   = @datasourceFields[dsName] = Set.new
    fieldNodes = dsn.xpath('./column')
    fieldNodes.each do |fn|
      dsFields.add WorksheetField.new fn, dsName
    end
  end
  @fields[:dsfields] = @datasourceFields
  # <rows>([DATA Connection (copy 2)].[none:JIRA HARVEST Correspondence  Name:nk] / [DATA Connection (copy 2)].[none:CreatedDate (Issue) (DAY):ok])</rows>
  # <cols>[DATA Connection (copy 2)].[:Measure Names]</cols>
  @rowFields     ||= loadRowColFields(:rows) # returns map of data source => (Set of) field names
  @fields[:rows]   = @rowFields
  @colFields     ||= loadRowColFields(:cols) # returns map of data source => (Set of) field names
  @fields[:cols]   = @colFields
end

#loadPaneFieldsObject



112
113
114
115
# File 'lib/twb/worksheet.rb', line 112

def loadPaneFields
  @paneFields = Set.new
  panes = @node.xpath('.//pane')
end

#loadRowColFields(type) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/twb/worksheet.rb', line 94

def loadRowColFields(type)
  fields = []
  xpath = case type
    when :rows then './/rows'
    when :cols then './/cols'
  end
  return fields if xpath.nil?
  node = @node.at_xpath(xpath)
  RowsColsSplitter.new(node).fields.each do |fcode|
    fields << CodedField.new(fcode)
  end
  return fields
end