Class: LogicTools::NodeVar
Overview
Represents a variable node.
Instance Attribute Summary collapse
-
#variable ⇒ Object
readonly
The variable held by the node.
Instance Method Summary collapse
-
#==(node) ⇒ Object
Compares with
node. -
#eval ⇒ Object
Computes the value of the node.
-
#get_variablesRecurse ⇒ Object
Gets the variables, recursively, without postprocessing.
-
#initialize(name) ⇒ NodeVar
constructor
Creates a node with variable
name. -
#op ⇒ Object
Gets the operator.
-
#to_s ⇒ Object
Converts to a string.
-
#to_sym ⇒ Object
Converts to a symbol.
Methods inherited from Node
#cover?, #distribute, #each, #each_line, #each_maxterm, #each_minterm, #eql?, #eval_input, #flatten, #flatten_deep, #get_variables, #hash, #include?, #inspect, #is_parent?, #reduce, #simplify, #size, #to_cover, #to_std_conjunctive, #to_std_disjunctive, #to_sum_product
Constructor Details
#initialize(name) ⇒ NodeVar
Creates a node with variable name.
390 391 392 393 394 |
# File 'lib/logic_tools/logictree.rb', line 390 def initialize(name) @variable = Variable.get(name) # @sym = @variable.to_s.to_sym @sym = nil end |
Instance Attribute Details
#variable ⇒ Object (readonly)
The variable held by the node.
387 388 389 |
# File 'lib/logic_tools/logictree.rb', line 387 def variable @variable end |
Instance Method Details
#==(node) ⇒ Object
Compares with node.
428 429 430 431 |
# File 'lib/logic_tools/logictree.rb', line 428 def ==(node) # :nodoc: return false unless node.is_a?(NodeVar) return self.variable == node.variable end |
#eval ⇒ Object
Computes the value of the node.
410 411 412 |
# File 'lib/logic_tools/logictree.rb', line 410 def eval() return @variable.value end |
#get_variablesRecurse ⇒ Object
Gets the variables, recursively, without postprocessing.
Returns the variables into sets of arrays with possible doublon
423 424 425 |
# File 'lib/logic_tools/logictree.rb', line 423 def get_variablesRecurse() # :nodoc: return [ @variable ] end |
#op ⇒ Object
Gets the operator.
Default: +nil+ (none).
399 400 401 |
# File 'lib/logic_tools/logictree.rb', line 399 def op :variable end |
#to_s ⇒ Object
Converts to a string.
434 435 436 437 438 439 440 |
# File 'lib/logic_tools/logictree.rb', line 434 def to_s # :nodoc: result = variable.to_s # Variables using more than one character are parenthesized # to avoid confunsion with the AND operator. result = "{" + result + "}" if (result.size > 1) return result end |
#to_sym ⇒ Object
Converts to a symbol.
415 416 417 418 |
# File 'lib/logic_tools/logictree.rb', line 415 def to_sym # :nodoc: @sym = @variable.to_s.to_sym unless @sym return @sym end |