module ZombieBattleground::Api::Extensions::Decks

API Extensions for Decks

Public Instance Methods

all_decks(**args) { |deck| ... } click to toggle source

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

@return [Enumerator]

@example Get an enumerator for the decks

ZombieBattleground::Api.all_decks
# => Enumerator

@example Dump all decks as an array

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

@example Return the first deck

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

@example Pass it a block

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

@api public

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

Return's the deck overlord (hero) type faction

@param type [Integer]

@return [String}

@example

deck_faction(0) # => "EARTH"

@api public

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

Return's the deck overlord (hero) faction weakness

@param type [Integer]

@return [String}

@example

deck_strong_against(0) # => "AIR"

@api public

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

Return's the deck overlord (hero) faction weakness

@param type [Integer]

@return [String}

@example

deck_weak_against(0) # => "FIRE"

@api public

# 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

Private Instance Methods

load_decks_data() click to toggle source

Loads the helper data for decks

@return [Hash]

@api private

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