Class: Vedeu::Editor::Item Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Item
- 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
- #collection ⇒ Vedeu::Editor::Line|Vedeu::Editor::Lines readonly protected private
- #index ⇒ Fixnum readonly protected private
Class Method Summary collapse
Instance Method Summary collapse
- #by_index ⇒ String|Vedeu::Editor::Line private
- #first_item ⇒ String|Vedeu::Editor::Line private private
- #index_out_of_range? ⇒ Boolean private private
- #index_within_range? ⇒ Boolean private private
-
#initialize(collection, index = nil) ⇒ Vedeu::Editor::item
constructor
private
Returns a new instance of Vedeu::Editor::Item.
- #last_item ⇒ String|Vedeu::Editor::Line private private
- #nth_item ⇒ String|Vedeu::Editor::Line private private
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
#collection ⇒ Vedeu::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 |
#index ⇒ Fixnum (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_index ⇒ 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.
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_item ⇒ String|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 |
#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.
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.
78 79 80 |
# File 'lib/vedeu/editor/item.rb', line 78 def index_within_range? index > 0 && index <= collection.size end |
#last_item ⇒ String|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_item ⇒ String|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 |