Class: Vedeu::Editor::Lines Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Lines
- Extended by:
- Common
- Includes:
- Enumerable, Collection
- 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
- #collection ⇒ String (also: #lines)
Class Method Summary collapse
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
.become(klass, attributes) ⇒ Class
extended
from Common
private
Converts one class into another.
-
.boolean(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the value was a boolean.
-
.boolean?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
.coerce(document) ⇒ Vedeu::Editor::Lines
private
Coerce a document into a new instance of Vedeu::Editor::Lines.
-
.escape?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
.falsy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
.hash?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
.line_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
.numeric?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
.snake_case(klass) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
-
.stream_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
.string?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.truthy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
.view_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::View.
Instance Method Summary collapse
-
#[](index) ⇒ void
included
from Repositories::Assemblage
private
Return an individual element or collection of elements (if the given index is a Range).
-
#any?(&block) ⇒ Boolean
included
from Repositories::Assemblage
private
Returns a boolean indicating whether the collection is not empty.
-
#by_index(index) ⇒ String
included
from Collection
private
Fetches an item from a collection.
-
#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
included
from Repositories::Assemblage
private
Returns a boolean indicating whether the collection is empty.
-
#eql?(other) ⇒ Boolean
(also: #==)
included
from Repositories::Assemblage
private
An object is equal when its values are the same.
-
#initialize(collection = 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
included
from Repositories::Assemblage
private
Return the size of the collection.
-
#to_s ⇒ String
(also: #to_str)
private
Return the lines as a string.
Constructor Details
#initialize(collection = 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.
60 61 62 |
# File 'lib/vedeu/editor/lines.rb', line 60 def initialize(collection = nil) @collection = collection || [] end |
Instance Attribute Details
#collection ⇒ String Also known as: lines
18 19 20 |
# File 'lib/vedeu/editor/lines.rb', line 18 def collection @collection end |
Class Method Details
.absent?(variable) ⇒ Boolean Originally defined in module Common
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 a variable is nil or empty.
.become(klass, attributes) ⇒ Class Originally defined in module Common
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.
Converts one class into another.
.boolean(value) ⇒ Boolean Originally defined in module Common
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 the value was a boolean.
.boolean?(value) ⇒ Boolean Originally defined in module Common
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 value is a Boolean.
.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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vedeu/editor/lines.rb', line 30 def coerce(document) if document.is_a?(self) new(document.lines) elsif document.is_a?(Array) collection = document.map do |line| Vedeu::Editor::Line.coerce(line) end new(collection) elsif string?(document) collection = document.lines.map(&:chomp).map do |line| Vedeu::Editor::Line.coerce(line) end new(collection) else new end end |
.escape?(value) ⇒ Boolean Originally defined in module Common
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 value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
.falsy?(value) ⇒ Boolean Originally defined in module Common
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 value should be considered false.
.hash?(value) ⇒ Boolean Originally defined in module Common
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 value is a Hash.
.line_model? ⇒ Boolean Originally defined in module Common
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 the model is a Views::Line.
.numeric?(value) ⇒ Boolean Originally defined in module Common
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 value is a Fixnum.
.present?(variable) ⇒ Boolean Originally defined in module Common
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 a variable has a useful value.
.snake_case(klass) ⇒ String Originally defined in module Common
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.
Converts a class name to a lowercase snake case string.
.stream_model? ⇒ Boolean Originally defined in module Common
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 the model is a Views::Stream.
.string?(value) ⇒ Boolean Originally defined in module Common
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 value is a Fixnum.
.truthy?(value) ⇒ Boolean Originally defined in module Common
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 value should be considered true.
.view_model? ⇒ Boolean Originally defined in module Common
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 the model is a Views::View.
Instance Method Details
#[](index) ⇒ void Originally defined in module Repositories::Assemblage
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.
This method returns an undefined value.
Return an individual element or collection of elements (if the given index is a Range).
#any?(&block) ⇒ Boolean Originally defined in module Repositories::Assemblage
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 collection is not empty.
#by_index(index) ⇒ String Originally defined in module Collection
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.
Fetches an item from a collection.
#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.
70 71 72 73 74 |
# File 'lib/vedeu/editor/lines.rb', line 70 def delete_character(y, x) collection[y] = line(y).delete_character(x) unless line(y).empty? Vedeu::Editor::Lines.coerce(collection) 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.
80 81 82 83 |
# File 'lib/vedeu/editor/lines.rb', line 80 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.
89 90 91 |
# File 'lib/vedeu/editor/lines.rb', line 89 def each(&block) collection.each(&block) end |
#empty? ⇒ Boolean Originally defined in module Repositories::Assemblage
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 collection is empty.
#eql?(other) ⇒ Boolean Also known as: == Originally defined in module Repositories::Assemblage
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.
#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.
99 100 101 102 103 |
# File 'lib/vedeu/editor/lines.rb', line 99 def insert_character(character, y, x) collection[y] = line(y).insert_character(character, x) Vedeu::Editor::Lines.coerce(collection) 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.
109 110 111 112 113 114 115 |
# File 'lib/vedeu/editor/lines.rb', line 109 def insert_line(index = nil) Vedeu::Editor::Lines.coerce( Vedeu::Editor::Insert.into(collection, 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.
121 122 123 124 125 126 |
# File 'lib/vedeu/editor/lines.rb', line 121 def line(index = nil) return Vedeu::Editor::Line.new unless collection return Vedeu::Editor::Line.coerce(collection[-1]) unless index Vedeu::Editor::Line.coerce(by_index(index)) end |
#size ⇒ Fixnum Originally defined in module Repositories::Assemblage
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 collection.
#to_s ⇒ String Also known as: to_str
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.
131 132 133 |
# File 'lib/vedeu/editor/lines.rb', line 131 def to_s collection.map(&:to_s).join end |