Sha256: 23449dc7a0fa77f58b216a3e57027a9e978279613e69992ba7c8ce6ce730e472
Contents?: true
Size: 1.07 KB
Versions: 5
Compression:
Stored size: 1.07 KB
Contents
# encoding: utf-8 module Synvert::Core # Scope finds the child nodes which match rules. class Rewriter::Scope # Initialize a scope # # @param instance [Synvert::Core::Rewriter::Instance] # @param rules [Hash] # @param block [Block] def initialize(instance, rules, &block) @instance = instance @rules = rules @block = block end # Find the matching nodes. It checks the current node and iterates all child nodes, # then run the block code for each matching node. def process current_node = @instance.current_node return unless current_node @instance.process_with_node current_node do matching_nodes = [] matching_nodes << current_node if current_node.match? @rules current_node.recursive_children do |child_node| matching_nodes << child_node if child_node.match? @rules end matching_nodes.each do |matching_node| @instance.process_with_node matching_node do @instance.instance_eval &@block end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems