Class: Vedeu::Editor::Item Private

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

Fetches an item from a collection.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, index = nil) ⇒ Vedeu::Editor::item

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

Parameters:



24
25
26
27
# File 'lib/vedeu/editor/item.rb', line 24

def initialize(collection, index = nil)
  @collection = collection
  @index      = index
end

Instance Attribute Details

#collectionVedeu::Editor::Line|Vedeu::Editor::Lines (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.



49
50
51
# File 'lib/vedeu/editor/item.rb', line 49

def collection
  @collection
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)


53
54
55
# File 'lib/vedeu/editor/item.rb', line 53

def index
  @index
end

Class Method Details

.by_index(collection, index = nil) ⇒ String|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.

Parameters:

Returns:



15
16
17
# File 'lib/vedeu/editor/item.rb', line 15

def self.by_index(collection, index = nil)
  new(collection, index).by_index
end

Instance Method Details

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vedeu/editor/item.rb', line 30

def by_index
  return nil unless size > 0

  if index.nil? || index > size
    collection[-1]

  elsif index > 0 && index <= size
    collection[index]

  else
    collection[0]

  end
end

#sizeFixnum (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 the size of the collection or 0.

Returns:

  • (Fixnum)


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

def size
  if collection
    collection.size

  else
    0

  end
end