Class: Vedeu::Editor::Delete Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Delete
- 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
- #collection ⇒ Vedeu::Editor::Line|Vedeu::Editor::Lines readonly protected private
- #size ⇒ Fixnum readonly protected private
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Vedeu::Editor::Line|Vedeu::Editor::Lines private
- #index ⇒ Fixnum private private
-
#initialize(collection, index = nil, size = 0) ⇒ Vedeu::Editor::Delete
constructor
private
Returns a new instance of Vedeu::Editor::Delete.
-
#line? ⇒ Boolean
private
private
If true, we are dealing with a Line object.
-
#lines? ⇒ Boolean
private
private
If true, we are dealing with a Lines collection.
-
#negative_index? ⇒ Boolean
private
private
Returns a boolean indicating whether the index was given or negative.
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.
23 24 25 26 27 |
# File 'lib/vedeu/editor/delete.rb', line 23 def initialize(collection, index = nil, size = 0) @collection = collection @index = index @size = size end |
Instance Attribute Details
#collection ⇒ Vedeu::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.
41 42 43 |
# File 'lib/vedeu/editor/delete.rb', line 41 def collection @collection end |
#size ⇒ Fixnum (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 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.
13 14 15 |
# File 'lib/vedeu/editor/delete.rb', line 13 def self.from(collection, index = nil, size = 0) new(collection, index, size).delete end |
Instance Method Details
#delete ⇒ 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.
30 31 32 33 34 35 |
# File 'lib/vedeu/editor/delete.rb', line 30 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 |
#index ⇒ Fixnum (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.
50 51 52 53 54 55 |
# File 'lib/vedeu/editor/delete.rb', line 50 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.
60 61 62 |
# File 'lib/vedeu/editor/delete.rb', line 60 def line? collection.is_a?(String) 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.
68 69 70 |
# File 'lib/vedeu/editor/delete.rb', line 68 def lines? collection.is_a?(Array) 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.
76 77 78 |
# File 'lib/vedeu/editor/delete.rb', line 76 def negative_index? index && index < 0 end |