class Sfp::Variable

SAS Variable is a finite-domain variable It has a finite set of possible values

Attributes

goal[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

id[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

init[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

is_final[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

is_primitive[R]
isset[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

layer[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

mutable[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

name[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

type[RW]

@name – name of variable @type – type of variable (‘string’,‘boolean’,‘number’, or fullpath of a class) @layer – axiom layer ( ‘-1’ if this is not axiom variable, otherwise >0) @init – initial value @goal – goal value (desired value)

Public Class Methods

new(name, type, layer=-1, init=nil, goal=nil, is_final=false) click to toggle source
# File lib/sfp/sas_translator.rb, line 1888
def initialize(name, type, layer=-1, init=nil, goal=nil, is_final=false)
        @name = name
        @type = type
        @layer = layer
        @init = init
        @goal = goal
        @is_final = is_final
        @is_primitive = (type == '$.String' or type == '$.Integer' or type == '$.Boolean')
        @mutable = true
end

Public Instance Methods

dump(stream, root) click to toggle source
# File lib/sfp/sas_translator.rb, line 1926
def dump(stream, root)
        stream.write "begin_variable\nvar_#{@id}#{@name}\n#{@layer}\n#{self.length}\n"
        self.each { |v|
                v = root.at?(v) if v.is_a?(String) and v.isref
                v = '"' + v + '"' if v.is_a?(String)
                stream.write (v.is_a?(Hash) ? (v.isnull ? "null\n" : "#{v.ref}\n") : "#{v}\n")
        }
        stream.write "end_variable\n"
end
not(x) click to toggle source
# File lib/sfp/sas_translator.rb, line 1936
def not(x)
        self.select { |y| y != x }
end
to_s() click to toggle source
# File lib/sfp/sas_translator.rb, line 1899
def to_s
        s = @name.to_s + '|' + @type.to_s
        s << '|'
        s << (@init == nil ? '-' : (@init.is_a?(Hash) ? @init.tostring : @init.to_s))
        s << '|'
        s << (@goal == nil ? '-' : (@goal.is_a?(Hash) ? @goal.tostring : @goal.to_s))
        s << '|'
        s << (@is_final ? 'final' : 'notfinal') + "\n"
        s << "\t["
        self.each { |v| s << (v.is_a?(Hash) ? v.tostring : v.to_s) + ',' }
        s = (self.length > 0 ? s.chop : s)
        s << "]"
end
to_sas(root) click to toggle source

return variable representation in SAS+ format

# File lib/sfp/sas_translator.rb, line 1914
def to_sas(root)
        sas = "begin_variable\nvar_#{@id}#{@name}\n#{@layer}\n#{self.length}\n"
        self.each { |v|
                if v.is_a?(String) and v.isref
                        v = root.at?(v)
                end
                v = '"' + v + '"' if v.is_a?(String)
                sas << (v.is_a?(Hash) ? (v.isnull ? "null\n" : "#{v.ref}\n") : "#{v}\n")
        }
        sas << "end_variable\n"
end