Class: LogicTools::NodeOr

Inherits:
NodeNary show all
Defined in:
lib/logic_tools/logictree.rb

Overview

Represents an OR node

Instance Attribute Summary

Attributes inherited from NodeNary

#op

Instance Method Summary collapse

Methods inherited from NodeNary

#==, #add, #cover?, #distribute, #each, #flatten, #flatten_deep, #get_variablesRecurse, #include?, #is_parent?, make, #reduce, #sort, #to_sym, #uniq

Methods inherited from Node

#cover?, #distribute, #each, #each_line, #each_maxterm, #each_minterm, #eql?, #flatten, #flatten_deep, #get_variables, #hash, #include?, #inspect, #is_parent?, #op, #reduce, #simplify, #size, #to_cover, #to_std_conjunctive, #to_std_disjunctive, #to_sym

Constructor Details

#initialize(*children) ⇒ NodeOr

Creates a new OR node with children.



807
808
809
# File 'lib/logic_tools/logictree.rb', line 807

def initialize(*children)
    super(:or,*children)
end

Instance Method Details

#dupObject

Duplicates the node.



812
813
814
# File 'lib/logic_tools/logictree.rb', line 812

def dup # :nodoc:
    return NodeOr.new(*@children.map(&:dup))
end

#evalObject

Computes the value of the node.



817
818
819
# File 'lib/logic_tools/logictree.rb', line 817

def eval
    return @children.any? {|child| child.eval() == true }
end

#to_sObject

Converts to a string.



830
831
832
833
834
835
# File 'lib/logic_tools/logictree.rb', line 830

def to_s # :nodoc:
    return @str if @str
    # Convert the children to string a insert "+" between them
    @str = @children.join("+")
    return @str
end

#to_sum_product(flattened = false) ⇒ Object

Creates a sum fo product from the tree rooted by current node.

Argument +flattened+ tells if the tree is already flattend


824
825
826
827
# File 'lib/logic_tools/logictree.rb', line 824

def to_sum_product(flattened = false) # :nodoc:
    return NodeOr.new(
        *@children.map {|child| child.to_sum_product(flatten) } )
end