Class: Synvert::Core::Rewriter::ReplaceWithAction

Inherits:
Action
  • Object
show all
Defined in:
lib/synvert/core/rewriter/action/replace_with_action.rb

Overview

ReplaceWithAction to replace code.

Constant Summary

Constants inherited from Action

Action::DEFAULT_INDENT

Instance Attribute Summary

Attributes inherited from Action

#begin_pos, #end_pos

Instance Method Summary collapse

Methods inherited from Action

#initialize, #line, #process

Constructor Details

This class inherits a constructor from Synvert::Core::Rewriter::Action

Instance Method Details

#calculate_positionObject



6
7
8
9
# File 'lib/synvert/core/rewriter/action/replace_with_action.rb', line 6

def calculate_position
  @begin_pos = @node.loc.expression.begin_pos
  @end_pos = @node.loc.expression.end_pos
end

#rewritten_codeString

The rewritten source code with proper indent.

Returns:

  • (String)

    rewritten code.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/synvert/core/rewriter/action/replace_with_action.rb', line 14

def rewritten_code
  if rewritten_source.include?("\n")
    new_code = []
    rewritten_source.split("\n").each_with_index do |line, index|
      new_code << (index == 0 ? line : indent + line)
    end
    new_code.join("\n")
  else
    rewritten_source
  end
end