Class: Twb::CalculatedField

Inherits:
TabClass show all
Defined in:
lib/twb/calculatedfield.rb

Instance Attribute Summary collapse

Attributes inherited from TabClass

#ttlogfile, #ttlogfilename, #type, #uuid

Instance Method Summary collapse

Methods inherited from TabClass

#docFile, #emit, #setDocFileName

Constructor Details

#initialize(calcNode, datasource = nil) ⇒ CalculatedField

Returns a new instance of CalculatedField.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/twb/calculatedfield.rb', line 31

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

#calcFieldsObject (readonly)

Returns the value of attribute calcFields.



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

def calcFields
  @calcFields
end

#calculationObject (readonly)

Returns the value of attribute calculation.



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

def calculation
  @calculation
end

#captionObject (readonly)

Returns the value of attribute caption.



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

def caption
  @caption
end

#dataSourceObject (readonly)

Returns the value of attribute dataSource.



23
24
25
# File 'lib/twb/calculatedfield.rb', line 23

def dataSource
  @dataSource
end

#datatypeObject (readonly)

Returns the value of attribute datatype.



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

def datatype
  @datatype
end

#groupMembersObject (readonly)

Returns the value of attribute groupMembers.



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

def groupMembers
  @groupMembers
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



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

def hidden
  @hidden
end

#isGroupObject (readonly)

Returns the value of attribute isGroup.



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

def isGroup
  @isGroup
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

#propTypeObject (readonly)

Returns the value of attribute propType.



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

def propType
  @propType
end

#roleObject (readonly)

Returns the value of attribute role.



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

def role
  @role
end

#uinameObject (readonly)

Returns the value of attribute uiname.



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

def uiname
  @uiname
end

Instance Method Details

#binValues(binName) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/twb/calculatedfield.rb', line 73

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



57
58
59
# File 'lib/twb/calculatedfield.rb', line 57

def formulaLines
    @calculation.formulaLines
end

#formulaResolvedObject



65
66
67
# File 'lib/twb/calculatedfield.rb', line 65

def formulaResolved
    @calculation.formulaResolved
end

#formulaResolvedLinesObject



61
62
63
# File 'lib/twb/calculatedfield.rb', line 61

def formulaResolvedLines
    @calculation.formulaResolvedLines
end

#idObject



95
96
97
# File 'lib/twb/calculatedfield.rb', line 95

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

#loadPropertiesObject



85
86
87
88
89
90
91
92
93
# File 'lib/twb/calculatedfield.rb', line 85

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



108
109
110
# File 'lib/twb/calculatedfield.rb', line 108

def to_s
    "%s(%s) => %s" % [uiname, name, @calculation.formulaFlat]
end