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
Returns the value of attribute calcField.
-
#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.
-
#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
- #hasComment? ⇒ Boolean
- #id ⇒ Object
-
#initialize(fieldNode, datasource = nil) ⇒ ColumnField
constructor
A new instance of ColumnField.
- #load(nodeName) ⇒ Object
- #loadAliases ⇒ 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
- #loadRole ⇒ 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/twb/columnfield.rb', line 70 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
#aggregation ⇒ Object (readonly)
Returns the value of attribute aggregation.
64 65 66 |
# File 'lib/twb/columnfield.rb', line 64 def aggregation @aggregation end |
#alias ⇒ Object (readonly)
Returns the value of attribute alias.
61 62 63 |
# File 'lib/twb/columnfield.rb', line 61 def alias @alias end |
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
68 69 70 |
# File 'lib/twb/columnfield.rb', line 68 def aliases @aliases end |
#autoColumn ⇒ Object (readonly)
Returns the value of attribute autoColumn.
65 66 67 |
# File 'lib/twb/columnfield.rb', line 65 def autoColumn @autoColumn end |
#calcField ⇒ Object (readonly)
Returns the value of attribute calcField.
66 67 68 |
# File 'lib/twb/columnfield.rb', line 66 def calcField @calcField end |
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
61 62 63 |
# File 'lib/twb/columnfield.rb', line 61 def @caption end |
#dataType ⇒ Object (readonly)
Returns the value of attribute dataType.
62 63 64 |
# File 'lib/twb/columnfield.rb', line 62 def dataType @dataType end |
#datatypeCustomized ⇒ Object (readonly)
Returns the value of attribute datatypeCustomized.
65 66 67 |
# File 'lib/twb/columnfield.rb', line 65 def datatypeCustomized @datatypeCustomized end |
#defaultFormat ⇒ Object (readonly)
Returns the value of attribute defaultFormat.
62 63 64 |
# File 'lib/twb/columnfield.rb', line 62 def defaultFormat @defaultFormat end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
65 66 67 |
# File 'lib/twb/columnfield.rb', line 65 def hidden @hidden end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
61 62 63 |
# File 'lib/twb/columnfield.rb', line 61 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
60 61 62 |
# File 'lib/twb/columnfield.rb', line 60 def node @node end |
#paramDomainType ⇒ Object (readonly)
Returns the value of attribute paramDomainType.
62 63 64 |
# File 'lib/twb/columnfield.rb', line 62 def paramDomainType @paramDomainType end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
67 68 69 |
# File 'lib/twb/columnfield.rb', line 67 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
60 61 62 |
# File 'lib/twb/columnfield.rb', line 60 def properties @properties end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
63 64 65 |
# File 'lib/twb/columnfield.rb', line 63 def role @role end |
#semanticRole ⇒ Object (readonly)
Returns the value of attribute semanticRole.
64 65 66 |
# File 'lib/twb/columnfield.rb', line 64 def semanticRole @semanticRole end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
63 64 65 |
# File 'lib/twb/columnfield.rb', line 63 def type @type end |
#uiname ⇒ Object (readonly)
Returns the value of attribute uiname.
61 62 63 |
# File 'lib/twb/columnfield.rb', line 61 def uiname @uiname end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
63 64 65 |
# File 'lib/twb/columnfield.rb', line 63 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
206 207 208 |
# File 'lib/twb/columnfield.rb', line 206 def <=>(other) @name <=> other.name end |
#comment ⇒ Object
136 137 138 |
# File 'lib/twb/columnfield.rb', line 136 def comment @commentLines ||= loadComment end |
#hasComment? ⇒ Boolean
169 170 171 172 |
# File 'lib/twb/columnfield.rb', line 169 def hasComment? loadComment if @commentLines.nil? @commentLines.empty? end |
#id ⇒ Object
90 91 92 |
# File 'lib/twb/columnfield.rb', line 90 def id @id ||= @id = @name.hash end |
#load(nodeName) ⇒ Object
94 95 96 97 98 |
# File 'lib/twb/columnfield.rb', line 94 def load nodeName attr = @node.attribute(nodeName) val = attr.nil? ? nil : attr.text.strip.gsub(/^\[|\]$/,'') return val end |
#loadAliases ⇒ Object
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/twb/columnfield.rb', line 178 def loadAliases @aliases = {} aliasNodes = @node.xpath('.//alias') aliasNodes.each do |node| key = node.attribute('key').text.gsub(/^"|"$/,'') value = node.attribute('value').text.gsub(/^"|"$/,'') @aliases[key] = value end return @aliases end |
#loadCalcField ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/twb/columnfield.rb', line 120 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>
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/twb/columnfield.rb', line 157 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
193 194 195 196 197 198 199 200 |
# File 'lib/twb/columnfield.rb', line 193 def loadProperties @properties= {} @node.attributes.each do |name,attr| @properties[name] = attr.value end @properties[:uiname] = @name return @properties end |
#loadRole ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/twb/columnfield.rb', line 104 def loadRole role = @node['role'] if role.nil? role = @@dataTypeRoleMap[@dataType].nil? ? @dataType : @@dataTypeRoleMap[@dataType] end return role end |
#pathbare ⇒ Object
132 133 134 |
# File 'lib/twb/columnfield.rb', line 132 def @pathbare ||= path().gsub(/\[\]/,'') end |
#to_s ⇒ Object
202 203 204 |
# File 'lib/twb/columnfield.rb', line 202 def to_s @name end |