class Sfp::Parameter
A class for operator/axiom parameter (prevail or effect condition)
:pre = nil - it can be anything (translated to -1) :post = nil - variable’s value doesn’t change
Attributes
post[RW]
pre[RW]
var[RW]
Public Class Methods
new(var, pre, post=nil)
click to toggle source
# File lib/sfp/sas_translator.rb, line 2183 def initialize(var, pre, post=nil) @var = var @pre = pre @post = post end
Public Instance Methods
clone()
click to toggle source
# File lib/sfp/sas_translator.rb, line 2197 def clone return Parameter.new(@var, @pre, @post) end
dump(stream, root, variables, is_prevail=true)
click to toggle source
# File lib/sfp/sas_translator.rb, line 2224 def dump(stream, root, variables, is_prevail=true) ### resolve reference pre = ((@pre.is_a?(String) and @pre.isref) ? variables[@pre.to_sym].init : @pre) ### calculate index if pre.is_a?(Hash) and pre.isnull pre = 0 elsif pre.nil? pre = -1 else pre = @var.index(pre) end line = nil if is_prevail line = "#{@var.id} #{pre}\n" else ### resolve reference post = ((@post.is_a?(String) and @post.isref) ? variables[@post.to_sym].init : @post) ### calculate index if post.is_a?(Hash) and post.isnull line = "0 #{@var.id} #{pre} 0\n" else line = "0 #{@var.id} #{pre} #{@var.index(post)}\n" end end raise TranslationException if line[-2] == ' ' stream.write line end
effect?()
click to toggle source
# File lib/sfp/sas_translator.rb, line 2193 def effect? return (@post != nil) end
prevail?()
click to toggle source
# File lib/sfp/sas_translator.rb, line 2189 def prevail? return (@post == nil) end
to_s()
click to toggle source
# File lib/sfp/sas_translator.rb, line 2254 def to_s return @var.name + ',' + (@pre == nil ? '-' : (@pre.is_a?(Hash) ? @pre.tostring : @pre.to_s)) + ',' + (@post == nil ? '-' : (@post.is_a?(Hash) ? @post.tostring : @post.to_s)) end
to_sas(root, variables, is_prevail=true)
click to toggle source
# File lib/sfp/sas_translator.rb, line 2201 def to_sas(root, variables, is_prevail=true) ### resolve reference pre = ((@pre.is_a?(String) and @pre.isref) ? variables[@pre.to_sym].init : @pre) ### calculate index if pre.is_a?(Hash) and pre.isnull pre = 0 elsif pre.nil? pre = -1 else pre = @var.index(pre) end return "#{@var.id} #{pre}" if is_prevail ### resolve reference post = ((@post.is_a?(String) and @post.isref) ? variables[@post.to_sym].init : @post) ### calculate index if post.is_a?(Hash) and post.isnull "0 #{@var.id} #{pre} 0" else "0 #{@var.id} #{pre} #{@var.index(post)}" end end
to_sfw()
click to toggle source
# File lib/sfp/sas_translator.rb, line 2260 def to_sfw pre = @pre pre = @pre.ref if @pre.is_a?(Hash) and @pre.isobject pre = Sfp::Null.new if @pre.is_a?(Hash) and @pre.isnull post = @post post = @post.ref if @post.is_a?(Hash) and @post.isobject post = Sfp::Null.new if @post.is_a?(Hash) and @post.isnull return { 'name' => @var.name, 'pre' => pre, 'post' => post } end