Sha256: ef32c8fa2c62e55f77f3867c52b691efc35871cd8f7191ccce7f373bfc8d6705
Contents?: true
Size: 1.8 KB
Versions: 31
Compression:
Stored size: 1.8 KB
Contents
# frozen_string_literal: true module Vedeu module Editor # Manipulate the lines of an Vedeu::Editor::Document. # # @api private # class Insert include Vedeu::Common # @param (see #initialize) # @return (see #insert) def self.into(collection, entity, index = nil, size = 0) new(collection, entity, index, size).insert end # Returns a new instance of Vedeu::Editor::Insert. # # @param collection [String|Vedeu::Editor::Line|Vedeu::Editor::Lines] # @param entity [String] # @param index [Fixnum] # @param size [Fixnum] # @return [Vedeu::Editor::Insert] def initialize(collection, entity, index = nil, size = 0) @collection = collection @entity = entity @index = index @size = size end # @return [String|Vedeu::Editor::Line|Vedeu::Editor::Lines] def insert return collection.insert(position, entity) if index? collection << entity end protected # @!attribute [r] entity # @return [String] attr_reader :entity # @!attribute [r] index # @return [Fixnum] attr_reader :index # @!attribute [r] size # @return [Fixnum] attr_reader :size private # @!attribute [r] collection # @return [String|Vedeu::Editor::Line|Vedeu::Editor::Lines] def collection if string?(@collection) @collection.dup else @collection end end # @return [Boolean] def index? numeric?(index) end # @return [Fixnum] def position if index < 0 0 elsif index > size size else index end end end # Insert end # Editor end # Vedeu
Version data entries
31 entries across 31 versions & 1 rubygems