Class: Vedeu::Editor::Line Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Line
- Defined in:
- lib/vedeu/editor/line.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 a single line of an Vedeu::Editor::Document.
Instance Attribute Summary collapse
- #line ⇒ String (also: #to_s)
Class Method Summary collapse
-
.coerce(line) ⇒ Vedeu::Editor::Line
private
Coerce a line into a new instance of Vedeu::Editor::Line.
Instance Method Summary collapse
-
#[](index) ⇒ String
private
Return a character or collection of characters (if index is a Range).
-
#character(index = nil) ⇒ String|NilClass
private
Return the character at the given index.
-
#delete_character(index = nil) ⇒ String
private
Delete the character from the line positioned at the given index.
-
#empty? ⇒ Boolean
private
Returns a boolean indicating whether there are characters on this line.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
-
#initialize(line = nil) ⇒ Vedeu::Editor::Line
constructor
private
Returns a new instance of Vedeu::Editor::Line.
-
#insert_character(character, index = nil) ⇒ Vedeu::Editor::Line
private
Insert the character on the line positioned at the given index.
-
#size ⇒ Fixnum
private
Return the size of the line in characters.
Constructor Details
#initialize(line = 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 a new instance of Vedeu::Editor::Line.
31 32 33 |
# File 'lib/vedeu/editor/line.rb', line 31 def initialize(line = nil) @line = line || '' end |
Instance Attribute Details
#line ⇒ String Also known as: to_s
13 14 15 |
# File 'lib/vedeu/editor/line.rb', line 13 def line @line end |
Class Method Details
.coerce(line) ⇒ 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.
Coerce a line into a new instance of Vedeu::Editor::Line.
20 21 22 23 24 25 |
# File 'lib/vedeu/editor/line.rb', line 20 def self.coerce(line) return line if line.is_a?(self) return new(line) if line.is_a?(String) new end |
Instance Method Details
#[](index) ⇒ 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 a character or collection of characters (if index is a Range).
40 41 42 |
# File 'lib/vedeu/editor/line.rb', line 40 def [](index) line[index] end |
#character(index = nil) ⇒ String|NilClass
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 character at the given index.
48 49 50 51 52 53 |
# File 'lib/vedeu/editor/line.rb', line 48 def character(index = nil) return '' if line && line.empty? return line[-1] unless index Vedeu::Editor::Item.by_index(line, index) end |
#delete_character(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 character from the line positioned at the given index.
60 61 62 63 |
# File 'lib/vedeu/editor/line.rb', line 60 def delete_character(index = nil) Vedeu::Editor::Line.coerce(Vedeu::Editor::Delete .from(line, index, size)) 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 characters on this line.
69 70 71 |
# File 'lib/vedeu/editor/line.rb', line 69 def empty? line.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.
77 78 79 |
# File 'lib/vedeu/editor/line.rb', line 77 def eql?(other) self.class == other.class && line == other.line end |
#insert_character(character, 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.
Insert the character on the line positioned at the given index.
88 89 90 91 92 93 |
# File 'lib/vedeu/editor/line.rb', line 88 def insert_character(character, index = nil) return self unless character Vedeu::Editor::Line.coerce(Vedeu::Editor::Insert .into(line, character, index, size)) 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 size of the line in characters.
98 99 100 |
# File 'lib/vedeu/editor/line.rb', line 98 def size line.size end |