Module: Predicate::Eq

Includes:
DyadicComp
Defined in:
lib/predicate/nodes/eq.rb

Constant Summary

Constants included from Expr

Predicate::Expr::OP_NEGATIONS

Instance Method Summary collapse

Methods included from DyadicComp

#!, #free_variables, #left, #priority, #right, #var_against_literal_value?

Methods included from Expr

#!, #and_split, #attr_split, #bind, #contradiction?, #identifier?, #literal?, #opaque?, #qualify, #rename, #sexpr, #tautology?, #to_postgres, #to_s, #to_sequel, #unqualify, #|

Methods included from Factory

#_factor_predicate, #and, #comp, #contradiction, #empty, #from_hash, #h, #has_size, #identifier, #in, #literal, #match, #native, #not, #opaque, #or, #pg_array_empty, #pg_array_literal, #pg_array_overlaps, #placeholder, #qualified_identifier, #sexpr, #tautology, #var, #vars

Instance Method Details

#&(other) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/predicate/nodes/eq.rb', line 9

def &(other)
  return super unless free_variables == other.free_variables
  case other
  when Eq
    return self if constants == other.constants
    return contradiction
  when In
    return super unless var_against_literal_value? && other.var_against_literal_value?
    mine, hers = self.right.value, other.right.value
    return self if hers.include?(mine)
    contradiction
  else
    super
  end
rescue NotSupportedError
  super
end

#constant_variablesObject



27
28
29
30
# File 'lib/predicate/nodes/eq.rb', line 27

def constant_variables
  fv = free_variables
  fv.size == 1 ? fv : []
end

#constantsObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/predicate/nodes/eq.rb', line 32

def constants
  left, right = sexpr(self.left), sexpr(self.right)
  if left.identifier? && right.literal? && !right.has_placeholder?
    { left.name => right.value }
  elsif right.identifier? && left.literal? && !left.has_placeholder?
    { right.name => left.value }
  else
    {}
  end
end

#dyadic_priorityObject



43
# File 'lib/predicate/nodes/eq.rb', line 43

def dyadic_priority; 900; end

#evaluate(tuple) ⇒ Object



45
46
47
# File 'lib/predicate/nodes/eq.rb', line 45

def evaluate(tuple)
  left.evaluate(tuple) == right.evaluate(tuple)
end

#operator_symbolObject



5
6
7
# File 'lib/predicate/nodes/eq.rb', line 5

def operator_symbol
  :==
end

#to_hashObject



49
50
51
52
53
54
55
56
57
# File 'lib/predicate/nodes/eq.rb', line 49

def to_hash
  if left.identifier? && right.literal? && !right.has_placeholder?
    { left.name => right.value }
  elsif right.identifier? && left.literal? && !left.has_placeholder?
    { right.name => left.value }
  else
    super
  end
end