Method: Parse::MapPosition#map_from

Defined in:
lib/parse/map_position.rb

#map_from(pos_b, new_pos_b) ⇒ self

Before:

  • m[pos1] == pos2

After:

  • m[pos1] == new_pos_b.advance(pos1 |-| pos_b) if pos1 >= pos_b

  • m[pos1] == pos2 otherwise

Here pos_m |-| pos_n is the number of characters between pos_m and pos_n; p.advance(n) is p advanced by n characters.

This method can not be called with pos_b with different Position#files!

Parameters:

  • pos_b (Position)
  • new_pos_b (Position)

Returns:

  • (self)


50
51
52
53
54
# File 'lib/parse/map_position.rb', line 50

def map_from(pos_b, new_pos_b)
  raise "can not call this method with different Position#file (was `#{@mappings.first.pos_b.file}' but `#{pos_b.file}' specified)" if not @mappings.empty? and @mappings.first.pos_b.file != pos_b.file
  pos_b_idx = @mappings.bsearch_index { |mapping| mapping.pos_b >= pos_b } || @mappings.size
  @mappings[pos_b_idx..-1] = [Mapping[pos_b, new_pos_b]]
end