Class: Sfp::Parameter
- Inherits:
-
Object
- Object
- Sfp::Parameter
- 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
-
#post ⇒ Object
Returns the value of attribute post.
-
#pre ⇒ Object
Returns the value of attribute pre.
-
#var ⇒ Object
Returns the value of attribute var.
Instance Method Summary collapse
- #clone ⇒ Object
- #effect? ⇒ Boolean
-
#initialize(var, pre, post = nil) ⇒ Parameter
constructor
A new instance of Parameter.
- #prevail? ⇒ Boolean
- #to_s ⇒ Object
- #to_sas(root, variables, prevail = true) ⇒ Object
- #to_sfw ⇒ Object
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
#post ⇒ Object
Returns the value of attribute post.
2040 2041 2042 |
# File 'lib/sfp/sas_translator.rb', line 2040 def post @post end |
#pre ⇒ Object
Returns the value of attribute pre.
2040 2041 2042 |
# File 'lib/sfp/sas_translator.rb', line 2040 def pre @pre end |
#var ⇒ Object
Returns the value of attribute var.
2040 2041 2042 |
# File 'lib/sfp/sas_translator.rb', line 2040 def var @var end |
Instance Method Details
#clone ⇒ Object
2056 2057 2058 |
# File 'lib/sfp/sas_translator.rb', line 2056 def clone return Parameter.new(@var, @pre, @post) end |
#effect? ⇒ Boolean
2052 2053 2054 |
# File 'lib/sfp/sas_translator.rb', line 2052 def effect? return (@post != nil) end |
#prevail? ⇒ Boolean
2048 2049 2050 |
# File 'lib/sfp/sas_translator.rb', line 2048 def prevail? return (@post == nil) end |
#to_s ⇒ Object
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
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_sfw ⇒ Object
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 |