Class: LogicTools::NodeOr
- Defined in:
- lib/logic_tools/logictree.rb
Overview
Represents an OR node
Instance Attribute Summary
Attributes inherited from NodeNary
Instance Method Summary collapse
-
#clone ⇒ Object
Duplicates the node.
-
#eval ⇒ Object
Computes the value of the node.
-
#initialize(*children) ⇒ NodeOr
constructor
Creates a new OR node with
children. -
#to_s ⇒ Object
Converts to a string.
-
#to_sum_product(flattened = false) ⇒ Object
Creates a sum fo product from the tree rooted by current node.
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?, #eval_input, #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.
834 835 836 |
# File 'lib/logic_tools/logictree.rb', line 834 def initialize(*children) super(:or,*children) end |
Instance Method Details
#clone ⇒ Object
Duplicates the node.
839 840 841 |
# File 'lib/logic_tools/logictree.rb', line 839 def clone # :nodoc: return NodeOr.new(*@children.map(&:clone)) end |
#eval ⇒ Object
Computes the value of the node.
844 845 846 |
# File 'lib/logic_tools/logictree.rb', line 844 def eval return @children.any? {|child| child.eval() == true } end |
#to_s ⇒ Object
Converts to a string.
858 859 860 861 862 863 |
# File 'lib/logic_tools/logictree.rb', line 858 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
851 852 853 854 855 |
# File 'lib/logic_tools/logictree.rb', line 851 def to_sum_product(flattened = false) # :nodoc: # print "OR to_sum_product with tree=#{self}\n" return NodeOr.new( *@children.map {|child| child.to_sum_product(flattened) } ).flatten end |