Sha256: 969b6621de36de6d25dc2c7a14c99b621f4c4dbb2f57646864f2e7c6fa7db098
Contents?: true
Size: 2 KB
Versions: 12
Compression:
Stored size: 2 KB
Contents
# frozen_string_literal: true module Vedeu module Editor # Manipulate the lines of an Vedeu::Editor::Document. # # @api private # class Delete include Vedeu::Common # @param (see #initialize) # @return [Vedeu::Editor::Line|Vedeu::Editor::Lines] def self.from(collection, index = nil, size = 0) new(collection, index, size).delete end # Returns a new instance of Vedeu::Editor::Delete. # # @param collection [Vedeu::Editor::Line|Vedeu::Editor::Lines] # @param index [Fixnum] # @param size [Fixnum] # @return [Vedeu::Editor::Delete] def initialize(collection, index = nil, size = 0) @collection = collection @index = index @size = size end # @return [Vedeu::Editor::Line|Vedeu::Editor::Lines] def delete return collection if collection.empty? || negative_index? return collection.dup.tap { |c| c.slice!(index) } if index return collection.dup.tap(&:pop) if lines? return collection.chop if line? end protected # @!attribute [r] collection # @return [Vedeu::Editor::Line|Vedeu::Editor::Lines] attr_reader :collection # @!attribute [r] size # @return [Fixnum] attr_reader :size private # @return [Fixnum] def index return nil unless @index @index = size - 1 if @index > size @index end # If true, we are dealing with a {Vedeu::Editor::Line} object. # # @return [Boolean] def line? string?(collection) end # If true, we are dealing with a {Vedeu::Editor::Lines} # collection. # # @return [Boolean] def lines? collection.is_a?(Array) end # Returns a boolean indicating whether the index was given or # negative. # # @return [Boolean] def negative_index? index && index < 0 end end # Delete end # Editor end # Vedeu
Version data entries
12 entries across 12 versions & 1 rubygems