Class: RuneterraCards::CardMetadata

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

Overview

Represents metadata for a single card. Metadata is all meaning the game imbues upon a card code, including things like cost, health, etc and also localised information such as name and description.

Currently this class only represents a thin sliver of metadata as required by its downstream consumers.

See Also:

  • CardAndCount

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ CardMetadata

Creates a single RuneterraCards::CardMetadata Object from the supplied Hash of data. This is intended for use with the data files from Legends of Runeterra Data Dragon, and it expects a Hash representing a single card from the parsed JSON data files from Data Dragon.

Parameters:

  • hash (Hash)

    Card data from Legends of Runeterra Data Dragon

Options Hash (hash):

  • name (String)
  • cardCode (String)
  • collectible (Boolean)
  • cost (Fixnum)
  • rarityRef (String)

Raises:

  • (MissingCardDataError)

    if any of the expected hash parameters are missing, or if rarityRef contains an unexpected value.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/runeterra_cards/card_metadata.rb', line 50

def initialize(hash)
  begin
    @name, @card_code, @collectible, @cost, rarity_ref =
      hash.fetch_values('name', 'cardCode', 'collectible', 'cost', 'rarityRef')
  rescue KeyError => e
    raise MetadataLoadError.new(hash['name'] || hash['cardCode'], "Missing expected key: #{e.key}")
  end

  @rarity = RARITIES[rarity_ref]
  return unless rarity.nil?

  raise MetadataLoadError.invalid_rarity(name, rarity_ref, RARITIES.keys)
end

Instance Attribute Details

#card_codeString (readonly)

Returns the card_code attribute. For example: “01NX055”.

Returns:

  • (String)


27
28
29
# File 'lib/runeterra_cards/card_metadata.rb', line 27

def card_code
  @card_code
end

#costFixnum (readonly)

Returns the cost attribute. For example: 3.

Returns:

  • (Fixnum)


31
32
33
# File 'lib/runeterra_cards/card_metadata.rb', line 31

def cost
  @cost
end

#nameString (readonly)

Returns the name attribute. The name is the localised name that the card would have in game. For example: “House Spider”.

Returns:

  • (String)


23
24
25
# File 'lib/runeterra_cards/card_metadata.rb', line 23

def name
  @name
end

#raritySymbol (readonly)

Returns the card’s rarity as a symbol. Can be one of: :none, :common, :rare, :epic, or :champion

Returns:

  • (Symbol)


35
36
37
# File 'lib/runeterra_cards/card_metadata.rb', line 35

def rarity
  @rarity
end

Instance Method Details

#collectible?Boolean

Whether or not the card is collectible.

Returns:

  • (Boolean)


65
66
67
# File 'lib/runeterra_cards/card_metadata.rb', line 65

def collectible?
  @collectible
end