module ZombieBattleground::Api::Extensions::Cards

API Extensions for Cards

Public Instance Methods

all_cards(**args) { |card| ... } click to toggle source

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

@return [Enumerator]

@example Get an enumerator for the cards

ZombieBattleground::Api.all_cards
# => Enumerator

@example Dump all cards as an array

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

@example Return the first card

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

@example Pass it a block

ZombieBattleground::Api.all_cards do |card|
  do_something_with(card) if card.mould_id == "1" && card.version == "v3"
end
# => nil

@api public

# 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_factions() click to toggle source

Fetches all card factions

@return [Array<String>]

@example

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

@api public

# File lib/zombie_battleground/api/extensions/cards.rb, line 106
def card_factions
  load_cards_data['factions']
end
card_kinds() click to toggle source

Fetches all card kinds

@return [Array<String>]

@example

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

@api public

# File lib/zombie_battleground/api/extensions/cards.rb, line 64
def card_kinds
  load_cards_data['kinds']
end
card_ranks() click to toggle source

Fetches all card ranks

@return [Array<String>]

@example

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

@api public

# File lib/zombie_battleground/api/extensions/cards.rb, line 78
def card_ranks
  load_cards_data['ranks']
end
card_rarities() click to toggle source

Fetches all card rarities

@return [Array<String>]

@example

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

@api public

# File lib/zombie_battleground/api/extensions/cards.rb, line 134
def card_rarities
  load_cards_data['rarities']
end
card_sets() click to toggle source

Fetches all card sets

@return [Array<String>]

@example

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

@api public

# File lib/zombie_battleground/api/extensions/cards.rb, line 92
def card_sets
  load_cards_data['sets']
end
card_types() click to toggle source

Fetches all card types

@return [Array<String>]

@example

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

@api public

# File lib/zombie_battleground/api/extensions/cards.rb, line 120
def card_types
  load_cards_data['types']
end
cards_by_faction(faction) click to toggle source

Fetches all cards with selected faction

@param faction [String]

@return [Array<ZombieBattleground::Api::Models::Card>]

@example

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

@api public

# 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) click to toggle source

Fetches all cards with selected kind

@param kind [String]

@return [Array<ZombieBattleground::Api::Models::Card>]

@example

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

@api public

# 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) click to toggle source

Fetches all cards with selected rank

@param rank [String]

@return [Array<ZombieBattleground::Api::Models::Card>]

@example

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

@api public

# 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) click to toggle source

Fetches all cards with selected rarity

@param rarity [String]

@return [Array<ZombieBattleground::Api::Models::Card>]

@example

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

@api public

# 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) click to toggle source

Fetches all cards with selected set

@param set [String]

@return [Array<ZombieBattleground::Api::Models::Card>]

@example

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

@api public

# 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) click to toggle source

Fetches all cards with selected type

@param type [String]

@return [Array<ZombieBattleground::Api::Models::Card>]

@example

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

@api public

# File lib/zombie_battleground/api/extensions/cards.rb, line 214
def cards_by_type(type)
  all_cards(type: type).to_a
end

Private Instance Methods

load_cards_data() click to toggle source

Loads the helper data for cards

@return [Hash]

@api private

# File lib/zombie_battleground/api/extensions/cards.rb, line 242
def load_cards_data
  @load_cards_data ||= YAML.safe_load(File.read(File.join(__dir__, 'cards.yml')))
end