module Predicate::And
Public Instance Methods
&(other)
click to toggle source
# File lib/predicate/nodes/and.rb, line 9 def &(other) case other when Tautology then self when Contradiction then other when And then sexpr(dup + other[1..-1]) else dup << other end end
and_split(attr_list)
click to toggle source
# File lib/predicate/nodes/and.rb, line 18 def and_split(attr_list) # Say we are X = X1 & X2 & X3 # We will split each term: X = (X1 & Y1) & (X2 & Y2) & (X3 & Y3) # ... such that Y1, Y2, and Y2 makes no reference to attr_list # ... which is equivalent to (X1 & X2 & X3) & (Y1 & Y2 & Y3) # ... hence P1 & P2, that we return sexpr_body.inject([tautology, tautology]) do |(top,down),term| p1, p2 = term.and_split(attr_list) [top & p1, down & p2] end end
attr_split()
click to toggle source
# File lib/predicate/nodes/and.rb, line 30 def attr_split # Similar to and_split above, but the reasonning applies on # attribute names this time. sexpr_body.each_with_object({}) do |term, h| term.attr_split.each_pair do |a,p| h[a] = (h[a] || tautology) & p end end end
constant_variables()
click to toggle source
# File lib/predicate/nodes/and.rb, line 40 def constant_variables sexpr_body.inject([]) do |cvars,expr| cvars | expr.constant_variables end end
constants()
click to toggle source
# File lib/predicate/nodes/and.rb, line 46 def constants sexpr_body.each_with_object({}) do |op, cs| cs.merge!(op.constants){|k,v1,v2| v1 } end end
evaluate(tuple)
click to toggle source
# File lib/predicate/nodes/and.rb, line 52 def evaluate(tuple) sexpr_body.all?{|operand| operand.evaluate(tuple) } end
operator_symbol()
click to toggle source
# File lib/predicate/nodes/and.rb, line 5 def operator_symbol :'&&' end
to_hash()
click to toggle source
Calls superclass method
# File lib/predicate/nodes/and.rb, line 56 def to_hash sexpr_body.inject({}) do |p,term| p.merge(term.to_hash){|k,v1,v2| super unless v1 == v2 v1 } end end