class Ovec::TextManipulator

Public Instance Methods

bind(chunks) click to toggle source

Subclasses, note: once you change the length of a chunk, delimiters will no longer be correct.

# File lib/ovec/text_manipulator.rb, line 5
def bind(chunks)
        @chunks = chunks
        @delimiters = [0]
        chunks.each do |chunk|
                @delimiters << @delimiters.last + chunk.length
        end

        _rejoin
end

Protected Instance Methods

_find_chunk_and_offset(offset) click to toggle source

Given an offset in the original string, returns the chunk and chunk offset that contains the refers to the same character.

# File lib/ovec/text_manipulator.rb, line 19
def _find_chunk_and_offset(offset)
        j = 0
        while j < @delimiters.size - 1
                break if @delimiters[j + 1] > offset
                j += 1
        end

        return [ @chunks[j], offset - @delimiters[j] ]
end
_rejoin() click to toggle source
# File lib/ovec/text_manipulator.rb, line 29
def _rejoin
        @joined = @chunks.join('')
end