Class: Sfp::Variable
- Inherits:
-
Array
- Object
- Array
- Sfp::Variable
- Defined in:
- lib/sfp/sas_translator.rb
Overview
SAS Variable is a finite-domain variable It has a finite set of possible values
Instance Attribute Summary collapse
-
#goal ⇒ Object
Returns the value of attribute goal.
-
#id ⇒ Object
Returns the value of attribute id.
-
#init ⇒ Object
Returns the value of attribute init.
-
#is_final ⇒ Object
Returns the value of attribute is_final.
-
#is_primitive ⇒ Object
readonly
Returns the value of attribute is_primitive.
-
#isset ⇒ Object
Returns the value of attribute isset.
-
#layer ⇒ Object
Returns the value of attribute layer.
-
#mutable ⇒ Object
Returns the value of attribute mutable.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, type, layer = -1,, init = nil, goal = nil, is_final = false) ⇒ Variable
constructor
A new instance of Variable.
- #not(x) ⇒ Object
- #to_s ⇒ Object
-
#to_sas(root) ⇒ Object
return variable representation in SAS+ format.
Constructor Details
#initialize(name, type, layer = -1,, init = nil, goal = nil, is_final = false) ⇒ Variable
Returns a new instance of Variable.
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 |
# File 'lib/sfp/sas_translator.rb', line 1800 def initialize(name, type, layer=-1, init=nil, goal=nil, is_final=false) @name = name @type = type @layer = layer @init = init @goal = goal @is_final = is_final @is_primitive = (type == '$.String' or type == '$.Integer' or type == '$.Boolean') @mutable = true end |
Instance Attribute Details
#goal ⇒ Object
Returns the value of attribute goal.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def goal @goal end |
#id ⇒ Object
Returns the value of attribute id.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def id @id end |
#init ⇒ Object
Returns the value of attribute init.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def init @init end |
#is_final ⇒ Object
Returns the value of attribute is_final.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def is_final @is_final end |
#is_primitive ⇒ Object (readonly)
Returns the value of attribute is_primitive.
1798 1799 1800 |
# File 'lib/sfp/sas_translator.rb', line 1798 def is_primitive @is_primitive end |
#isset ⇒ Object
Returns the value of attribute isset.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def isset @isset end |
#layer ⇒ Object
Returns the value of attribute layer.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def layer @layer end |
#mutable ⇒ Object
Returns the value of attribute mutable.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def mutable @mutable end |
#name ⇒ Object
Returns the value of attribute name.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
1797 1798 1799 |
# File 'lib/sfp/sas_translator.rb', line 1797 def type @type end |
Instance Method Details
#not(x) ⇒ Object
1833 1834 1835 |
# File 'lib/sfp/sas_translator.rb', line 1833 def not(x) self.select { |y| y != x } end |
#to_s ⇒ Object
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 |
# File 'lib/sfp/sas_translator.rb', line 1811 def to_s s = @name.to_s + '|' + @type.to_s s += '|' + (@init == nil ? '-' : (@init.is_a?(Hash) ? @init.tostring : @init.to_s)) s += '|' + (@goal == nil ? '-' : (@goal.is_a?(Hash) ? @goal.tostring : @goal.to_s)) s += '|' + (@is_final ? 'final' : 'notfinal') + "\n" s += "\t[" self.each { |v| s += (v.is_a?(Hash) ? v.tostring : v.to_s) + ',' } s = (self.length > 0 ? s.chop : s) + "]" return s end |
#to_sas(root) ⇒ Object
return variable representation in SAS+ format
1823 1824 1825 1826 1827 1828 1829 1830 1831 |
# File 'lib/sfp/sas_translator.rb', line 1823 def to_sas(root) sas = "begin_variable\nvar_#{@id}#{@name}\n#{@layer}\n#{self.length}\n" self.each { |v| v = root.at?(v) if v.is_a?(String) and v.isref v = '"' + v + '"' if v.is_a?(String) sas += (v.is_a?(Hash) ? (v.isnull ? "null\n" : "#{v.ref}\n") : "#{v}\n") } return sas += "end_variable" end |