Class: Vedeu::Repositories::Collection
- Inherits:
-
Object
- Object
- Vedeu::Repositories::Collection
- Includes:
- Enumerable
- Defined in:
- lib/vedeu/repositories/collection.rb
Overview
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
- #name ⇒ String|Symbol|NilClass
- #parent ⇒ Fixnum
Class Method Summary collapse
Instance Method Summary collapse
-
#[](value) ⇒ void
Fetch an entry from the collection via index.
-
#add(*other) ⇒ Vedeu::Repositories::Collection
(also: #<<)
Adds an entry to the collection.
-
#each(&block) ⇒ Enumerator
Provides iteration over the collection.
-
#empty? ⇒ Boolean
Returns a boolean indicating whether the collection is empty.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#initialize(collection = [], parent = nil, name = nil) ⇒ Vedeu::Repositories::Collection
constructor
Returns a new instance of Vedeu::Repositories::Collection.
-
#size ⇒ Fixnum
Returns the size of the collection.
-
#to_s ⇒ String
(also: #to_str)
Returns the collection as a String.
Constructor Details
#initialize(collection = [], parent = nil, name = nil) ⇒ Vedeu::Repositories::Collection
Returns a new instance of Vedeu::Repositories::Collection.
45 46 47 48 49 |
# File 'lib/vedeu/repositories/collection.rb', line 45 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
14 15 16 |
# File 'lib/vedeu/repositories/collection.rb', line 14 def collection @collection end |
#name ⇒ String|Symbol|NilClass
23 24 25 |
# File 'lib/vedeu/repositories/collection.rb', line 23 def name @name end |
#parent ⇒ Fixnum
19 20 21 |
# File 'lib/vedeu/repositories/collection.rb', line 19 def parent @parent end |
Class Method Details
.coerce(collection = [], parent = nil, name = nil) ⇒ Vedeu::Repositories::Collection
29 30 31 32 33 34 35 36 37 |
# File 'lib/vedeu/repositories/collection.rb', line 29 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 returns an undefined value.
Fetch an entry from the collection via index.
55 56 57 |
# File 'lib/vedeu/repositories/collection.rb', line 55 def [](value) collection[value] end |
#add(*other) ⇒ Vedeu::Repositories::Collection Also known as: <<
Adds an entry to the collection.
63 64 65 |
# File 'lib/vedeu/repositories/collection.rb', line 63 def add(*other) self.class.new(@collection += other, parent, name) end |
#each(&block) ⇒ Enumerator
Provides iteration over the collection.
72 73 74 |
# File 'lib/vedeu/repositories/collection.rb', line 72 def each(&block) collection.each(&block) end |
#empty? ⇒ Boolean
Returns a boolean indicating whether the collection is empty.
79 80 81 |
# File 'lib/vedeu/repositories/collection.rb', line 79 def empty? collection.empty? end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
87 88 89 |
# File 'lib/vedeu/repositories/collection.rb', line 87 def eql?(other) self.class == other.class && collection == other.collection end |
#size ⇒ Fixnum
Returns the size of the collection.
95 96 97 |
# File 'lib/vedeu/repositories/collection.rb', line 95 def size collection.size end |
#to_s ⇒ String Also known as: to_str
Returns the collection as a String.
102 103 104 |
# File 'lib/vedeu/repositories/collection.rb', line 102 def to_s collection.map(&:to_s).join end |