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?, #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.
809 810 811 |
# File 'lib/logic_tools/logictree.rb', line 809 def initialize(*children) super(:or,*children) end |
Instance Method Details
#clone ⇒ Object
Duplicates the node.
814 815 816 |
# File 'lib/logic_tools/logictree.rb', line 814 def clone # :nodoc: return NodeOr.new(*@children.map(&:clone)) end |
#eval ⇒ Object
Computes the value of the node.
819 820 821 |
# File 'lib/logic_tools/logictree.rb', line 819 def eval return @children.any? {|child| child.eval() == true } end |
#to_s ⇒ Object
Converts to a string.
832 833 834 835 836 837 |
# File 'lib/logic_tools/logictree.rb', line 832 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
826 827 828 829 |
# File 'lib/logic_tools/logictree.rb', line 826 def to_sum_product(flattened = false) # :nodoc: return NodeOr.new( *@children.map {|child| child.to_sum_product(flatten) } ) end |