Sha256: 7b8773e0b4b131160ef020338d156c8522812fba98c08f1edfb8375fe923dc5d

Contents?: true

Size: 796 Bytes

Versions: 11

Compression:

Stored size: 796 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:)
      super(instance, with)
      @selectors = selectors
    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

11 entries across 11 versions & 1 rubygems

Version Path
synvert-core-0.56.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.56.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.55.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.54.3 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.54.2 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.54.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.54.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.53.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.52.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.52.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-0.51.1 lib/synvert/core/rewriter/action/replace_action.rb