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?, #eval_input, #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.



874
875
876
877
878
879
880
881
882
# File 'lib/logic_tools/logictree.rb', line 874

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.



871
872
873
# File 'lib/logic_tools/logictree.rb', line 871

def child
  @child
end

#opObject (readonly)

Returns the value of attribute op.



871
872
873
# File 'lib/logic_tools/logictree.rb', line 871

def op
  @op
end

Instance Method Details

#==(node) ⇒ Object

Compares with node.



922
923
924
925
926
# File 'lib/logic_tools/logictree.rb', line 922

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:



913
914
915
916
917
918
919
# File 'lib/logic_tools/logictree.rb', line 913

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


908
909
910
# File 'lib/logic_tools/logictree.rb', line 908

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

#include?(tree) ⇒ Boolean

Tells if the self includes tree.

Returns:

  • (Boolean)


929
930
931
932
933
934
935
# File 'lib/logic_tools/logictree.rb', line 929

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)


885
886
887
# File 'lib/logic_tools/logictree.rb', line 885

def is_parent?
    return true
end

#sizeObject

Gets the number of children.



890
891
892
# File 'lib/logic_tools/logictree.rb', line 890

def size # :nodoc:
    1
end

#to_symObject

Converts to a symbol.



938
939
940
941
# File 'lib/logic_tools/logictree.rb', line 938

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