Module: ZombieBattleground::Api::Extensions::Decks

Included in:
ZombieBattleground::Api::Extensions
Defined in:
lib/zombie_battleground/api/extensions/decks.rb

Overview

API Extensions for Decks

Instance Method Summary collapse

Instance Method Details

#all_decks(**args) ⇒ Enumerator

Returns an enumerator for all available decks, accepts a block for yields

Examples:

Get an enumerator for the decks

ZombieBattleground::Api.all_decks
# => Enumerator

Dump all decks as an array

ZombieBattleground::Api.all_decks.to_a
# => [ZombieBattleground::Api::Models::Deck]

Return the first deck

ZombieBattleground::Api.all_decks.first
# => ZombieBattleground::Api::Models::Deck

Pass it a block

ZombieBattleground::Api.all_decks do |deck|
  do_something_with(deck) if deck.id == 1
end
# => nil

Returns:

  • (Enumerator)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/zombie_battleground/api/extensions/decks.rb', line 35

def all_decks(**args)
  args.delete(:limit) # query as many as possible
  return enum_for(:all_decks, args) unless block_given?

  page = 1

  loop do
    response = @client.decks_request(args.merge(page: page))
    response.decks.each { |deck| yield deck }

    break if response.decks_count < PAGE_MAX
    # :nocov:
    page += 1
    # :nocov:
  end
end