Class: LogicTools::NodeVar

Inherits:
Node
  • Object
show all
Defined in:
lib/logic_tools/logictree.rb

Overview

Represents a variable node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#distribute, #each, #each_line, #each_maxterm, #each_minterm, #eql?, #flatten, #flatten_deep, #getVariables, #hash, #inspect, #op, #simplify, #size, #to_std_conjunctive, #to_std_disjunctive, #to_sum_product

Constructor Details

#initialize(name) ⇒ NodeVar

Creates a node with variable name.



325
326
327
328
# File 'lib/logic_tools/logictree.rb', line 325

def initialize(name)
    @variable = Variable.get(name)
    @sym = @variable.to_s.to_sym
end

Instance Attribute Details

#variableObject (readonly)

The variable held by the node.



322
323
324
# File 'lib/logic_tools/logictree.rb', line 322

def variable
  @variable
end

Instance Method Details

#==(node) ⇒ Object

Compares with node.



348
349
350
351
# File 'lib/logic_tools/logictree.rb', line 348

def ==(node) # :nodoc:
    return false unless node.is_a?(NodeVar)
    return self.variable == node.variable
end

#evalObject

Computes the value of the node.



331
332
333
# File 'lib/logic_tools/logictree.rb', line 331

def eval()
    return @variable.value
end

#getVariablesRecurseObject

Gets the variables, recursively, without postprocessing.

Returns the variables into sets of arrays with possible doublon


343
344
345
# File 'lib/logic_tools/logictree.rb', line 343

def getVariablesRecurse() # :nodoc:
    return [ @variable ]
end

#to_sObject

Converts to a string.



354
355
356
# File 'lib/logic_tools/logictree.rb', line 354

def to_s # :nodoc:
    return variable.to_s
end

#to_symObject

Converts to a symbol.



336
337
338
# File 'lib/logic_tools/logictree.rb', line 336

def to_sym # :nodoc:
    return @sym
end