Class: Vedeu::Editor::Line Private

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

Instance Method Summary collapse

Methods included from Collection

#by_index

Methods included from Repositories::Assemblage

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

Constructor Details

#initialize(collection = 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.

Parameters:

  • collection (String|NilClass) (defaults to: nil)


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

def initialize(collection = nil)
  @collection = collection || ''
end

Instance Attribute Details

#collectionString Also known as: line, to_s

Returns:

  • (String)


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

def collection
  @collection
end

Instance Method Details

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

Parameters:

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

Returns:

  • (String|NilClass)


42
43
44
45
46
47
# File 'lib/vedeu/editor/line.rb', line 42

def character(index = nil)
  return ''             if collection && collection.empty?
  return collection[-1] unless index

  by_index(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.

Parameters:

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

Returns:

  • (String)


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

def delete_character(index = nil)
  Vedeu::Editor::Line.coerce(Vedeu::Editor::Delete
                             .from(line, index, size))
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.

Parameters:

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

Returns:



65
66
67
68
69
70
# File 'lib/vedeu/editor/line.rb', line 65

def insert_character(character, index = nil)
  return self unless character

  Vedeu::Editor::Line.coerce(Vedeu::Editor::Insert
                             .into(collection, character, index, size))
end