Class: Twb::CalculatedField

Inherits:
Object
  • Object
show all
Includes:
TabTool
Defined in:
lib/twb/calculatedfield.rb

Instance Attribute Summary collapse

Attributes included from TabTool

#alerts, #docDir, #docfiles, #funcdoc, #licensed, #logfilename, #logger, #loglevel, #metrics, #ttdocdir, #type, #uuid

Instance Method Summary collapse

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     = caption.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

#calculationObject (readonly)

Returns the value of attribute calculation


29
30
31
# File 'lib/twb/calculatedfield.rb', line 29

def calculation
  @calculation
end

#captionObject (readonly)

Returns the value of attribute caption


27
28
29
# File 'lib/twb/calculatedfield.rb', line 27

def caption
  @caption
end

#dataSourceObject (readonly)

Returns the value of attribute dataSource


25
26
27
# File 'lib/twb/calculatedfield.rb', line 25

def dataSource
  @dataSource
end

#datatypeObject (readonly)

Returns the value of attribute datatype


28
29
30
# File 'lib/twb/calculatedfield.rb', line 28

def datatype
  @datatype
end

#groupMembersObject (readonly)

Returns the value of attribute groupMembers


30
31
32
# File 'lib/twb/calculatedfield.rb', line 30

def groupMembers
  @groupMembers
end

#hiddenObject (readonly)

Returns the value of attribute hidden


31
32
33
# File 'lib/twb/calculatedfield.rb', line 31

def hidden
  @hidden
end

#isGroupObject (readonly)

Returns the value of attribute isGroup


30
31
32
# File 'lib/twb/calculatedfield.rb', line 30

def isGroup
  @isGroup
end

#nameObject (readonly)

Returns the value of attribute name


27
28
29
# File 'lib/twb/calculatedfield.rb', line 27

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node


26
27
28
# File 'lib/twb/calculatedfield.rb', line 26

def node
  @node
end

#propertiesObject (readonly)

Returns the value of attribute properties


26
27
28
# File 'lib/twb/calculatedfield.rb', line 26

def properties
  @properties
end

#propTypeObject (readonly)

Returns the value of attribute propType


28
29
30
# File 'lib/twb/calculatedfield.rb', line 28

def propType
  @propType
end

#referencedFieldsObject (readonly)

Returns the value of attribute referencedFields


29
30
31
# File 'lib/twb/calculatedfield.rb', line 29

def referencedFields
  @referencedFields
end

#roleObject (readonly)

Returns the value of attribute role


28
29
30
# File 'lib/twb/calculatedfield.rb', line 28

def role
  @role
end

#uinameObject (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

#formulaLinesObject


59
60
61
# File 'lib/twb/calculatedfield.rb', line 59

def formulaLines
    @calculation.formulaLines
end

#formulaResolvedObject


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

def formulaResolved
    @calculation.formulaResolved
end

#formulaResolvedLinesObject


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

def formulaResolvedLines
    @calculation.formulaResolvedLines
end

#idObject


97
98
99
# File 'lib/twb/calculatedfield.rb', line 97

def id
    @id ||= @id = "#{@dataSource.uiname}::#{@uiname}"
end

#loadPropertiesObject


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_sObject

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