Class: GiphyAPI::Collection

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

Constant Summary collapse

PAGINATION_ATTRIBUTES =
[:total_count, :offset].freeze

Instance Method Summary collapse

Constructor Details

#initialize(elements) ⇒ Collection

Returns a new instance of Collection.



9
10
11
# File 'lib/giphy_api/collection.rb', line 9

def initialize(elements)
  @elements = elements
end

Instance Method Details

#collect!Object



21
22
23
24
25
26
27
# File 'lib/giphy_api/collection.rb', line 21

def collect!
  return elements unless block_given?
  set = []
  each { |e| set << yield(e) }
  @elements = set
  self
end

#countObject



17
18
19
# File 'lib/giphy_api/collection.rb', line 17

def count
  elements.length
end

#each(&block) ⇒ Object



13
14
15
# File 'lib/giphy_api/collection.rb', line 13

def each &block
  elements.each(&block)
end