Sha256: c3371c0079999b062cd72d1aa1f8297b127174bee7f331f7220f74337732a1f1

Contents?: true

Size: 851 Bytes

Versions: 32

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  # ReplaceAction to replace child node with code.
  class Rewriter::ReplaceAction < Rewriter::Action
    def initialize(instance, *selectors, with:)
      @instance = instance
      @selectors = selectors
      @code = with
      @node = @instance.current_node
    end

    # Begin position of code to replace.
    #
    # @return [Integer] begin position.
    def begin_pos
      @selectors.map { |selector| @node.child_node_range(selector).begin_pos }.min
    end

    # End position of code to replace.
    #
    # @return [Integer] end position.
    def end_pos
      @selectors.map { |selector| @node.child_node_range(selector).end_pos }.max
    end

    # The rewritten source code.
    #
    # @return [String] rewritten code.
    def rewritten_code
      rewritten_source
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
synvert-core-0.51.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.50.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.49.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.49.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.48.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.47.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.46.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.45.2 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.45.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.45.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.44.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.44.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.42.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.42.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.41.2 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.41.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.41.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.40.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.39.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.38.0 lib/synvert/core/rewriter/action/replace_action.rb