Class: Twb::ColumnField

Inherits:
TabClass show all
Includes:
Comparable
Defined in:
lib/twb/columnfield.rb

Constant Summary collapse

@@dataTypeRoleMap =
{
  'date'     => :dimension,
  'datetime' => :dimension, 
  'boolean'  => :dimension,
  'integer'  => :measure,
  'float'    => :measure,
  'real'     => :measure,
  'string'   => :dimension,
}

Instance Attribute Summary collapse

Attributes inherited from TabClass

#ttlogfile, #ttlogfilename, #uuid

Instance Method Summary collapse

Methods inherited from TabClass

#docFile, #emit, #setDocFileName

Constructor Details

#initialize(fieldNode, datasource = nil) ⇒ ColumnField

Returns a new instance of ColumnField.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/twb/columnfield.rb', line 71

def initialize(fieldNode, datasource=nil)
  @datasource         = datasource
  @node               = fieldNode
  @name               = load 'name'
  @caption            = load 'caption'
  @uiname             = @caption.nil? ? @name : @caption
  @dataType           = load 'datatype'
  @userDataType       = load 'user-datatype'
  @defaultFormat      = load 'default-format'
  @paramDomainType    = load 'param-domain-type'
  @type               = load 'type'
  @value              = load 'value'
  @alias              = load 'alias'
  @semanticRole       = load 'semantic-role'
  @aggregation        = load 'aggregation'
  @autoColumn         = load 'auto-column'
  @datatypeCustomized = load 'datatype-customized'
  # @calcField          = loadCalcField
end

Instance Attribute Details

#aggregationObject (readonly)

Returns the value of attribute aggregation.



65
66
67
# File 'lib/twb/columnfield.rb', line 65

def aggregation
  @aggregation
end

#aliasObject (readonly)

Returns the value of attribute alias.



62
63
64
# File 'lib/twb/columnfield.rb', line 62

def alias
  @alias
end

#aliasesObject (readonly)

Returns the value of attribute aliases.



69
70
71
# File 'lib/twb/columnfield.rb', line 69

def aliases
  @aliases
end

#autoColumnObject (readonly)

Returns the value of attribute autoColumn.



66
67
68
# File 'lib/twb/columnfield.rb', line 66

def autoColumn
  @autoColumn
end

#calcFieldObject (readonly)

Returns the value of attribute calcField.



67
68
69
# File 'lib/twb/columnfield.rb', line 67

def calcField
  @calcField
end

#captionObject (readonly)

Returns the value of attribute caption.



61
62
63
# File 'lib/twb/columnfield.rb', line 61

def caption
  @caption
end

#dataTypeObject (readonly)

Returns the value of attribute dataType.



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

def dataType
  @dataType
end

#datatypeCustomizedObject (readonly)

Returns the value of attribute datatypeCustomized.



66
67
68
# File 'lib/twb/columnfield.rb', line 66

def datatypeCustomized
  @datatypeCustomized
end

#defaultFormatObject (readonly)

Returns the value of attribute defaultFormat.



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

def defaultFormat
  @defaultFormat
end

#hasaliasesObject (readonly)

Returns the value of attribute hasaliases.



62
63
64
# File 'lib/twb/columnfield.rb', line 62

def hasaliases
  @hasaliases
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



66
67
68
# File 'lib/twb/columnfield.rb', line 66

def hidden
  @hidden
end

#nameObject (readonly)

Returns the value of attribute name.



61
62
63
# File 'lib/twb/columnfield.rb', line 61

def name
  @name
end

#nodeObject (readonly)

XML Attributes known to exist in TWB xml


aggregation aggregation-param alias auto-column caption datatype datatype-customized default-format default-role default-type hidden layered name param-domain-type pivot role semantic-role SplitFieldIndex SplitFieldOrigin type user-datatype value visual-totals



60
61
62
# File 'lib/twb/columnfield.rb', line 60

def node
  @node
end

#paramDomainTypeObject (readonly)

Returns the value of attribute paramDomainType.



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

def paramDomainType
  @paramDomainType
end

#pathObject (readonly)

Returns the value of attribute path.



68
69
70
# File 'lib/twb/columnfield.rb', line 68

def path
  @path
end

#propertiesObject (readonly)

XML Attributes known to exist in TWB xml


aggregation aggregation-param alias auto-column caption datatype datatype-customized default-format default-role default-type hidden layered name param-domain-type pivot role semantic-role SplitFieldIndex SplitFieldOrigin type user-datatype value visual-totals



60
61
62
# File 'lib/twb/columnfield.rb', line 60

def properties
  @properties
end

#roleObject (readonly)

Returns the value of attribute role.



64
65
66
# File 'lib/twb/columnfield.rb', line 64

def role
  @role
end

#semanticRoleObject (readonly)

Returns the value of attribute semanticRole.



65
66
67
# File 'lib/twb/columnfield.rb', line 65

def semanticRole
  @semanticRole
end

#typeObject (readonly)

Returns the value of attribute type.



64
65
66
# File 'lib/twb/columnfield.rb', line 64

def type
  @type
end

#uinameObject (readonly)

Returns the value of attribute uiname.



61
62
63
# File 'lib/twb/columnfield.rb', line 61

def uiname
  @uiname
end

#valueObject (readonly)

Returns the value of attribute value.



64
65
66
# File 'lib/twb/columnfield.rb', line 64

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



226
227
228
# File 'lib/twb/columnfield.rb', line 226

def <=>(other)
  @name <=> other.name
end

#commentObject



137
138
139
# File 'lib/twb/columnfield.rb', line 137

def comment
  @commentLines ||= loadComment
end

#hasComment?Boolean

Returns:

  • (Boolean)


189
190
191
192
# File 'lib/twb/columnfield.rb', line 189

def hasComment?
  loadComment if @commentLines.nil?
  @commentLines.empty?
end

#idObject



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

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

#load(nodeName) ⇒ Object



95
96
97
98
99
# File 'lib/twb/columnfield.rb', line 95

def load nodeName
  attr = @node.attribute(nodeName)
  val  = attr.nil? ? nil : attr.text.strip.gsub(/^\[|\]$/,'')
  return val
end

#loadAliasesObject



149
150
151
152
153
154
155
156
157
158
# File 'lib/twb/columnfield.rb', line 149

def loadAliases
  @aliases = {}
  if hasaliases
    @node.at_xpath('./aliases//alias').each do |an|
      dbvalue = an['key'].to_s.gsub(/^["]+/,'').gsub(/["]+$/,'')
      @aliases[ dbvalue ] = an['value']
    end
  end
  return @aliases
end

#loadCalcFieldObject



121
122
123
124
125
126
127
# File 'lib/twb/columnfield.rb', line 121

def loadCalcField
  if !@node.at_xpath('./calculation').nil?
    @calcField = Twb::CalculatedField.new @node, @datasource
  else 
    @calcField = nil
  end
end

#loadCommentObject

COMMENTED FIELDS


<column caption=‘Calculation1’ datatype=‘real’ name=‘’ role=‘measure’ type=‘quantitative’>

<calculation class='tableau' formula='[Formula Length] * 1.1' />
<desc>
  <formatted-text>
    <run>THIS IS A COMMENT</run>
  </formatted-text>
</desc>

</column> <column datatype=‘string’ name=‘[Data Source Name (tech) (CalculatedFieldsReferencedFields.csv)]’ role=‘dimension’ type=‘nominal’>

<desc>
  <formatted-text>
    <run>THIS IS A COMMENT</run>
  </formatted-text>
</desc>

</column>



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/twb/columnfield.rb', line 177

def loadComment
  @commentLines = []
  runs = @node.xpath('./desc/formatted-text/run')
  runs.each do |run|
    lines = run.text.split(/\n/)
    lines.each do |line|
      @commentLines << line
    end
  end
  return @commentLines
end

#loadPropertiesObject



213
214
215
216
217
218
219
220
# File 'lib/twb/columnfield.rb', line 213

def loadProperties
  @properties= {}
  @node.attributes.each do |name,attr|
    @properties[name] = attr.value
  end
  @properties[:uiname] = @name
  return @properties
end

#loadRoleObject



105
106
107
108
109
110
111
# File 'lib/twb/columnfield.rb', line 105

def loadRole
  role = @node['role']
  if role.nil? 
    role = @@dataTypeRoleMap[@dataType].nil? ? @dataType : @@dataTypeRoleMap[@dataType]
  end
  return role
end

#pathbareObject



133
134
135
# File 'lib/twb/columnfield.rb', line 133

def pathbare
  @pathbare ||= path().gsub(/\[\]/,'')
end

#to_sObject



222
223
224
# File 'lib/twb/columnfield.rb', line 222

def to_s
  @name
end