Exception: RuneterraCards::MetadataLoadError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/runeterra_cards/errors.rb

Overview

This exception is raised if you try to parse data from Runeterra Data Dragon that is not in the expected form. The message will tell you what data was not right, and the #card attribute will tell you which card had issues, if possible.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(card, problem) ⇒ MetadataLoadError

Returns a new instance of MetadataLoadError.

Parameters:

  • card (String)

    The card’s name or cardCode.

  • problem (String)

    Details on the problem encountered loading the card.



82
83
84
85
86
87
88
89
# File 'lib/runeterra_cards/errors.rb', line 82

def initialize(card, problem)
  if card.nil?
    super("Error loading data for unknown card (no code or name): #{problem}")
  else
    super("Error loading data for card #{card}: #{problem}")
  end
  @card = card
end

Instance Attribute Details

#cardString? (readonly)

Return the name or card code of the card that was missing an expected attribute.

Returns:

  • (String)

    name if the name was present

  • (String)

    card code if the name was not present

  • (nil)

    if neither name nor card code were present



78
79
80
# File 'lib/runeterra_cards/errors.rb', line 78

def card
  @card
end

Class Method Details

.invalid_rarity(card, given, expected) ⇒ MetadataLoadError

Create a MetadataLoadError with a helpful message regarding an invalid value for rarityRef.

Parameters:

  • card (String)

    The card name that had an invalid rarityRef value.

  • given (String)

    The value that rarityRef had.

  • expected (Enumerable<String>)

    A list of values that would have been valid.

Returns:



97
98
99
# File 'lib/runeterra_cards/errors.rb', line 97

def self.invalid_rarity(card, given, expected)
  new(card, "Invalid value for rarityRef, got: #{given}, expected one of: #{expected.join ', '}")
end