Class: Evilution::AST::Pattern::NodeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/ast/pattern/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_type, attributes) ⇒ NodeMatcher

Returns a new instance of NodeMatcher.



9
10
11
12
13
# File 'lib/evilution/ast/pattern/matcher.rb', line 9

def initialize(node_type, attributes)
  @node_type = node_type
  @prism_class = resolve_prism_class(node_type)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/evilution/ast/pattern/matcher.rb', line 7

def attributes
  @attributes
end

#node_typeObject (readonly)

Returns the value of attribute node_type.



7
8
9
# File 'lib/evilution/ast/pattern/matcher.rb', line 7

def node_type
  @node_type
end

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/evilution/ast/pattern/matcher.rb', line 15

def match?(node)
  return false unless node.is_a?(@prism_class)

  @attributes.all? { |attr_name, value_matcher| match_attribute?(node, attr_name, value_matcher) }
end