predicate 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/predicate/nodes/expr.rb +5 -0
- data/lib/predicate/processors/to_s.rb +90 -0
- data/lib/predicate/processors.rb +1 -0
- data/lib/predicate/version.rb +1 -1
- data/lib/predicate.rb +4 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0640cc584c97fcc3284e49a237ed100eafb99b6
|
4
|
+
data.tar.gz: 477609b676466dd9e6a43e36740929e4ab660d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31a4d9754d7b1c7be5ecc4703cd2b1b6ecfdeab6616e736b3754e276c48468881b79420475d64aa5acf265007daf0fe3309fe3e2cc5fcf69cd6a15f150d67b18
|
7
|
+
data.tar.gz: 142229a63ac9c525b1fa90eaf6689a673db467ffd11b9b26c034d75d752ff93258198eb4030ca167effc75fde6573ab9e2a8ed9e4fc7b4e9e3729ff0a5e12e5a
|
data/lib/predicate/nodes/expr.rb
CHANGED
@@ -0,0 +1,90 @@
|
|
1
|
+
class Predicate
|
2
|
+
class ToS < Sexpr::Processor
|
3
|
+
|
4
|
+
def on_tautology(sexpr)
|
5
|
+
"true"
|
6
|
+
end
|
7
|
+
|
8
|
+
def on_contradiction(sexpr)
|
9
|
+
"false"
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_qualified_identifier(sexpr)
|
13
|
+
"#{sexpr.qualifier}.#{sexpr.name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_identifier(sexpr)
|
17
|
+
if s = options[:scope]
|
18
|
+
"#{s}.#{sexpr.last.to_s}"
|
19
|
+
else
|
20
|
+
"@#{sexpr.last.to_s}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_not(sexpr)
|
25
|
+
"not(" << apply(sexpr.last, sexpr) << ")"
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_and(sexpr)
|
29
|
+
sexpr.sexpr_body.map{|term|
|
30
|
+
apply(term, sexpr)
|
31
|
+
}.join(" AND ")
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_or(sexpr)
|
35
|
+
sexpr.sexpr_body.map{|term|
|
36
|
+
apply(term, sexpr)
|
37
|
+
}.join(" OR ")
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_dyadic(sexpr)
|
41
|
+
sexpr.sexpr_body.map{|term|
|
42
|
+
apply(term, sexpr)
|
43
|
+
}.join(" #{sexpr.operator_symbol} ")
|
44
|
+
end
|
45
|
+
alias :on_eq :on_dyadic
|
46
|
+
alias :on_neq :on_dyadic
|
47
|
+
alias :on_lt :on_dyadic
|
48
|
+
alias :on_lte :on_dyadic
|
49
|
+
alias :on_gt :on_dyadic
|
50
|
+
alias :on_gte :on_dyadic
|
51
|
+
|
52
|
+
def on_in(sexpr)
|
53
|
+
"#{apply(sexpr.identifier)} IN #{to_literal(sexpr.values)}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def on_intersect(sexpr)
|
57
|
+
"#{apply(sexpr.identifier)} INTERSECTS #{to_literal(sexpr.values)}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def on_literal(sexpr)
|
61
|
+
to_literal(sexpr.last)
|
62
|
+
end
|
63
|
+
|
64
|
+
def on_native(sexpr)
|
65
|
+
sexpr.last.inspect
|
66
|
+
end
|
67
|
+
|
68
|
+
def on_missing(sexpr)
|
69
|
+
raise "Unimplemented: #{sexpr.first}"
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
def to_literal(x)
|
75
|
+
case x
|
76
|
+
when Array then "{" << x.map{|y| to_literal(y) }.join(',') << "}"
|
77
|
+
else x.inspect
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def apply(sexpr, parent = nil)
|
82
|
+
code = super(sexpr)
|
83
|
+
if parent && (parent.priority >= sexpr.priority)
|
84
|
+
code = "(" << code << ")"
|
85
|
+
end
|
86
|
+
code
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
data/lib/predicate/processors.rb
CHANGED
data/lib/predicate/version.rb
CHANGED
data/lib/predicate.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: predicate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/predicate/processors/qualifier.rb
|
119
119
|
- lib/predicate/processors/renamer.rb
|
120
120
|
- lib/predicate/processors/to_ruby_code.rb
|
121
|
+
- lib/predicate/processors/to_s.rb
|
121
122
|
- lib/predicate/sequel.rb
|
122
123
|
- lib/predicate/sequel/to_sequel.rb
|
123
124
|
- lib/predicate/version.rb
|