Class: Vedeu::Editor::Delete Private

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/vedeu/editor/delete.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Manipulate the lines of an Vedeu::Editor::Document.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Constructor Details

#initialize(collection, index = nil, size = 0) ⇒ Vedeu::Editor::Delete

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Vedeu::Editor::Delete.

Parameters:



27
28
29
30
31
# File 'lib/vedeu/editor/delete.rb', line 27

def initialize(collection, index = nil, size = 0)
  @collection = collection
  @index      = index
  @size       = size
end

Instance Attribute Details

#collectionVedeu::Editor::Line|Vedeu::Editor::Lines (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
# File 'lib/vedeu/editor/delete.rb', line 45

def collection
  @collection
end

#sizeFixnum (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


49
50
51
# File 'lib/vedeu/editor/delete.rb', line 49

def size
  @size
end

Class Method Details

.from(collection, index = nil, size = 0) ⇒ Vedeu::Editor::Line|Vedeu::Editor::Lines

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:



17
18
19
# File 'lib/vedeu/editor/delete.rb', line 17

def self.from(collection, index = nil, size = 0)
  new(collection, index, size).delete
end

Instance Method Details

#deleteVedeu::Editor::Line|Vedeu::Editor::Lines

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
38
39
# File 'lib/vedeu/editor/delete.rb', line 34

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

#indexFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


54
55
56
57
58
59
# File 'lib/vedeu/editor/delete.rb', line 54

def index
  return nil unless @index

  @index = size - 1 if @index > size
  @index
end

#line?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

If true, we are dealing with a Line object.

Returns:



64
65
66
# File 'lib/vedeu/editor/delete.rb', line 64

def line?
  string?(collection)
end

#lines?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

If true, we are dealing with a Lines collection.

Returns:



72
73
74
# File 'lib/vedeu/editor/delete.rb', line 72

def lines?
  array?(collection)
end

#negative_index?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the index was given or negative.

Returns:



80
81
82
# File 'lib/vedeu/editor/delete.rb', line 80

def negative_index?
  index && index < 0
end