Module: Predicate::Expr
- Includes:
- Factory
- Included in:
- BinaryFunc, Contradiction, DyadicComp, Exists, Identifier, In, Literal, NadicBool, Native, Not, Opaque, QualifiedIdentifier, SetOp, Tautology, UnaryFunc, Var
- Defined in:
- lib/predicate/sequel.rb,
lib/predicate/nodes/expr.rb,
lib/predicate/postgres/rewriter.rb
Constant Summary
collapse
- OP_NEGATIONS =
{
:eq => :neq,
:neq => :eq,
:lt => :gte,
:lte => :gt,
:gt => :lte,
:gte => :lt
}
Instance Method Summary
collapse
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, #tautology, #var, #vars
Instance Method Details
#! ⇒ Object
34
35
36
|
# File 'lib/predicate/nodes/expr.rb', line 34
def !
sexpr([:not, self])
end
|
#&(other) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/predicate/nodes/expr.rb', line 40
def &(other)
return other if other.contradiction?
return self if other.tautology?
return other & self if other.dyadic_priority > self.dyadic_priority
sexpr([:and, self, other])
end
|
#and_split(attr_list) ⇒ Object
53
54
55
56
|
# File 'lib/predicate/nodes/expr.rb', line 53
def and_split(attr_list)
(free_variables & attr_list).empty? ? [ tautology, self ] : [ self, tautology ]
end
|
#attr_split ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/predicate/nodes/expr.rb', line 58
def attr_split
if (vars = free_variables).size == 1
{ vars.first => self }
else
{ nil => self }
end
end
|
#bind(binding) ⇒ Object
82
83
84
|
# File 'lib/predicate/nodes/expr.rb', line 82
def bind(binding)
Binder.new(binding).call(self)
end
|
#constant_variables ⇒ Object
86
87
88
|
# File 'lib/predicate/nodes/expr.rb', line 86
def constant_variables
[]
end
|
#constants ⇒ Object
90
91
92
|
# File 'lib/predicate/nodes/expr.rb', line 90
def constants
{}
end
|
#contradiction? ⇒ Boolean
18
19
20
|
# File 'lib/predicate/nodes/expr.rb', line 18
def contradiction?
false
end
|
#dyadic_priority ⇒ Object
38
|
# File 'lib/predicate/nodes/expr.rb', line 38
def dyadic_priority; 0; end
|
#identifier? ⇒ Boolean
30
31
32
|
# File 'lib/predicate/nodes/expr.rb', line 30
def identifier?
sexpr_type == :identifier
end
|
#literal? ⇒ Boolean
22
23
24
|
# File 'lib/predicate/nodes/expr.rb', line 22
def literal?
sexpr_type == :literal
end
|
#opaque? ⇒ Boolean
26
27
28
|
# File 'lib/predicate/nodes/expr.rb', line 26
def opaque?
sexpr_type == :opaque
end
|
#qualify(qualifier) ⇒ Object
74
75
76
|
# File 'lib/predicate/nodes/expr.rb', line 74
def qualify(qualifier)
Qualifier.new(qualifier).call(self)
end
|
#rename(renaming) ⇒ Object
70
71
72
|
# File 'lib/predicate/nodes/expr.rb', line 70
def rename(renaming)
Renamer.call(self, :renaming => renaming)
end
|
#sexpr(arg) ⇒ Object
102
103
104
|
# File 'lib/predicate/nodes/expr.rb', line 102
def sexpr(arg)
Factory.sexpr(arg)
end
|
#tautology? ⇒ Boolean
14
15
16
|
# File 'lib/predicate/nodes/expr.rb', line 14
def tautology?
false
end
|
#to_hash ⇒ Object
98
99
100
|
# File 'lib/predicate/nodes/expr.rb', line 98
def to_hash
raise ArgumentError, "Unable to represent #{self} to a Hash"
end
|
#to_postgres(*args) ⇒ Object
41
42
43
|
# File 'lib/predicate/postgres/rewriter.rb', line 41
def to_postgres(*args)
Postgres::Rewriter.new(*args).call(self)
end
|
#to_s(scope = nil) ⇒ Object
94
95
96
|
# File 'lib/predicate/nodes/expr.rb', line 94
def to_s(scope = nil)
ToS.call(self, scope: scope)
end
|
#to_sequel ⇒ Object
5
6
7
|
# File 'lib/predicate/sequel.rb', line 5
def to_sequel
ToSequel.call(self)
end
|
#unqualify ⇒ Object
78
79
80
|
# File 'lib/predicate/nodes/expr.rb', line 78
def unqualify
Unqualifier.new.call(self)
end
|
#|(other) ⇒ Object
47
48
49
50
51
|
# File 'lib/predicate/nodes/expr.rb', line 47
def |(other)
return other if other.tautology?
return self if other.contradiction?
sexpr([:or, self, other])
end
|