Sha256: d7b893c205e17c9484f0f90ff53a154ec55b6e9ac4c3ec962b7da4bc0b275254
Contents?: true
Size: 1.98 KB
Versions: 15
Compression:
Stored size: 1.98 KB
Contents
module Vedeu module Editor # Manipulate a single line of an Vedeu::Editor::Document. # # @api private # class Line include Vedeu::Editor::Collection # @!attribute [rw] collection # @return [String] attr_accessor :collection alias_method :line, :collection alias_method :to_s, :collection # Coerce a line into a new instance of Vedeu::Editor::Line. # # @param collection [String|Vedeu::Editor::Line] # @return (see #initialize) def self.coerce(collection) return collection if collection.is_a?(self) return new(collection) if collection.is_a?(String) new end # Returns a new instance of Vedeu::Editor::Line. # # @param collection [String|NilClass] # @return [Vedeu::Editor::Line] def initialize(collection = nil) @collection = collection || '' end # Return the character at the given index. # # @param index [Fixnum|NilClass] # @return [String|NilClass] def character(index = nil) return '' if collection && collection.empty? return collection[-1] unless index by_index(index) end # Delete the character from the line positioned at the given # index. # # @param index [Fixnum|NilClass] # @return [String] def delete_character(index = nil) Vedeu::Editor::Line.coerce(Vedeu::Editor::Delete .from(line, index, size)) end # Insert the character on the line positioned at the given # index. # # @param character [String] # @param index [Fixnum|NilClass] # @return [Vedeu::Editor::Line] def insert_character(character, index = nil) return self unless character Vedeu::Editor::Line.coerce(Vedeu::Editor::Insert .into(collection, character, index, size)) end end # Line end # Editor end # Vedeu
Version data entries
15 entries across 15 versions & 1 rubygems