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)


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

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

#deck_faction(type) ⇒ String

Return’s the deck overlord (hero) type faction

Examples:

deck_faction(0) # => "EARTH"

Parameters:

  • type (Integer)

Returns:

  • (String)


65
66
67
# File 'lib/zombie_battleground/api/extensions/decks.rb', line 65

def deck_faction(type)
  load_decks_data['overlord_types'][type]
end

#deck_strong_against(type) ⇒ String

Return’s the deck overlord (hero) faction weakness

Examples:

deck_strong_against(0) # => "AIR"

Parameters:

  • type (Integer)

Returns:

  • (String)


95
96
97
# File 'lib/zombie_battleground/api/extensions/decks.rb', line 95

def deck_strong_against(type)
  load_decks_data['strong_against'][load_decks_data['overlord_types'][type]]
end

#deck_weak_against(type) ⇒ String

Return’s the deck overlord (hero) faction weakness

Examples:

deck_weak_against(0) # => "FIRE"

Parameters:

  • type (Integer)

Returns:

  • (String)


80
81
82
# File 'lib/zombie_battleground/api/extensions/decks.rb', line 80

def deck_weak_against(type)
  load_decks_data['weak_against'][load_decks_data['overlord_types'][type]]
end