Class: RuneterraCards::CardMetadata
- Inherits:
-
Object
- Object
- RuneterraCards::CardMetadata
- 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.
Instance Attribute Summary collapse
-
#card_code ⇒ String
readonly
Returns the card_code attribute.
-
#cost ⇒ Fixnum
readonly
Returns the cost attribute.
-
#name ⇒ String
readonly
Returns the name attribute.
-
#rarity ⇒ Symbol
readonly
Returns the card’s rarity as a symbol.
Instance Method Summary collapse
-
#collectible? ⇒ Boolean
Whether or not the card is collectible.
-
#initialize(hash) ⇒ CardMetadata
constructor
Creates a single CardMetadata Object from the supplied Hash of data.
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.
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_code ⇒ String (readonly)
Returns the card_code attribute. For example: “01NX055”.
27 28 29 |
# File 'lib/runeterra_cards/card_metadata.rb', line 27 def card_code @card_code end |
#cost ⇒ Fixnum (readonly)
Returns the cost attribute. For example: 3.
31 32 33 |
# File 'lib/runeterra_cards/card_metadata.rb', line 31 def cost @cost end |
#name ⇒ String (readonly)
Returns the name attribute. The name is the localised name that the card would have in game. For example: “House Spider”.
23 24 25 |
# File 'lib/runeterra_cards/card_metadata.rb', line 23 def name @name end |
#rarity ⇒ Symbol (readonly)
Returns the card’s rarity as a symbol. Can be one of: :none
, :common
, :rare
, :epic
, or :champion
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.
65 66 67 |
# File 'lib/runeterra_cards/card_metadata.rb', line 65 def collectible? @collectible end |