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.



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.



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.



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.



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 collection

  if index.nil? || index > collection.size
    last_item

  elsif index > 0 && index <= collection.size
    nth_item

  else
    first_item

  end
end

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



58
59
60
# File 'lib/vedeu/editor/item.rb', line 58

def first_item
  collection[0]
end

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



63
64
65
# File 'lib/vedeu/editor/item.rb', line 63

def last_item
  collection[-1]
end

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



68
69
70
# File 'lib/vedeu/editor/item.rb', line 68

def nth_item
  collection[index]
end