Class: Parser::Source::Rewriter::Action Private

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/parser/source/rewriter/action.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range, replacement = '', allow_multiple_insertions = false, order = 0) ⇒ Action

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Action.



15
16
17
18
19
20
21
22
# File 'lib/parser/source/rewriter/action.rb', line 15

def initialize(range, replacement='', allow_multiple_insertions = false, order = 0)
  @range = range
  @replacement = replacement
  @allow_multiple_insertions = allow_multiple_insertions
  @order = order

  freeze
end

Instance Attribute Details

#allow_multiple_insertionsObject (readonly) Also known as: allow_multiple_insertions?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/parser/source/rewriter/action.rb', line 12

def allow_multiple_insertions
  @allow_multiple_insertions
end

#orderObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/parser/source/rewriter/action.rb', line 12

def order
  @order
end

#rangeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/parser/source/rewriter/action.rb', line 12

def range
  @range
end

#replacementObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/parser/source/rewriter/action.rb', line 12

def replacement
  @replacement
end

Instance Method Details

#<=>(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
# File 'lib/parser/source/rewriter/action.rb', line 24

def <=>(other)
  result = range.begin_pos <=> other.range.begin_pos
  return result unless result.zero?
  order <=> other.order
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/parser/source/rewriter/action.rb', line 30

def to_s
  if @range.length == 0 && @replacement.empty?
    'do nothing'
  elsif @range.length == 0
    "insert #{@replacement.inspect}"
  elsif @replacement.empty?
    "remove #{@range.length} character(s)"
  else
    "replace #{@range.length} character(s) with #{@replacement.inspect}"
  end
end