Class: SexpPath::Matcher::Child

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

Overview

See SexpQueryBuilder.child

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(child) ⇒ Child

Create a Child matcher which will match anything having a descendant matching child.



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

def initialize(child)
  @child = child
end

Instance Attribute Details

#childObject (readonly)

Returns the value of attribute child.



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

def child
  @child
end

Instance Method Details

#inspectObject



21
22
23
# File 'lib/sexp_path/matcher/child.rb', line 21

def inspect
  "child(#{child.inspect})"
end

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

Satisfied if matches child or o has a descendant matching child.

Returns:

  • (Boolean)


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

def satisfy?(o, data={})
  if child.satisfy?(o,data)
    capture_match o, data
  elsif o.is_a? Sexp
    o.search_each(child,data) do 
      return capture_match(o, data)
    end
  end
end