Class: NodeGrep::Matcher
- Inherits:
-
Object
- Object
- NodeGrep::Matcher
- Defined in:
- lib/nodegrep/matcher.rb
Defined Under Namespace
Classes: SourceParseError
Instance Method Summary collapse
-
#initialize(source) ⇒ Matcher
constructor
A new instance of Matcher.
- #matching_nodes(pattern) ⇒ Object
Constructor Details
#initialize(source) ⇒ Matcher
Returns a new instance of Matcher.
8 9 10 11 12 13 |
# File 'lib/nodegrep/matcher.rb', line 8 def initialize(source) @parsed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION.to_f) @parsed_source.diagnostics.each do |d| raise SourceParseError if d.level == :error end end |
Instance Method Details
#matching_nodes(pattern) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/nodegrep/matcher.rb', line 15 def matching_nodes(pattern) @matches = [] @pattern = RuboCop::NodePattern.new(pattern) visit_node(@parsed_source.ast) @matches end |