Class: Twb::ColumnField
- 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
-
#aggregation ⇒ Object
readonly
Returns the value of attribute aggregation.
-
#alias ⇒ Object
readonly
Returns the value of attribute alias.
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#autoColumn ⇒ Object
readonly
Returns the value of attribute autoColumn.
-
#calcField ⇒ Object
readonly
def loadRole role = @node if role.nil? role = @@dataTypeRoleMap.nil? ? @dataType : @@dataTypeRoleMap end return role end.
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#dataType ⇒ Object
readonly
Returns the value of attribute dataType.
-
#datatypeCustomized ⇒ Object
readonly
Returns the value of attribute datatypeCustomized.
-
#defaultFormat ⇒ Object
readonly
Returns the value of attribute defaultFormat.
-
#hasaliases ⇒ Object
readonly
Returns the value of attribute hasaliases.
-
#hidden ⇒ Object
readonly
Returns the value of attribute hidden.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
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.
-
#paramDomainType ⇒ Object
readonly
Returns the value of attribute paramDomainType.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#properties ⇒ Object
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.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#semanticRole ⇒ Object
readonly
Returns the value of attribute semanticRole.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#uiname ⇒ Object
readonly
Returns the value of attribute uiname.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from TabClass
#ttlogfile, #ttlogfilename, #uuid
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #comment ⇒ Object
- #eql?(other) ⇒ Boolean
- #hasComment? ⇒ Boolean
- #hash ⇒ Object
- #id ⇒ Object
-
#initialize(fieldNode, datasource = nil) ⇒ ColumnField
constructor
A new instance of ColumnField.
- #load(nodeName) ⇒ Object
- #loadAliases ⇒ Object
- #loadAttributes(node) ⇒ Object
- #loadCalcField ⇒ Object
-
#loadComment ⇒ Object
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>.
- #loadProperties ⇒ Object
- #pathbare ⇒ Object
- #to_s ⇒ Object
Methods inherited from TabClass
#docFile, #emit, #setDocFileName
Constructor Details
#initialize(fieldNode, datasource = nil) ⇒ ColumnField
Returns a new instance of ColumnField.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/twb/columnfield.rb', line 73 def initialize(fieldNode, datasource=nil) @datasource = datasource @node = fieldNode @name = load('name').sub(/^\[/,'').sub(/\]$/,'') @caption = load 'caption' @uiname = @caption.nil? ? @name : @caption #-- loadAttributes @node # @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' end |
Instance Attribute Details
#aggregation ⇒ Object (readonly)
Returns the value of attribute aggregation.
67 68 69 |
# File 'lib/twb/columnfield.rb', line 67 def aggregation @aggregation end |
#alias ⇒ Object (readonly)
Returns the value of attribute alias.
63 64 65 |
# File 'lib/twb/columnfield.rb', line 63 def alias @alias end |
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
71 72 73 |
# File 'lib/twb/columnfield.rb', line 71 def aliases @aliases end |
#autoColumn ⇒ Object (readonly)
Returns the value of attribute autoColumn.
68 69 70 |
# File 'lib/twb/columnfield.rb', line 68 def autoColumn @autoColumn end |
#calcField ⇒ Object (readonly)
def loadRole
role = @node['role']
if role.nil?
role = @@dataTypeRoleMap[@dataType].nil? ? @dataType : @@dataTypeRoleMap[@dataType]
end
return role
end
155 156 157 |
# File 'lib/twb/columnfield.rb', line 155 def calcField @calcField end |
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
62 63 64 |
# File 'lib/twb/columnfield.rb', line 62 def @caption end |
#dataType ⇒ Object (readonly)
Returns the value of attribute dataType.
64 65 66 |
# File 'lib/twb/columnfield.rb', line 64 def dataType @dataType end |
#datatypeCustomized ⇒ Object (readonly)
Returns the value of attribute datatypeCustomized.
68 69 70 |
# File 'lib/twb/columnfield.rb', line 68 def datatypeCustomized @datatypeCustomized end |
#defaultFormat ⇒ Object (readonly)
Returns the value of attribute defaultFormat.
64 65 66 |
# File 'lib/twb/columnfield.rb', line 64 def defaultFormat @defaultFormat end |
#hasaliases ⇒ Object (readonly)
Returns the value of attribute hasaliases.
63 64 65 |
# File 'lib/twb/columnfield.rb', line 63 def hasaliases @hasaliases end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
68 69 70 |
# File 'lib/twb/columnfield.rb', line 68 def hidden @hidden end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
62 63 64 |
# File 'lib/twb/columnfield.rb', line 62 def name @name end |
#node ⇒ Object (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
61 62 63 |
# File 'lib/twb/columnfield.rb', line 61 def node @node end |
#paramDomainType ⇒ Object (readonly)
Returns the value of attribute paramDomainType.
64 65 66 |
# File 'lib/twb/columnfield.rb', line 64 def paramDomainType @paramDomainType end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
70 71 72 |
# File 'lib/twb/columnfield.rb', line 70 def path @path end |
#properties ⇒ Object (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
61 62 63 |
# File 'lib/twb/columnfield.rb', line 61 def properties @properties end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
65 66 67 |
# File 'lib/twb/columnfield.rb', line 65 def role @role end |
#semanticRole ⇒ Object (readonly)
Returns the value of attribute semanticRole.
65 66 67 |
# File 'lib/twb/columnfield.rb', line 65 def semanticRole @semanticRole end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
66 67 68 |
# File 'lib/twb/columnfield.rb', line 66 def type @type end |
#uiname ⇒ Object (readonly)
Returns the value of attribute uiname.
62 63 64 |
# File 'lib/twb/columnfield.rb', line 62 def uiname @uiname end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
66 67 68 |
# File 'lib/twb/columnfield.rb', line 66 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
268 269 270 |
# File 'lib/twb/columnfield.rb', line 268 def <=>(other) @name <=> other.name end |
#comment ⇒ Object
179 180 181 |
# File 'lib/twb/columnfield.rb', line 179 def comment @commentLines ||= loadComment end |
#eql?(other) ⇒ Boolean
272 273 274 |
# File 'lib/twb/columnfield.rb', line 272 def eql?(other) @name == other.name end |
#hasComment? ⇒ Boolean
231 232 233 234 |
# File 'lib/twb/columnfield.rb', line 231 def hasComment? loadComment if @commentLines.nil? @commentLines.empty? end |
#hash ⇒ Object
276 277 278 |
# File 'lib/twb/columnfield.rb', line 276 def hash @name.hash end |
#id ⇒ Object
94 95 96 |
# File 'lib/twb/columnfield.rb', line 94 def id @id ||= @id = @name.hash end |
#load(nodeName) ⇒ Object
98 99 100 101 102 |
# File 'lib/twb/columnfield.rb', line 98 def load nodeName attr = @node.attribute(nodeName) val = attr.nil? ? nil : attr.text.strip return val end |
#loadAliases ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/twb/columnfield.rb', line 191 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 |
#loadAttributes(node) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/twb/columnfield.rb', line 104 def loadAttributes node # puts "augmenting with node:#{node}" @node = node if node.has_attribute?('aggregation') then @aggregation = node['aggregation'] end if node.has_attribute?('alias') then @alias = node['alias'] end if node.has_attribute?('auto-column') then @autoColumn = node['auto-column'] end if node.has_attribute?('datatype') then @dataType = node['datatype'] end if node.has_attribute?('datatype-customized') then @datatypeCustomized = node['datatype-customized'] end if node.has_attribute?('default-format') then @defaultFormat = node['default-format'] end if node.has_attribute?('param-domain-type') then @paramDomainType = node['param-domain-type'] end if node.has_attribute?('role') then @role = node['role'] end if node.has_attribute?('semantic-role') then @semanticRole = node['semantic-role'] end if node.has_attribute?('type') then @type = node['type'] end if node.has_attribute?('user-datatype') then @userDataType = node['user-datatype'] end if node.has_attribute?('value') then @value = node['value'] end # loadAttr @aggregation, 'aggregation' # loadAttr @alias, 'alias' # loadAttr @autoColumn, 'auto-column' # loadAttr @dataType, 'datatype' # loadAttr @datatypeCustomized, 'datatype-customized' # loadAttr @defaultFormat, 'default-format' # loadAttr @paramDomainType, 'param-domain-type' # loadAttr @role, 'role' # loadAttr @semanticRole, 'semantic-role' # loadAttr @type, 'type' # loadAttr @userDataType, 'user-datatype' # loadAttr @value, 'value' end |
#loadCalcField ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/twb/columnfield.rb', line 163 def loadCalcField if !@node.at_xpath('./calculation').nil? @calcField = Twb::CalculatedField.new @node, @datasource else @calcField = nil end end |
#loadComment ⇒ Object
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>
219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/twb/columnfield.rb', line 219 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 |
#loadProperties ⇒ Object
255 256 257 258 259 260 261 262 |
# File 'lib/twb/columnfield.rb', line 255 def loadProperties @properties = {} if @properties.nil? @node.attributes.each do |name,attr| @properties[name] = attr.value end @properties[:uiname] = @name return @properties end |
#pathbare ⇒ Object
175 176 177 |
# File 'lib/twb/columnfield.rb', line 175 def @pathbare ||= path().gsub(/\[\]/,'') end |
#to_s ⇒ Object
264 265 266 |
# File 'lib/twb/columnfield.rb', line 264 def to_s "n:#{@name}: uin:#{uiname}: " end |