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.
10 11 12 13 14 15 |
# File 'lib/nodegrep/matcher.rb', line 10 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
17 18 19 20 21 22 |
# File 'lib/nodegrep/matcher.rb', line 17 def matching_nodes(pattern) @matches = [] @pattern = RuboCop::NodePattern.new(pattern) visit_node(@parsed_source.ast) @matches end |