Class: SexpPath::Matcher::Base
- Defined in:
- lib/sexp_path/matcher/base.rb
Overview
This is the base class for all Sexp matchers.
A matcher should implement the following methods:
-
satisfy?
-
inspect
satisfy?
determines whether the matcher matches a given input, and inspect
will print the matcher nicely in a user’s console.
The base matcher is created with the SexpQueryBuilder as follows
Q?{ s() }
Instance Method Summary collapse
-
#&(o) ⇒ Object
Combines the Matcher with another Matcher, the resulting one will be satisfied only if both Matchers would be satisfied.
-
#-@ ⇒ Object
Returns a Matcher that matches whenever this Matcher would not have matched.
-
#>>(o) ⇒ Object
Returns a Matcher that matches if this has a sibling
o
. -
#inspect ⇒ Object
Formats the matcher as: q(:a, :b).
-
#|(o) ⇒ Object
Combines the Matcher with another Matcher, the resulting one will be satisfied if either Matcher would be satisfied.
Methods inherited from Sexp
Methods included from Traverse
#capture_as, #replace_sexp, #search, #search_each
Instance Method Details
#&(o) ⇒ Object
Combines the Matcher with another Matcher, the resulting one will be satisfied only if both Matchers would be satisfied.
Example:
t(:a) & include(:b)
28 29 30 |
# File 'lib/sexp_path/matcher/base.rb', line 28 def & o SexpPath::Matcher::All.new(self, o) end |
#-@ ⇒ Object
Returns a Matcher that matches whenever this Matcher would not have matched
Example:
-s(:a)
36 37 38 |
# File 'lib/sexp_path/matcher/base.rb', line 36 def -@ SexpPath::Matcher::Not.new(self) end |
#>>(o) ⇒ Object
Returns a Matcher that matches if this has a sibling o
Example:
s(:a) >> s(:b)
44 45 46 |
# File 'lib/sexp_path/matcher/base.rb', line 44 def >> o SexpPath::Matcher::Sibling.new(self, o) end |
#inspect ⇒ Object
Formats the matcher as:
q(:a, :b)
50 51 52 53 |
# File 'lib/sexp_path/matcher/base.rb', line 50 def inspect children = map{|e| e.inspect}.join(', ') "q(#{children})" end |