Class: LogicTools::NodeUnary

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

Overview

Represents an unary node.

Direct Known Subclasses

NodeNot

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#cover?, #distribute, #each_line, #each_maxterm, #each_minterm, #eql?, #flatten, #flatten_deep, #get_variables, #hash, #inspect, #reduce, #simplify, #to_cover, #to_std_conjunctive, #to_std_disjunctive, #to_sum_product

Constructor Details

#initialize(op, child) ⇒ NodeUnary

Creates a node with operator op and a child.



848
849
850
851
852
853
854
855
856
# File 'lib/logic_tools/logictree.rb', line 848

def initialize(op,child)
    if !child.is_a?(Node) then
        raise ArgumentError.new("Not a valid object for child.")
    end
    @op = op.to_sym
    @child = child
    # @sym = self.to_s.to_sym
    @sym = nil
end

Instance Attribute Details

#childObject (readonly)

Returns the value of attribute child.



845
846
847
# File 'lib/logic_tools/logictree.rb', line 845

def child
  @child
end

#opObject (readonly)

Returns the value of attribute op.



845
846
847
# File 'lib/logic_tools/logictree.rb', line 845

def op
  @op
end

Instance Method Details

#==(node) ⇒ Object

Compares with node.



896
897
898
899
900
# File 'lib/logic_tools/logictree.rb', line 896

def ==(node) # :nodoc:
    return false unless node.is_a?(Node)
    return false unless self.op == node.op
    return self.child == node.child
end

#each {|@child| ... } ⇒ Object

Iterates over the children.

Yields:



887
888
889
890
891
892
893
# File 'lib/logic_tools/logictree.rb', line 887

def each # :nodoc:
    # No block given? Return an enumerator.
    return to_enum(:each) unless block_given?

    # Block given? Apply it.
    yield(@child)
end

#get_variablesRecurseObject

Gets the variables, recursively, without postprocessing.

Returns the variables into sets of arrays with possible doublon


882
883
884
# File 'lib/logic_tools/logictree.rb', line 882

def get_variablesRecurse() # :nodoc:
    return @child.get_variablesRecurse
end

#include?(tree) ⇒ Boolean

Tells if the self includes tree.

Returns:

  • (Boolean)


903
904
905
906
907
908
909
# File 'lib/logic_tools/logictree.rb', line 903

def include?(tree)
    return true if self == tree # Same tree, so inclusion.
    # Check the child
    return true if @child.include?(tree)
    # Do not include
    return false
end

#is_parent?Boolean

Tells if the node is a parent.

Returns:

  • (Boolean)


859
860
861
# File 'lib/logic_tools/logictree.rb', line 859

def is_parent?
    return true
end

#sizeObject

Gets the number of children.



864
865
866
# File 'lib/logic_tools/logictree.rb', line 864

def size # :nodoc:
    1
end

#to_symObject

Converts to a symbol.



912
913
914
915
# File 'lib/logic_tools/logictree.rb', line 912

def to_sym # :nodoc:
    @sym = self.to_s.to_sym unless @sym
    return @sym
end