Class: Mastodon::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mastodon/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(items, klass) ⇒ Collection

Returns a new instance of Collection.



5
6
7
# File 'lib/mastodon/collection.rb', line 5

def initialize(items, klass)
  @collection = items.map { |attributes| klass.new(attributes) }
end

Instance Method Details

#each(start = 0) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/mastodon/collection.rb', line 9

def each(start = 0)
  return to_enum(:each, start) unless block_given?

  Array(@collection[start..-1]).each do |element|
    yield(element)
  end

  self
end

#lastObject



23
24
25
# File 'lib/mastodon/collection.rb', line 23

def last
  @collection.last
end

#sizeObject



19
20
21
# File 'lib/mastodon/collection.rb', line 19

def size
  @collection.size
end