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.
2030 2031 2032 2033 2034 |
# File 'lib/sfp/sas_translator.rb', line 2030 def initialize(var, pre, post=nil) @var = var @pre = pre @post = post end |
Instance Attribute Details
#post ⇒ Object
Returns the value of attribute post.
2028 2029 2030 |
# File 'lib/sfp/sas_translator.rb', line 2028 def post @post end |
#pre ⇒ Object
Returns the value of attribute pre.
2028 2029 2030 |
# File 'lib/sfp/sas_translator.rb', line 2028 def pre @pre end |
#var ⇒ Object
Returns the value of attribute var.
2028 2029 2030 |
# File 'lib/sfp/sas_translator.rb', line 2028 def var @var end |
Instance Method Details
#clone ⇒ Object
2044 2045 2046 |
# File 'lib/sfp/sas_translator.rb', line 2044 def clone return Parameter.new(@var, @pre, @post) end |
#effect? ⇒ Boolean
2040 2041 2042 |
# File 'lib/sfp/sas_translator.rb', line 2040 def effect? return (@post != nil) end |
#prevail? ⇒ Boolean
2036 2037 2038 |
# File 'lib/sfp/sas_translator.rb', line 2036 def prevail? return (@post == nil) end |
#to_s ⇒ Object
2064 2065 2066 2067 2068 |
# File 'lib/sfp/sas_translator.rb', line 2064 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
2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 |
# File 'lib/sfp/sas_translator.rb', line 2048 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
2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 |
# File 'lib/sfp/sas_translator.rb', line 2070 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 |