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 collection

  if index_out_of_range?
    last_item

  elsif index_within_range?
    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.

Returns:



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

def first_item
  collection[0]
end

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



73
74
75
# File 'lib/vedeu/editor/item.rb', line 73

def index_out_of_range?
  index.nil? || index > collection.size
end

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



78
79
80
# File 'lib/vedeu/editor/item.rb', line 78

def index_within_range?
  index > 0 && index <= collection.size
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.

Returns:



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.

Returns:



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

def nth_item
  collection[index]
end