Class: Vedeu::Editor::Lines Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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

Instance Method Summary collapse

Methods included from Collection

#by_index

Methods included from Repositories::Assemblage

#[], #any?, #empty?, #eql?, #size

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.

Parameters:

  • collection (Array<String>|NilClass) (defaults to: nil)


34
35
36
# File 'lib/vedeu/editor/lines.rb', line 34

def initialize(collection = nil)
  @collection = collection || []
end

Instance Attribute Details

#collectionString Also known as: lines

Returns:

  • (String)


18
19
20
# File 'lib/vedeu/editor/lines.rb', line 18

def collection
  @collection
end

Instance Method Details

#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.

Parameters:

  • y (Fixnum)
  • x (Fixnum)

Returns:



44
45
46
47
48
# File 'lib/vedeu/editor/lines.rb', line 44

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.

Parameters:

  • index (Fixnum|NilClass) (defaults to: nil)

Returns:

  • (String)


54
55
56
57
# File 'lib/vedeu/editor/lines.rb', line 54

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.

Parameters:

  • block (Proc)

Returns:

  • (Enumerator)


63
64
65
# File 'lib/vedeu/editor/lines.rb', line 63

def each(&block)
  collection.each(&block)
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.

Parameters:

  • character (String)
  • y (Fixnum)
  • x (Fixnum)

Returns:



73
74
75
76
77
# File 'lib/vedeu/editor/lines.rb', line 73

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.

Parameters:

  • index (Fixnum|NilClass) (defaults to: nil)

Returns:



83
84
85
86
87
88
89
90
# File 'lib/vedeu/editor/lines.rb', line 83

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.

Parameters:

  • index (Fixnum|NilClass) (defaults to: nil)

Returns:



96
97
98
99
100
101
# File 'lib/vedeu/editor/lines.rb', line 96

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

#to_sString 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.

Returns:

  • (String)


106
107
108
# File 'lib/vedeu/editor/lines.rb', line 106

def to_s
  collection.map(&:to_s).join
end