Class: Predicate
- Inherits:
-
Object
show all
- Extended by:
- Factory
- Defined in:
- lib/predicate.rb,
lib/predicate/sequel.rb,
lib/predicate/factory.rb,
lib/predicate/grammar.rb,
lib/predicate/version.rb,
lib/predicate/nodes/eq.rb,
lib/predicate/nodes/gt.rb,
lib/predicate/nodes/in.rb,
lib/predicate/nodes/lt.rb,
lib/predicate/nodes/or.rb,
lib/predicate/nodes/and.rb,
lib/predicate/nodes/gte.rb,
lib/predicate/nodes/lte.rb,
lib/predicate/nodes/neq.rb,
lib/predicate/nodes/not.rb,
lib/predicate/nodes/expr.rb,
lib/predicate/nodes/native.rb,
lib/predicate/nodes/literal.rb,
lib/predicate/nodes/tautology.rb,
lib/predicate/nodes/identifier.rb,
lib/predicate/nodes/nadic_bool.rb,
lib/predicate/sequel/to_sequel.rb,
lib/predicate/nodes/dyadic_comp.rb,
lib/predicate/processors/renamer.rb,
lib/predicate/nodes/contradiction.rb,
lib/predicate/processors/qualifier.rb,
lib/predicate/processors/to_ruby_code.rb,
lib/predicate/nodes/qualified_identifier.rb
Defined Under Namespace
Modules: And, Contradiction, DyadicComp, Eq, Expr, Factory, Grammar, Gt, Gte, Identifier, In, Literal, Lt, Lte, NadicBool, Native, Neq, Not, Or, QualifiedIdentifier, Tautology, Version
Classes: NotSupportedError, Qualifier, Renamer, ToRubyCode, ToSequel
Constant Summary
collapse
- TupleLike =
->(t){ t.is_a?(Hash) }
- VERSION =
"#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
Instance Attribute Summary collapse
-
#sexpr ⇒ Object
(also: #expr)
readonly
Returns the value of attribute sexpr.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Factory
and, between, comp, contradiction, from_hash, identifier, in, literal, native, not, or, qualified_identifier, tautology
Constructor Details
#initialize(sexpr) ⇒ Predicate
Returns a new instance of Predicate.
12
13
14
|
# File 'lib/predicate.rb', line 12
def initialize(sexpr)
@sexpr = sexpr
end
|
Instance Attribute Details
#sexpr ⇒ Object
Also known as:
expr
Returns the value of attribute sexpr.
15
16
17
|
# File 'lib/predicate.rb', line 15
def sexpr
@sexpr
end
|
Class Method Details
.coerce(arg) ⇒ Object
Also known as:
parse
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/predicate.rb', line 21
def coerce(arg)
case arg
when Predicate then arg
when TrueClass then tautology
when FalseClass then contradiction
when Symbol then identifier(arg)
when Proc then native(arg)
when Hash then from_hash(arg)
else
raise ArgumentError, "Unable to coerce `#{arg}` to a predicate"
end
end
|
Instance Method Details
#! ⇒ Object
75
76
77
|
# File 'lib/predicate.rb', line 75
def !
Predicate.new(!expr)
end
|
#&(other) ⇒ Object
63
64
65
66
67
|
# File 'lib/predicate.rb', line 63
def &(other)
return self if other.tautology? or other==self
return other if tautology?
Predicate.new(expr & other.expr)
end
|
#==(other) ⇒ Object
Also known as:
eql?
95
96
97
|
# File 'lib/predicate.rb', line 95
def ==(other)
other.is_a?(Predicate) && (other.expr==expr)
end
|
#and_split(attr_list) ⇒ Object
91
92
93
|
# File 'lib/predicate.rb', line 91
def and_split(attr_list)
expr.and_split(attr_list).map{|e| Predicate.new(e)}
end
|
#constant_variables ⇒ Object
59
60
61
|
# File 'lib/predicate.rb', line 59
def constant_variables
expr.constant_variables
end
|
#contradiction? ⇒ Boolean
51
52
53
|
# File 'lib/predicate.rb', line 51
def contradiction?
expr.contradiction?
end
|
#evaluate(tuple) ⇒ Object
87
88
89
|
# File 'lib/predicate.rb', line 87
def evaluate(tuple)
to_proc.call(tuple)
end
|
#free_variables ⇒ Object
55
56
57
|
# File 'lib/predicate.rb', line 55
def free_variables
expr.free_variables
end
|
#hash ⇒ Object
100
101
102
|
# File 'lib/predicate.rb', line 100
def hash
expr.hash
end
|
#native? ⇒ Boolean
43
44
45
|
# File 'lib/predicate.rb', line 43
def native?
Native===expr
end
|
#qualify(qualifier) ⇒ Object
79
80
81
|
# File 'lib/predicate.rb', line 79
def qualify(qualifier)
Predicate.new(expr.qualify(qualifier))
end
|
#rename(renaming) ⇒ Object
83
84
85
|
# File 'lib/predicate.rb', line 83
def rename(renaming)
Predicate.new(expr.rename(renaming))
end
|
#tautology? ⇒ Boolean
47
48
49
|
# File 'lib/predicate.rb', line 47
def tautology?
expr.tautology?
end
|
#to_proc ⇒ Object
109
110
111
|
# File 'lib/predicate.rb', line 109
def to_proc
@proc ||= expr.to_proc("t")
end
|
#to_ruby_code(scope = "t") ⇒ Object
Also known as:
to_s
104
105
106
|
# File 'lib/predicate.rb', line 104
def to_ruby_code(scope = "t")
expr.to_ruby_code(scope)
end
|
#to_sequel ⇒ Object
11
12
13
|
# File 'lib/predicate/sequel.rb', line 11
def to_sequel
expr.to_sequel
end
|
#|(other) ⇒ Object
69
70
71
72
73
|
# File 'lib/predicate.rb', line 69
def |(other)
return self if other.contradiction? or other==self
return other if contradiction?
Predicate.new(expr | other.expr)
end
|