Module: Predicate::Factory

Extended by:
Factory
Included in:
Predicate, Expr, Factory
Defined in:
lib/predicate/factory.rb

Instance Method Summary collapse

Instance Method Details

#and(left, right = nil) ⇒ Object



20
21
22
# File 'lib/predicate/factory.rb', line 20

def and(left, right = nil)
  _factor_predicate([:and, sexpr(left), sexpr(right)])
end

#between(middle, lower_bound, upper_bound) ⇒ Object



49
50
51
52
# File 'lib/predicate/factory.rb', line 49

def between(middle, lower_bound, upper_bound)
  _factor_predicate [:and, [:gte, sexpr(middle), sexpr(lower_bound)],
                           [:lte, sexpr(middle), sexpr(upper_bound)]]
end

#comp(op, h) ⇒ Object



38
39
40
# File 'lib/predicate/factory.rb', line 38

def comp(op, h)
  from_hash(h, op)
end

#contradictionObject



8
9
10
# File 'lib/predicate/factory.rb', line 8

def contradiction
  _factor_predicate([:contradiction, false])
end

#from_hash(h, op = :eq) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/predicate/factory.rb', line 54

def from_hash(h, op = :eq)
  if h.empty?
    tautology
  else
    terms = h.to_a.map{|(k,v)|
      if v.is_a?(Array)
        [:in, sexpr(k), v]
      else
        [op, sexpr(k), sexpr(v)]
      end
    }
    terms = terms.size == 1 ? terms.first : terms.unshift(:and)
    _factor_predicate terms
  end
end

#identifier(name) ⇒ Object



12
13
14
# File 'lib/predicate/factory.rb', line 12

def identifier(name)
  _factor_predicate([:identifier, name])
end

#in(identifier, values) ⇒ Object Also known as: among



32
33
34
35
# File 'lib/predicate/factory.rb', line 32

def in(identifier, values)
  identifier = sexpr(identifier) if identifier.is_a?(Symbol)
  _factor_predicate([:in, identifier, values])
end

#literal(literal) ⇒ Object



70
71
72
# File 'lib/predicate/factory.rb', line 70

def literal(literal)
  _factor_predicate([:literal, literal])
end

#native(arg) ⇒ Object



74
75
76
# File 'lib/predicate/factory.rb', line 74

def native(arg)
  _factor_predicate([:native, arg])
end

#not(operand) ⇒ Object



28
29
30
# File 'lib/predicate/factory.rb', line 28

def not(operand)
  _factor_predicate([:not, sexpr(operand)])
end

#or(left, right = nil) ⇒ Object



24
25
26
# File 'lib/predicate/factory.rb', line 24

def or(left, right = nil)
  _factor_predicate([:or, sexpr(left), sexpr(right)])
end

#qualified_identifier(qualifier, name) ⇒ Object



16
17
18
# File 'lib/predicate/factory.rb', line 16

def qualified_identifier(qualifier, name)
  _factor_predicate([:qualified_identifier, qualifier, name])
end

#tautologyObject



4
5
6
# File 'lib/predicate/factory.rb', line 4

def tautology
  _factor_predicate([:tautology, true])
end