Class: Twb::ColumnField

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fieldNode, datasource = nil) ⇒ ColumnField

Returns a new instance of ColumnField.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/twb/columnfield.rb', line 59

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'
  @role               = load 'role'
  @type               = load 'type'
  @value              = load 'value'
  @alias              = load 'alias'
  @semanticRole       = load 'semantic-role'
  @aggregation        = load 'aggregation'
  @autoColumn         = load 'auto-column'
  @hidden             = load 'hidden'
  @datatypeCustomized = load 'datatype-customized'
  @calcField          = loadCalcField
end

Instance Attribute Details

#aggregationObject (readonly)

Returns the value of attribute aggregation.



54
55
56
# File 'lib/twb/columnfield.rb', line 54

def aggregation
  @aggregation
end

#aliasObject (readonly)

Returns the value of attribute alias.



54
55
56
# File 'lib/twb/columnfield.rb', line 54

def alias
  @alias
end

#autoColumnObject (readonly)

Returns the value of attribute autoColumn.



55
56
57
# File 'lib/twb/columnfield.rb', line 55

def autoColumn
  @autoColumn
end

#calcFieldObject (readonly)

Returns the value of attribute calcField.



56
57
58
# File 'lib/twb/columnfield.rb', line 56

def calcField
  @calcField
end

#captionObject (readonly)

Returns the value of attribute caption.



51
52
53
# File 'lib/twb/columnfield.rb', line 51

def caption
  @caption
end

#dataTypeObject (readonly)

Returns the value of attribute dataType.



52
53
54
# File 'lib/twb/columnfield.rb', line 52

def dataType
  @dataType
end

#datatypeCustomizedObject (readonly)

Returns the value of attribute datatypeCustomized.



55
56
57
# File 'lib/twb/columnfield.rb', line 55

def datatypeCustomized
  @datatypeCustomized
end

#defaultFormatObject (readonly)

Returns the value of attribute defaultFormat.



52
53
54
# File 'lib/twb/columnfield.rb', line 52

def defaultFormat
  @defaultFormat
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



55
56
57
# File 'lib/twb/columnfield.rb', line 55

def hidden
  @hidden
end

#nameObject (readonly)

Returns the value of attribute name.



51
52
53
# File 'lib/twb/columnfield.rb', line 51

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



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

def node
  @node
end

#paramDomainTypeObject (readonly)

Returns the value of attribute paramDomainType.



52
53
54
# File 'lib/twb/columnfield.rb', line 52

def paramDomainType
  @paramDomainType
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



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

def properties
  @properties
end

#roleObject (readonly)

Returns the value of attribute role.



53
54
55
# File 'lib/twb/columnfield.rb', line 53

def role
  @role
end

#semanticRoleObject (readonly)

Returns the value of attribute semanticRole.



54
55
56
# File 'lib/twb/columnfield.rb', line 54

def semanticRole
  @semanticRole
end

#typeObject (readonly)

Returns the value of attribute type.



53
54
55
# File 'lib/twb/columnfield.rb', line 53

def type
  @type
end

#uinameObject (readonly)

Returns the value of attribute uiname.



51
52
53
# File 'lib/twb/columnfield.rb', line 51

def uiname
  @uiname
end

#valueObject (readonly)

Returns the value of attribute value.



53
54
55
# File 'lib/twb/columnfield.rb', line 53

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



155
156
157
# File 'lib/twb/columnfield.rb', line 155

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

#commentObject



100
101
102
# File 'lib/twb/columnfield.rb', line 100

def comment
  @commentLines ||= loadComment
end

#hasComment?Boolean

Returns:

  • (Boolean)


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

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

#load(nodeName) ⇒ Object



82
83
84
85
86
# File 'lib/twb/columnfield.rb', line 82

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

#loadCalcFieldObject



92
93
94
95
96
97
98
# File 'lib/twb/columnfield.rb', line 92

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>



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

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



142
143
144
145
146
147
148
149
# File 'lib/twb/columnfield.rb', line 142

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

#to_sObject



151
152
153
# File 'lib/twb/columnfield.rb', line 151

def to_s
  @name
end