Module: ZombieBattleground::Api::Extensions::Cards

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

Overview

API Extensions for Cards

Instance Method Summary collapse

Instance Method Details

#all_cards(**args) ⇒ Enumerator

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

Examples:

Get an enumerator for the cards

ZombieBattleground::Api.all_cards
# => Enumerator

Dump all cards as an array

ZombieBattleground::Api.all_cards.to_a
# => [ZombieBattleground::Api::Models::Card]

Return the first card

ZombieBattleground::Api.all_cards.first
# => ZombieBattleground::Api::Models::Card

Pass it a block

ZombieBattleground::Api.all_cards do |card|
  do_something_with(card) if card.mould_id == "1" && card.version == "v3"
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/cards.rb', line 37

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

  page = 1

  loop do
    response = @client.cards_request(args.merge(page: page))
    response.cards.each { |card| yield card }

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

#card_factionsArray<String>

Fetches all card factions

Examples:

factions = ZombieBattleground::Api.card_factions
# => [String]

Returns:

  • (Array<String>)


106
107
108
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 106

def card_factions
  load_cards_data['factions']
end

#card_kindsArray<String>

Fetches all card kinds

Examples:

cards = ZombieBattleground::Api.card_kinds
# => [String]

Returns:

  • (Array<String>)


64
65
66
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 64

def card_kinds
  load_cards_data['kinds']
end

#card_ranksArray<String>

Fetches all card ranks

Examples:

ranks = ZombieBattleground::Api.card_ranks
# => [String]

Returns:

  • (Array<String>)


78
79
80
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 78

def card_ranks
  load_cards_data['ranks']
end

#card_raritiesArray<String>

Fetches all card rarities

Examples:

rarities = ZombieBattleground::Api.card_rarities
# => [String]

Returns:

  • (Array<String>)


134
135
136
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 134

def card_rarities
  load_cards_data['rarities']
end

#card_setsArray<String>

Fetches all card sets

Examples:

sets = ZombieBattleground::Api.card_sets
# => [String]

Returns:

  • (Array<String>)


92
93
94
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 92

def card_sets
  load_cards_data['sets']
end

#card_typesArray<String>

Fetches all card types

Examples:

types = ZombieBattleground::Api.card_types
# => [String]

Returns:

  • (Array<String>)


120
121
122
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 120

def card_types
  load_cards_data['types']
end

#cards_by_faction(faction) ⇒ Array<ZombieBattleground::Api::Models::Card>

Fetches all cards with selected faction

Examples:

cards = ZombieBattleground::Api.cards_by_faction("WATER")
# => [ZombieBattleground::Api::Models::Card]

Parameters:

  • faction (String)

Returns:



198
199
200
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 198

def cards_by_faction(faction)
  all_cards(set: faction).to_a
end

#cards_by_kind(kind) ⇒ Array<ZombieBattleground::Api::Models::Card>

Fetches all cards with selected kind

Examples:

cards = ZombieBattleground::Api.cards_by_kind("SPELL")
# => [ZombieBattleground::Api::Models::Card]

Parameters:

  • kind (String)

Returns:



150
151
152
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 150

def cards_by_kind(kind)
  all_cards(kind: kind).to_a
end

#cards_by_rank(rank) ⇒ Array<ZombieBattleground::Api::Models::Card>

Fetches all cards with selected rank

Examples:

cards = ZombieBattleground::Api.cards_by_rank("COMMANDER")
# => [ZombieBattleground::Api::Models::Card]

Parameters:

  • rank (String)

Returns:



166
167
168
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 166

def cards_by_rank(rank)
  all_cards(rank: rank).to_a
end

#cards_by_rarity(rarity) ⇒ Array<ZombieBattleground::Api::Models::Card>

Fetches all cards with selected rarity

Examples:

cards = ZombieBattleground::Api.cards_by_rarity("")
# => [ZombieBattleground::Api::Models::Card]

Parameters:

  • rarity (String)

Returns:



230
231
232
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 230

def cards_by_rarity(rarity)
  all_cards(rarity: rarity).to_a
end

#cards_by_set(set) ⇒ Array<ZombieBattleground::Api::Models::Card>

Fetches all cards with selected set

Examples:

cards = ZombieBattleground::Api.cards_by_set("WATER")
# => [ZombieBattleground::Api::Models::Card]

Parameters:

  • set (String)

Returns:



182
183
184
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 182

def cards_by_set(set)
  all_cards(set: set).to_a
end

#cards_by_type(type) ⇒ Array<ZombieBattleground::Api::Models::Card>

Fetches all cards with selected type

Examples:

cards = ZombieBattleground::Api.cards_by_type("WALKER")
# => [ZombieBattleground::Api::Models::Card]

Parameters:

  • type (String)

Returns:



214
215
216
# File 'lib/zombie_battleground/api/extensions/cards.rb', line 214

def cards_by_type(type)
  all_cards(type: type).to_a
end