Class: Vedeu::Editor::Line Private

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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

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


31
32
33
# File 'lib/vedeu/editor/line.rb', line 31

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

Instance Attribute Details

#lineString Also known as: to_s

Returns:

  • (String)


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.

Parameters:

Returns:



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

Parameters:

  • index (Fixnum|Range)

Returns:

  • (String)


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.

Parameters:

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

Returns:

  • (String|NilClass)


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.

Parameters:

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

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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.

Parameters:

Returns:

  • (Boolean)


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.

Parameters:

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

Returns:



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

#sizeFixnum

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.

Returns:

  • (Fixnum)


98
99
100
# File 'lib/vedeu/editor/line.rb', line 98

def size
  line.size
end