Class: Vedeu::Editor::Lines Private

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

Class Method Summary collapse

Instance Method Summary collapse

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)


60
61
62
# File 'lib/vedeu/editor/lines.rb', line 60

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

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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

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

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

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

Parameters:

  • value (void)

Returns:

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

Parameters:

Returns:

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

Parameters:

Returns:



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

Returns:

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

Parameters:

  • value (void)

Returns:

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

Parameters:

  • value (Hash|void)

Returns:

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

Returns:

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

Parameters:

  • value (Fixnum|void)

Returns:

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

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

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

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • klass (Module|Class|String)

Returns:

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

Returns:

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

Parameters:

  • value (String|void)

Returns:

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

Parameters:

  • value (void)

Returns:

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

Returns:

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

Parameters:

  • index (Fixnum|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.

Parameters:

  • block (Proc)

Returns:

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

Parameters:

  • index (Fixnum)

Returns:

  • (String)

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



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.

Parameters:

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

Returns:

  • (String)


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.

Parameters:

  • block (Proc)

Returns:

  • (Enumerator)


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.

Returns:

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

Parameters:

  • other (void)

Returns:

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



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.

Parameters:

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

Returns:



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.

Parameters:

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

Returns:



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

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

Returns:

  • (Fixnum)

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


131
132
133
# File 'lib/vedeu/editor/lines.rb', line 131

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