Class: Vedeu::Editor::Insert Private

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/vedeu/editor/insert.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

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Constructor Details

#initialize(collection, entity, index = nil, size = 0) ⇒ Vedeu::Editor::Insert

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

Parameters:



28
29
30
31
32
33
# File 'lib/vedeu/editor/insert.rb', line 28

def initialize(collection, entity, index = nil, size = 0)
  @collection = collection
  @entity     = entity
  @index      = index
  @size       = size
end

Instance Attribute Details

#collectionString|Vedeu::Editor::Line|Vedeu::Editor::Lines (readonly, private)

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.



60
61
62
63
64
65
66
67
68
# File 'lib/vedeu/editor/insert.rb', line 60

def collection
  if string?(@collection)
    @collection.dup

  else
    @collection

  end
end

#entityString (readonly, protected)

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:

  • (String)


46
47
48
# File 'lib/vedeu/editor/insert.rb', line 46

def entity
  @entity
end

#indexFixnum (readonly, protected)

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:

  • (Fixnum)


50
51
52
# File 'lib/vedeu/editor/insert.rb', line 50

def index
  @index
end

#sizeFixnum (readonly, protected)

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:

  • (Fixnum)


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

def size
  @size
end

Class Method Details

.into(collection, entity, index = nil, size = 0) ⇒ String|Vedeu::Editor::Line|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.

Parameters:

Returns:



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

def self.into(collection, entity, index = nil, size = 0)
  new(collection, entity, index, size).insert
end

Instance Method Details

#index?Boolean (private)

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:



71
72
73
# File 'lib/vedeu/editor/insert.rb', line 71

def index?
  numeric?(index)
end

#insertString|Vedeu::Editor::Line|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.



36
37
38
39
40
# File 'lib/vedeu/editor/insert.rb', line 36

def insert
  return collection.insert(position, entity) if index?

  collection << entity
end

#positionFixnum (private)

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:

  • (Fixnum)


76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vedeu/editor/insert.rb', line 76

def position
  if index < 0
    0

  elsif index > size
    size

  else
    index

  end
end