Class: SexpPath::Matcher::Type

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

Overview

See SexpQueryBuilder.t

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(type) ⇒ Type

Creates a Matcher which will match any Sexp who’s type is type, where a type is the first element in the Sexp.



7
8
9
# File 'lib/sexp_path/matcher/type.rb', line 7

def initialize(type)
  @sexp_type = type
end

Instance Attribute Details

#sexp_typeObject (readonly)

Returns the value of attribute sexp_type.



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

def sexp_type
  @sexp_type
end

Instance Method Details

#inspectObject



18
19
20
# File 'lib/sexp_path/matcher/type.rb', line 18

def inspect
  "t(#{sexp_type.inspect})"
end

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

Satisfied if the sexp_type of o is type.

Returns:

  • (Boolean)


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

def satisfy?(o, data={})
  return nil unless o.is_a?(Sexp) && o.sexp_type == sexp_type

  capture_match o, data
end