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.



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

#postObject

Returns the value of attribute post.



2028
2029
2030
# File 'lib/sfp/sas_translator.rb', line 2028

def post
  @post
end

#preObject

Returns the value of attribute pre.



2028
2029
2030
# File 'lib/sfp/sas_translator.rb', line 2028

def pre
  @pre
end

#varObject

Returns the value of attribute var.



2028
2029
2030
# File 'lib/sfp/sas_translator.rb', line 2028

def var
  @var
end

Instance Method Details

#cloneObject



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

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

#effect?Boolean

Returns:

  • (Boolean)


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

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

#prevail?Boolean

Returns:

  • (Boolean)


2036
2037
2038
# File 'lib/sfp/sas_translator.rb', line 2036

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

#to_sObject



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

Raises:

  • (Exception)


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_sfwObject



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