class Twb::CalculatedField

Attributes

calculation[R]
caption[R]
dataSource[R]
datatype[R]
groupMembers[R]
hidden[R]
isGroup[R]
name[R]
node[R]
propType[R]
properties[R]
referencedFields[R]
role[R]
uiname[R]

Public Class Methods

new(calcNode, datasource=nil) click to toggle source
# 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

Public Instance Methods

binValues(binName) click to toggle source
# 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() click to toggle source
# File lib/twb/calculatedfield.rb, line 59
def formulaLines
    @calculation.formulaLines
end
formulaResolved() click to toggle source
# File lib/twb/calculatedfield.rb, line 67
def formulaResolved
    @calculation.formulaResolved
end
formulaResolvedLines() click to toggle source
# File lib/twb/calculatedfield.rb, line 63
def formulaResolvedLines
    @calculation.formulaResolvedLines
end
id() click to toggle source
# File lib/twb/calculatedfield.rb, line 97
def id
    @id ||= @id = "#{@dataSource.uiname}::#{@uiname}"
end
loadProperties() click to toggle source
# 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() click to toggle source

def loadUUID

dsn = @dataSource.nil? ? 'NO DATASOURCE' : dataSource.uuid 
@uuid = Digest::MD5.hexdigest("#{dsn}::@name").hash

end

# File lib/twb/calculatedfield.rb, line 110
def to_s
    "%s(%s) => %s" % [uiname, name, @calculation.formulaFlat]
end

Private Instance Methods

loadgroupmembers() click to toggle source
# File lib/twb/calculatedfield.rb, line 116
def loadgroupmembers
    @groupMembers = Hash.new { |h,k| h[k] = [] } 
    if @isGroup
        groupLeads =  @node.xpath('./calculation[@class="categorical-bin"]//bin')
        groupLeads.each do |gl|
            lead = gl['value']
            groupAlias = @node.at_xpath("./aliases/alias[@key='#{lead}']")
            groupNamex = groupAlias.nil? ? lead : groupAlias['value']
            groupName  = groupNamex.gsub(/^['"]|['"]$/,'')
            values = gl.xpath('./value')
            values.each do |v|
                @groupMembers[groupName] << v.text.gsub(/^['"]|['"]$/,'').gsub('\"','"')
            end
        end
    end
    return @groupMembers
end