Class: Sfp::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/sfp/sas_translator.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var, pre, post = nil) ⇒ Parameter

Returns a new instance of Parameter.



2042
2043
2044
2045
2046
# File 'lib/sfp/sas_translator.rb', line 2042

def initialize(var, pre, post=nil)
	@var = var
	@pre = pre
	@post = post
end

Instance Attribute Details

#postObject

Returns the value of attribute post.



2040
2041
2042
# File 'lib/sfp/sas_translator.rb', line 2040

def post
  @post
end

#preObject

Returns the value of attribute pre.



2040
2041
2042
# File 'lib/sfp/sas_translator.rb', line 2040

def pre
  @pre
end

#varObject

Returns the value of attribute var.



2040
2041
2042
# File 'lib/sfp/sas_translator.rb', line 2040

def var
  @var
end

Instance Method Details

#cloneObject



2056
2057
2058
# File 'lib/sfp/sas_translator.rb', line 2056

def clone
	return Parameter.new(@var, @pre, @post)
end

#effect?Boolean

Returns:

  • (Boolean)


2052
2053
2054
# File 'lib/sfp/sas_translator.rb', line 2052

def effect?
	return (@post != nil)
end

#prevail?Boolean

Returns:

  • (Boolean)


2048
2049
2050
# File 'lib/sfp/sas_translator.rb', line 2048

def prevail?
	return (@post == nil)
end

#to_sObject



2076
2077
2078
2079
2080
# File 'lib/sfp/sas_translator.rb', line 2076

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, prevail = true) ⇒ Object

Raises:

  • (Exception)


2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
# File 'lib/sfp/sas_translator.rb', line 2060

def to_sas(root, variables, prevail=true)
	# resolve the reference
	#pre = ( (@pre.is_a?(String) and @pre.isref) ? root.at?(@pre) : @pre )
	#post = ( (@post.is_a?(String) and @post.isref) ? root.at?(@post) : @post )
	pre = ((@pre.is_a?(String) and @pre.isref) ? variables[@pre].init : @pre)
	post = ((@post.is_a?(String) and @post.isref) ? variables[@post].init : @post)
	# calculate the index
	pre = ( (pre.is_a?(Hash) and pre.isnull) ? 0 : (pre == nil ? -1 : @var.index(pre)) )
	post = ( (post.is_a?(Hash) and post.isnull) ? 0 : @var.index(post) )

	raise Exception, self.to_s if not prevail and post.nil?

	return "#{@var.id} #{pre}" if post.nil?
	return "0 #{@var.id} #{pre} #{post}"
end

#to_sfwObject



2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
# File 'lib/sfp/sas_translator.rb', line 2082

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