class Predicate

Constants

Grammar
SexprLike
TupleLike
VERSION

Attributes

expr[R]
sexpr[R]

Public Class Methods

coerce(arg) click to toggle source
# File lib/predicate.rb, line 30
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
Also aliased as: parse
currying(var = var(".", :dig), &bl) click to toggle source
# File lib/predicate.rb, line 48
def currying(var = var(".", :dig), &bl)
  Predicate::Dsl.new(var, true).instance_eval(&bl)
end
dsl(var = var(".", :dig), &bl) click to toggle source
# File lib/predicate.rb, line 44
def dsl(var = var(".", :dig), &bl)
  Predicate::Dsl.new(var, false).instance_eval(&bl)
end
new(sexpr) click to toggle source
# File lib/predicate.rb, line 20
def initialize(sexpr)
  @sexpr = sexpr
end
parse(arg)
Alias for: coerce

Private Class Methods

_factor_predicate(arg) click to toggle source
# File lib/predicate.rb, line 54
def _factor_predicate(arg)
  Predicate.new Grammar.sexpr(arg)
end

Public Instance Methods

!() click to toggle source
# File lib/predicate.rb, line 96
def !
  Predicate.new(!expr)
end
&(other) click to toggle source
# File lib/predicate.rb, line 84
def &(other)
  return self  if other.tautology? or other==self
  return other if tautology?
  Predicate.new(expr & other.expr)
end
==(other) click to toggle source
# File lib/predicate.rb, line 145
def ==(other)
  other.is_a?(Predicate) && (other.expr==expr)
end
Also aliased as: eql?
and_split(attr_list) click to toggle source

Splits this predicate, say P, as too predicates P1 & P2 such that `P <=> P1 & P2` and P2 makes no reference to any attribute in `attr_list`.

# File lib/predicate.rb, line 127
def and_split(attr_list)
  expr.and_split(attr_list).map{|e| Predicate.new(e)}
end
attr_split() click to toggle source

Returns a hash `(attr -> Pattr)` associating attribute names to predicates, so that each predicate `Pattr` only makes reference to the corresponding attribute name `attr`, while the conjunction of `Pattr`s is still equivalent to the original predicate.

A `nil` key may map a predicate that still makes references to more than one attribute.

# File lib/predicate.rb, line 139
def attr_split
  expr.attr_split.each_pair.each_with_object({}) do |(k,v),h|
    h[k] = Predicate.new(v)
  end
end
bind(binding) click to toggle source
# File lib/predicate.rb, line 112
def bind(binding)
  Predicate.new(expr.bind(binding))
end
call(tuple) click to toggle source
# File lib/predicate.rb, line 120
def call(tuple)
  expr.evaluate(tuple)
end
constant_variables() click to toggle source
# File lib/predicate.rb, line 76
def constant_variables
  expr.constant_variables
end
constants() click to toggle source
# File lib/predicate.rb, line 80
def constants
  expr.constants
end
contradiction() click to toggle source

Factors a Predicate that captures False

# File lib/predicate/factory.rb, line 12
def contradiction
  _factor_predicate([:contradiction, false])
end
contradiction?() click to toggle source
# File lib/predicate.rb, line 68
def contradiction?
  expr.contradiction?
end
eql?(other)
Alias for: ==
evaluate(tuple) click to toggle source
# File lib/predicate.rb, line 116
def evaluate(tuple)
  expr.evaluate(tuple)
end
free_variables() click to toggle source
# File lib/predicate.rb, line 72
def free_variables
  expr.free_variables
end
hash() click to toggle source
# File lib/predicate.rb, line 150
def hash
  expr.hash
end
native?() click to toggle source
# File lib/predicate.rb, line 60
def native?
  Native===expr
end
qualify(qualifier) click to toggle source
# File lib/predicate.rb, line 100
def qualify(qualifier)
  Predicate.new(expr.qualify(qualifier))
end
rename(renaming) click to toggle source
# File lib/predicate.rb, line 108
def rename(renaming)
  Predicate.new(expr.rename(renaming))
end
tautology?() click to toggle source
# File lib/predicate.rb, line 64
def tautology?
  expr.tautology?
end
to_hash() click to toggle source

If possible, converts this predicate back to a `{ attr: value, … }` hash. Raises an IllegalArgumentError if the predicate cannot be represented that way.

# File lib/predicate.rb, line 161
def to_hash
  expr.to_hash
end
to_s(scope = nil) click to toggle source
# File lib/predicate.rb, line 154
def to_s(scope = nil)
  expr.to_s(scope)
end
to_sequel() click to toggle source
# File lib/predicate/sequel.rb, line 11
def to_sequel
  expr.to_sequel
end
unqualify() click to toggle source
# File lib/predicate.rb, line 104
def unqualify
  Predicate.new(expr.unqualify)
end
|(other) click to toggle source
# File lib/predicate.rb, line 90
def |(other)
  return self  if other.contradiction? or other==self
  return other if contradiction?
  Predicate.new(expr | other.expr)
end