Class: Vedeu::Repositories::Collection Private

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • collection (void) (defaults to: [])
  • parent (void) (defaults to: nil)
  • name (String|Symbol|NilClass) (defaults to: nil)


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

#collectionArray|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

#nameString|Symbol|NilClass

Returns:

  • (String|Symbol|NilClass)


25
26
27
# File 'lib/vedeu/repositories/collection.rb', line 25

def name
  @name
end

#parentFixnum

Returns:

  • (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.

Parameters:

Returns:



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.

Parameters:

  • value (Fixnum)


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.

Parameters:

  • block (Proc)

Returns:

  • (Enumerator)


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.

Returns:

  • (Boolean)


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.

Parameters:

Returns:

  • (Boolean)


95
96
97
# File 'lib/vedeu/repositories/collection.rb', line 95

def eql?(other)
  self.class == other.class && collection == other.collection
end

#sizeFixnum

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.

Returns:

  • (Fixnum)


103
104
105
# File 'lib/vedeu/repositories/collection.rb', line 103

def size
  collection.size
end

#to_sString 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.

Returns:

  • (String)


110
111
112
# File 'lib/vedeu/repositories/collection.rb', line 110

def to_s
  collection.map(&:to_s).join
end