Method: Deckstrings::Deck.encode

Defined in:
lib/deckstrings/deckstrings.rb

.encode(format:, heroes:, cards:) ⇒ String

Encodes a Hearthstone deck as a compact deckstring.

This method validates card counts, format, and each hero/card ID.

All IDs refer to unique Hearthstone DBF IDs which can be seen in HearthstoneJSON metadata.

Examples:

deckstring = Deckstrings::Deck.encode(format: 2, heroes: [637], cards: { 1004 => 2, 315 => 2 })
deckstring = Deckstrings::Deck.encode(
  format: Deckstrings::Format.standard,
  heroes: [Deckstrings::Hero.mage],
  cards: { 1004 => 2, 315 => 2 }
)

Parameters:

  • format (Integer, Deckstrings::Format)

    Format for this deck: wild or standard.

  • heroes (Array<Integer, Deckstrings::Hero>)

    Heroes for this deck. Multiple heroes are supported, but typically this array will contain one element.

  • cards (Hash{Integer, Deckstrings::Card => Integer})

    Cards in the deck. A Hash from card ID to its instance count in the deck.

Returns:

  • (String)

    Base64-encoded compact byte string representing the deck.

Raises:

  • (FormatError)

    If any card counts are less than 1, or if any IDs do not refer to valid Hearthstone entities.

See Also:



361
362
363
364
365
366
367
# File 'lib/deckstrings/deckstrings.rb', line 361

def self.encode(format:, heroes:, cards:)
  begin
    Deck.new(format: format, heroes: heroes, cards: cards).deckstring
  rescue ArgumentError => e
    raise FormatError, e.to_s
  end
end