Class: SexpPath::Matcher::Include

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

Overview

See SexpQueryBuilder.include

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(value) ⇒ Include

Creates a Matcher which will match any Sexp that contains the value



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

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#inspectObject



19
20
21
# File 'lib/sexp_path/matcher/include.rb', line 19

def inspect
  "include(#{value.inspect})"
end

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

Satisfied if a o is a Sexp and one of o‘s elements matches value

Returns:

  • (Boolean)


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

def satisfy?(o, data={})
  if o.is_a? Sexp
    return nil unless o.any?{|c| value.is_a?(Sexp) ? value.satisfy?(c, data) : value == c}
  end

  capture_match o, data
end