Class: Twb::CalculatedField
- Inherits:
-
Object
- Object
- Twb::CalculatedField
- Includes:
- TabTool
- Defined in:
- lib/twb/calculatedfield.rb
Instance Attribute Summary collapse
-
#calculation ⇒ Object
readonly
Returns the value of attribute calculation.
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#dataSource ⇒ Object
readonly
Returns the value of attribute dataSource.
-
#datatype ⇒ Object
readonly
Returns the value of attribute datatype.
-
#groupMembers ⇒ Object
readonly
Returns the value of attribute groupMembers.
-
#hidden ⇒ Object
readonly
Returns the value of attribute hidden.
-
#isGroup ⇒ Object
readonly
Returns the value of attribute isGroup.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#propType ⇒ Object
readonly
Returns the value of attribute propType.
-
#referencedFields ⇒ Object
readonly
Returns the value of attribute referencedFields.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#uiname ⇒ Object
readonly
Returns the value of attribute uiname.
Attributes included from TabTool
#alerts, #docDir, #docfiles, #funcdoc, #licensed, #logfilename, #logger, #loglevel, #metrics, #ttdocdir, #type, #uuid
Instance Method Summary collapse
- #binValues(binName) ⇒ Object
- #formulaLines ⇒ Object
- #formulaResolved ⇒ Object
- #formulaResolvedLines ⇒ Object
- #id ⇒ Object
-
#initialize(calcNode, datasource = nil) ⇒ CalculatedField
constructor
A new instance of CalculatedField.
- #loadProperties ⇒ Object
-
#to_s ⇒ Object
def loadUUID dsn = @dataSource.nil? ? ‘NO DATASOURCE’ : dataSource.uuid @uuid = Digest::MD5.hexdigest(“#dsn::@name”).hash end.
Methods included from TabTool
#addDocFile, #alert, #closeDocFiles, #config, #docFile, #docFileMaxNameLen, #docfilesdoc, #docfilesdocto_s, #emit, #emitCSV, #finis, #hasConfig, #init, #initCSV, #initDocDir, #initLogger, #license=, #licensed?, #loadConfig
Constructor Details
#initialize(calcNode, datasource = nil) ⇒ CalculatedField
Returns a new instance of CalculatedField.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/twb/calculatedfield.rb', line 33 def initialize(calcNode, datasource=nil) @node = calcNode @dataSource = datasource # -- @caption = calcNode.attribute('caption').text if calcNode.has_attribute?('caption') @name = calcNode.attribute('name').text.gsub(/^\[/,'').gsub(/\]$/,'') @uiname = .nil? ? @name : @caption # -- @datatype = @node.attribute('datatype').text @role = @node.attribute('role').text @propType = @node.attribute('type').text # n.b. 'type' is used as a proxy for class # -- @calculation = Twb::FieldCalculation.new(self, datasource) # -- @hidden = true if calcNode.has_attribute?('caption') @isGroup = !@node.at_xpath('./calculation[@class="categorical-bin"]').nil? end |
Instance Attribute Details
#calculation ⇒ Object (readonly)
Returns the value of attribute calculation.
29 30 31 |
# File 'lib/twb/calculatedfield.rb', line 29 def calculation @calculation end |
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
27 28 29 |
# File 'lib/twb/calculatedfield.rb', line 27 def @caption end |
#dataSource ⇒ Object (readonly)
Returns the value of attribute dataSource.
25 26 27 |
# File 'lib/twb/calculatedfield.rb', line 25 def dataSource @dataSource end |
#datatype ⇒ Object (readonly)
Returns the value of attribute datatype.
28 29 30 |
# File 'lib/twb/calculatedfield.rb', line 28 def datatype @datatype end |
#groupMembers ⇒ Object (readonly)
Returns the value of attribute groupMembers.
30 31 32 |
# File 'lib/twb/calculatedfield.rb', line 30 def groupMembers @groupMembers end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
31 32 33 |
# File 'lib/twb/calculatedfield.rb', line 31 def hidden @hidden end |
#isGroup ⇒ Object (readonly)
Returns the value of attribute isGroup.
30 31 32 |
# File 'lib/twb/calculatedfield.rb', line 30 def isGroup @isGroup end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/twb/calculatedfield.rb', line 27 def name @name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
26 27 28 |
# File 'lib/twb/calculatedfield.rb', line 26 def node @node end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
26 27 28 |
# File 'lib/twb/calculatedfield.rb', line 26 def properties @properties end |
#propType ⇒ Object (readonly)
Returns the value of attribute propType.
28 29 30 |
# File 'lib/twb/calculatedfield.rb', line 28 def propType @propType end |
#referencedFields ⇒ Object (readonly)
Returns the value of attribute referencedFields.
29 30 31 |
# File 'lib/twb/calculatedfield.rb', line 29 def referencedFields @referencedFields end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
28 29 30 |
# File 'lib/twb/calculatedfield.rb', line 28 def role @role end |
#uiname ⇒ Object (readonly)
Returns the value of attribute uiname.
27 28 29 |
# File 'lib/twb/calculatedfield.rb', line 27 def uiname @uiname end |
Instance Method Details
#binValues(binName) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/twb/calculatedfield.rb', line 75 def binValues binName values = [] binValue = "\"#{binName}\"" binNode = @node.at_xpath("./calculation[@class='categorical-bin']/bin[@value='#{binValue}']") unless binNode.nil? binNode.xpath('.//value').each do |v| values << v.text.gsub(/^['"]|['"]$/,'') end end return values end |
#formulaLines ⇒ Object
59 60 61 |
# File 'lib/twb/calculatedfield.rb', line 59 def formulaLines @calculation.formulaLines end |
#formulaResolved ⇒ Object
67 68 69 |
# File 'lib/twb/calculatedfield.rb', line 67 def formulaResolved @calculation.formulaResolved end |
#formulaResolvedLines ⇒ Object
63 64 65 |
# File 'lib/twb/calculatedfield.rb', line 63 def formulaResolvedLines @calculation.formulaResolvedLines end |
#id ⇒ Object
97 98 99 |
# File 'lib/twb/calculatedfield.rb', line 97 def id @id ||= @id = "#{@dataSource.uiname}::#{@uiname}" end |
#loadProperties ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/twb/calculatedfield.rb', line 87 def loadProperties @properties= {} @node.attributes.each do |name,attr| @properties[name] = attr.value end @properties[:uiname] = @uiname @properties[:uuid] = uuid return @properties end |
#to_s ⇒ Object
def loadUUID
dsn = @dataSource.nil? ? 'NO DATASOURCE' : dataSource.uuid
@uuid = Digest::MD5.hexdigest("#{dsn}::@name").hash
end
110 111 112 |
# File 'lib/twb/calculatedfield.rb', line 110 def to_s "%s(%s) => %s" % [uiname, name, @calculation.formulaFlat] end |