Class: SexpPath::Matcher::Pattern

Inherits:
Base
  • Object
show all
Defined in:
lib/sexp_path/matcher/pattern.rb

Overview

See SexpQueryBuilder.m

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#&, #-@, #>>, #|

Methods included from Traverse

#capture_as, #replace_sexp, #search, #search_each

Constructor Details

#initialize(pattern) ⇒ Pattern

Create a Patten matcher which will match any atom that either matches the input pattern.



6
7
8
# File 'lib/sexp_path/matcher/pattern.rb', line 6

def initialize(pattern)
  @pattern = pattern
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



3
4
5
# File 'lib/sexp_path/matcher/pattern.rb', line 3

def pattern
  @pattern
end

Instance Method Details

#inspectObject



17
18
19
# File 'lib/sexp_path/matcher/pattern.rb', line 17

def inspect
  "m(#{pattern.inspect})"
end

#satisfy?(o, data = {}) ⇒ Boolean

Satisfied if o is an atom, and o matches pattern

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/sexp_path/matcher/pattern.rb', line 11

def satisfy?(o, data={})
  return nil unless !o.is_a?(Sexp) && o.to_s =~ pattern

  capture_match o, data
end