Class: Metamorpher::Transformer::Site

Inherits:
Struct
  • Object
show all
Defined in:
lib/metamorpher/transformer/site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#original_codeObject

Returns the value of attribute original_code

Returns:

  • (Object)

    the current value of original_code



5
6
7
# File 'lib/metamorpher/transformer/site.rb', line 5

def original_code
  @original_code
end

#original_positionObject

Returns the value of attribute original_position

Returns:

  • (Object)

    the current value of original_position



5
6
7
# File 'lib/metamorpher/transformer/site.rb', line 5

def original_position
  @original_position
end

#transformed_codeObject

Returns the value of attribute transformed_code

Returns:

  • (Object)

    the current value of transformed_code



5
6
7
# File 'lib/metamorpher/transformer/site.rb', line 5

def transformed_code
  @transformed_code
end

Instance Method Details

#<=>(other) ⇒ Object



24
25
26
# File 'lib/metamorpher/transformer/site.rb', line 24

def <=>(other)
  original_position.begin <=> other.original_position.begin
end

#merge_into(destination) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/metamorpher/transformer/site.rb', line 11

def merge_into(destination)
  if original_position.begin > destination.size
    fail ArgumentError, "Position #{original_position} does not exist in: #{destination}"
  end

  destination[original_position] = transformed_code
  destination
end

#offsetObject



20
21
22
# File 'lib/metamorpher/transformer/site.rb', line 20

def offset
  transformed_code.size - original_code.size
end

#slide(offset) ⇒ Object



6
7
8
9
# File 'lib/metamorpher/transformer/site.rb', line 6

def slide(offset)
  new_position = (original_position.begin + offset)..(original_position.end + offset)
  Site.new(new_position, original_code, transformed_code)
end