Class: Ravensat::Extension::IntegerVariable
- Defined in:
- lib/ravensat/extension/variable/integer_variable.rb
Instance Attribute Summary collapse
-
#var_nodes ⇒ Object
readonly
Returns the value of attribute var_nodes.
Attributes inherited from Variable
Instance Method Summary collapse
- #!=(object) ⇒ Object
- #==(object) ⇒ Object
-
#initialize(name, args) ⇒ IntegerVariable
constructor
A new instance of IntegerVariable.
- #only_one ⇒ Object
- #result ⇒ Object
Methods inherited from Variable
Constructor Details
#initialize(name, args) ⇒ IntegerVariable
Returns a new instance of IntegerVariable.
6 7 8 9 10 |
# File 'lib/ravensat/extension/variable/integer_variable.rb', line 6 def initialize(name, args) super return unless args.first.is_a? Range @var_nodes = args.first.zip(Array.new(args.first.size){Ravensat::VarNode.new}).to_h end |
Instance Attribute Details
#var_nodes ⇒ Object (readonly)
Returns the value of attribute var_nodes.
5 6 7 |
# File 'lib/ravensat/extension/variable/integer_variable.rb', line 5 def var_nodes @var_nodes end |
Instance Method Details
#!=(object) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ravensat/extension/variable/integer_variable.rb', line 29 def !=(object) case object when Integer return ~(@var_nodes[object]) when IntegerVariable result_formula = Ravensat::InitialNode.new duplicated_keys = self.var_nodes.keys & object.var_nodes.keys duplicated_keys.each do |index| result_formula &= ~(self.var_nodes[index]) | ~(object.var_nodes[index]) end return result_formula else raise ArgumentError end end |
#==(object) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ravensat/extension/variable/integer_variable.rb', line 12 def ==(object) case object when Integer return @var_nodes[object] when IntegerVariable result_formula = Ravensat::InitialNode.new duplicated_keys = self.var_nodes.keys & object.var_nodes.keys [self.var_nodes, object.var_nodes].repeated_permutation(duplicated_keys.size) do |var_nodes| result_formula &= Ravensat::Claw.alo(var_nodes.zip(duplicated_keys).map{|arr| arr.first[arr.last]}) end return result_formula else raise ArgumentError end end |
#only_one ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ravensat/extension/variable/integer_variable.rb', line 46 def only_one result_formula = Ravensat::InitialNode.new result_formula &= Ravensat::Claw.alo @var_nodes.values result_formula &= Ravensat::Claw.amo @var_nodes.values result_formula end |
#result ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/ravensat/extension/variable/integer_variable.rb', line 53 def result result = @var_nodes.select{|key, var_node| var_node.value}.keys if result.one? result.first else result end end |