Module: Predicate::Match

Includes:
Expr
Defined in:
lib/predicate/nodes/match.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  case_sensitive: true
}

Constants included from Expr

Expr::OP_NEGATIONS

Instance Method Summary collapse

Methods included from Expr

#!, #&, #and_split, #attr_split, #bind, #constant_variables, #constants, #contradiction?, #identifier?, #literal?, #opaque?, #qualify, #rename, #sexpr, #tautology?, #to_hash, #to_s, #to_sequel, #unqualify, #|

Methods included from Factory

#and, #between, #comp, #contradiction, #from_hash, #identifier, #in, #intersect, #literal, #match, #native, #not, #opaque, #or, #placeholder, #qualified_identifier, #tautology

Instance Method Details

#case_sentitive?Boolean



25
26
27
# File 'lib/predicate/nodes/match.rb', line 25

def case_sentitive?
  options[:case_sensitive]
end

#dyadic_priorityObject



33
34
35
# File 'lib/predicate/nodes/match.rb', line 33

def dyadic_priority
  800
end

#evaluate(tuple) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/predicate/nodes/match.rb', line 37

def evaluate(tuple)
  l = left.evaluate(tuple)
  r = right.evaluate(tuple)
  if l.nil? or r.nil?
    nil
  elsif l.is_a?(Regexp)
    l =~ r.to_s
  elsif r.is_a?(Regexp)
    r =~ l.to_s
  elsif options[:case_sensitive]
    l.to_s.include?(r.to_s)
  else
    l.to_s.downcase.include?(r.to_s.downcase)
  end
end

#free_variablesObject



29
30
31
# File 'lib/predicate/nodes/match.rb', line 29

def free_variables
  @free_variables ||= left.free_variables | right.free_variables
end

#leftObject



13
14
15
# File 'lib/predicate/nodes/match.rb', line 13

def left
  self[1]
end

#optionsObject



21
22
23
# File 'lib/predicate/nodes/match.rb', line 21

def options
  @options ||= DEFAULT_OPTIONS.merge(self[3] || {})
end

#priorityObject



9
10
11
# File 'lib/predicate/nodes/match.rb', line 9

def priority
  80
end

#rightObject



17
18
19
# File 'lib/predicate/nodes/match.rb', line 17

def right
  self[2]
end