Class: Vedeu::Repositories::Collection Private
- Inherits:
-
Object
- Object
- Vedeu::Repositories::Collection
- Includes:
- Enumerable
- Defined in:
- lib/vedeu/repositories/collection.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.
Convert an Array into an object which has some meaning in the context it is being used.
Direct Known Subclasses
Events::Collection, Input::Keys, Views::Chars, Views::Lines, Views::Streams, Views::ViewCollection
Instance Attribute Summary collapse
- #collection ⇒ Array|Vedeu::Repositories::Collection (also: #all) readonly private
- #name ⇒ String|Symbol|NilClass
- #parent ⇒ Fixnum
Class Method Summary collapse
Instance Method Summary collapse
-
#[](value) ⇒ void
private
Fetch an entry from the collection via index.
-
#add(other) ⇒ Vedeu::Repositories::Collection
(also: #<<)
private
Adds an entry to the collection.
-
#each(&block) ⇒ Enumerator
private
Provides iteration over the collection.
-
#empty? ⇒ Boolean
private
Returns a boolean indicating whether the collection is empty.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
-
#initialize(collection = [], parent = nil, name = nil) ⇒ Vedeu::Repositories::Collection
constructor
private
Returns a new instance of Vedeu::Repositories::Collection.
-
#size ⇒ Fixnum
private
Returns the size of the collection.
-
#to_s ⇒ String
(also: #to_str)
private
Returns the collection as a String.
Constructor Details
#initialize(collection = [], parent = nil, name = nil) ⇒ Vedeu::Repositories::Collection
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::Repositories::Collection.
47 48 49 50 51 |
# File 'lib/vedeu/repositories/collection.rb', line 47 def initialize(collection = [], parent = nil, name = nil) @collection = collection @parent = parent @name = name end |
Instance Attribute Details
#collection ⇒ Array|Vedeu::Repositories::Collection (readonly) Also known as: all
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.
16 17 18 |
# File 'lib/vedeu/repositories/collection.rb', line 16 def collection @collection end |
#name ⇒ String|Symbol|NilClass
25 26 27 |
# File 'lib/vedeu/repositories/collection.rb', line 25 def name @name end |
#parent ⇒ Fixnum
21 22 23 |
# File 'lib/vedeu/repositories/collection.rb', line 21 def parent @parent end |
Class Method Details
.coerce(collection = [], parent = nil, name = nil) ⇒ Vedeu::Repositories::Collection
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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/vedeu/repositories/collection.rb', line 31 def self.coerce(collection = [], parent = nil, name = nil) if collection.is_a?(Vedeu::Repositories::Collection) collection else new(Array(collection), parent, name) end end |
Instance Method Details
#[](value) ⇒ void
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.
This method returns an undefined value.
Fetch an entry from the collection via index.
57 58 59 |
# File 'lib/vedeu/repositories/collection.rb', line 57 def [](value) collection[value] end |
#add(other) ⇒ Vedeu::Repositories::Collection Also known as: <<
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.
Adds an entry to the collection.
65 66 67 68 69 70 71 72 73 |
# File 'lib/vedeu/repositories/collection.rb', line 65 def add(other) if other.is_a?(Vedeu::Repositories::Collection) return self.class.coerce(other, parent, name) if empty? else self.class.new(@collection += Array(other), parent, name) end end |
#each(&block) ⇒ Enumerator
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.
Provides iteration over the collection.
80 81 82 |
# File 'lib/vedeu/repositories/collection.rb', line 80 def each(&block) collection.each(&block) end |
#empty? ⇒ Boolean
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 boolean indicating whether the collection is empty.
87 88 89 |
# File 'lib/vedeu/repositories/collection.rb', line 87 def empty? collection.empty? end |
#eql?(other) ⇒ Boolean Also known as: ==
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.
An object is equal when its values are the same.
95 96 97 |
# File 'lib/vedeu/repositories/collection.rb', line 95 def eql?(other) self.class == other.class && collection == other.collection end |
#size ⇒ Fixnum
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.
103 104 105 |
# File 'lib/vedeu/repositories/collection.rb', line 103 def size collection.size end |
#to_s ⇒ String Also known as: to_str
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 collection as a String.
110 111 112 |
# File 'lib/vedeu/repositories/collection.rb', line 110 def to_s collection.map(&:to_s).join end |