Class: Vedeu::Editor::Lines Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Lines
- Includes:
- Enumerable
- Defined in:
- lib/vedeu/editor/lines.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
-
.coerce(document) ⇒ Vedeu::Editor::Lines
private
Coerce a document into a new instance of Vedeu::Editor::Lines.
Instance Method Summary collapse
-
#[](index) ⇒ Vedeu::Editor::Line
private
Return a line or collection of lines (if index is a Range).
-
#delete_character(y, x) ⇒ Vedeu::Editor::Lines
private
Deletes the character from the line where the cursor is currently positioned.
-
#delete_line(index = nil) ⇒ String
private
Delete the line from the lines positioned at the given index.
-
#each(&block) ⇒ Enumerator
private
Provides iteration over the collection.
-
#empty? ⇒ Boolean
private
Returns a boolean indicating whether there are lines.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
-
#initialize(lines = nil) ⇒ Vedeu::Editor::Lines
constructor
private
Returns a new instance of Vedeu::Editor::Lines.
-
#insert_character(character, y, x) ⇒ Vedeu::Editor::Lines
private
Insert a character in to a line.
-
#insert_line(index = nil) ⇒ Vedeu::Editor::Lines
private
Insert the line on the line below the given index.
-
#line(index = nil) ⇒ Vedeu::Editor::Line
private
Returns the line at the given index.
-
#size ⇒ Fixnum
private
Return the number of lines.
-
#to_s ⇒ String
private
Return the lines as a string.
Constructor Details
#initialize(lines = nil) ⇒ 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.
Returns a new instance of Vedeu::Editor::Lines.
47 48 49 |
# File 'lib/vedeu/editor/lines.rb', line 47 def initialize(lines = nil) @lines = lines || [] end |
Instance Attribute Details
#lines ⇒ String
15 16 17 |
# File 'lib/vedeu/editor/lines.rb', line 15 def lines @lines end |
Class Method Details
.coerce(document) ⇒ 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.
Coerce a document into a new instance of Vedeu::Editor::Lines.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vedeu/editor/lines.rb', line 21 def self.coerce(document) if document.is_a?(self) new(document.lines) elsif document.is_a?(Array) lines = document.map { |line| Vedeu::Editor::Line.coerce(line) } new(lines) elsif document.is_a?(String) lines = document.lines.map(&:chomp).map do |line| Vedeu::Editor::Line.coerce(line) end new(lines) else new end end |
Instance Method Details
#[](index) ⇒ Vedeu::Editor::Line
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.
Return a line or collection of lines (if index is a Range).
55 56 57 |
# File 'lib/vedeu/editor/lines.rb', line 55 def [](index) lines[index] end |
#delete_character(y, x) ⇒ 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.
Deletes the character from the line where the cursor is currently positioned.
65 66 67 68 69 |
# File 'lib/vedeu/editor/lines.rb', line 65 def delete_character(y, x) lines[y] = line(y).delete_character(x) unless line(y).empty? Vedeu::Editor::Lines.coerce(lines) end |
#delete_line(index = nil) ⇒ String
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.
Delete the line from the lines positioned at the given index.
75 76 77 78 |
# File 'lib/vedeu/editor/lines.rb', line 75 def delete_line(index = nil) Vedeu::Editor::Lines.coerce(Vedeu::Editor::Delete .from(lines, index, size)) end |
#each(&block) ⇒ Enumerator
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.
Provides iteration over the collection.
84 85 86 |
# File 'lib/vedeu/editor/lines.rb', line 84 def each(&block) lines.each(&block) end |
#empty? ⇒ Boolean
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 there are lines.
91 92 93 |
# File 'lib/vedeu/editor/lines.rb', line 91 def empty? lines.empty? end |
#eql?(other) ⇒ Boolean Also known as: ==
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.
An object is equal when its values are the same.
99 100 101 |
# File 'lib/vedeu/editor/lines.rb', line 99 def eql?(other) self.class == other.class && lines == other.lines end |
#insert_character(character, y, x) ⇒ 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.
Insert a character in to a line.
110 111 112 113 114 |
# File 'lib/vedeu/editor/lines.rb', line 110 def insert_character(character, y, x) lines[y] = line(y).insert_character(character, x) Vedeu::Editor::Lines.coerce(lines) end |
#insert_line(index = nil) ⇒ 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.
Insert the line on the line below the given index.
120 121 122 123 124 125 126 |
# File 'lib/vedeu/editor/lines.rb', line 120 def insert_line(index = nil) Vedeu::Editor::Lines.coerce( Vedeu::Editor::Insert.into(lines, Vedeu::Editor::Line.new, index, size)) end |
#line(index = nil) ⇒ Vedeu::Editor::Line
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 the line at the given index.
132 133 134 135 136 137 |
# File 'lib/vedeu/editor/lines.rb', line 132 def line(index = nil) return Vedeu::Editor::Line.new unless lines return Vedeu::Editor::Line.coerce(lines[-1]) unless index Vedeu::Editor::Line.coerce(Vedeu::Editor::Item.by_index(lines, index)) end |
#size ⇒ Fixnum
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.
Return the number of lines.
142 143 144 |
# File 'lib/vedeu/editor/lines.rb', line 142 def size lines.size end |
#to_s ⇒ String
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.
Return the lines as a string.
149 150 151 |
# File 'lib/vedeu/editor/lines.rb', line 149 def to_s lines.map(&:to_s).join end |