Class: SexpPath::Matcher::Any

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

Overview

See SexpQueryBuilder.any

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(*options) ⇒ Any

Create an Any matcher which will match any of the options.



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

def initialize(*options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#inspectObject



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

def inspect
  options.map{|o| o.inspect}.join(' | ')
end

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

Satisfied when any sub expressions match o

Returns:

  • (Boolean)


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

def satisfy?(o, data={})
  return nil unless options.any?{|exp| exp.is_a?(Sexp) ? exp.satisfy?(o, data) : exp == o}

  capture_match o, data
end