Class: RuneterraCards::Metadata
- Inherits:
-
Object
- Object
- RuneterraCards::Metadata
- Defined in:
- lib/runeterra_cards/metadata.rb
Overview
This class cannot yet handle metadata for multiple locales at the same time. You will need multiple instances of this class, one for each locale, if you wish to handle multiple locales at this time.
Loads, stores, and retrieves data for cards from Legends of Runeterra Data Dragon set files. N.B. this does not ship with any metadata of its own, you must provide set files yourself and load them before this class will do anything.
Instance Method Summary collapse
-
#add_set_file(file_path) ⇒ Object
Load card data from a Legends of Runeterra Data Dragon set file, e.g.
-
#all_collectible ⇒ Hash<String,CardMetadata>
Returns all cards in the metadata set that are collectible.
-
#full_set ⇒ CardSet
Returns a [CardSet] that represents a complete card collection.
-
#initialize ⇒ Metadata
constructor
A new instance of Metadata.
-
#lookup_card(card_code) ⇒ CardMetadata
Fetch card metadata for a card via its card code.
Constructor Details
#initialize ⇒ Metadata
Returns a new instance of Metadata.
23 24 25 |
# File 'lib/runeterra_cards/metadata.rb', line 23 def initialize @cards = {} end |
Instance Method Details
#add_set_file(file_path) ⇒ Object
document and test exceptions that can be thrown here
Load card data from a Legends of Runeterra Data Dragon set file, e.g. “set1-en_us.json”
30 31 32 33 34 35 36 37 |
# File 'lib/runeterra_cards/metadata.rb', line 30 def add_set_file(file_path) file = File.read(file_path) data = JSON.parse(file) data.each do |card_data| card = CardMetadata.new(card_data) @cards[card.card_code] = card end end |
#all_collectible ⇒ Hash<String,CardMetadata>
Returns all cards in the metadata set that are collectible
50 51 52 |
# File 'lib/runeterra_cards/metadata.rb', line 50 def all_collectible @cards.select { |_, card| card.collectible? } end |
#full_set ⇒ CardSet
Returns a [CardSet] that represents a complete card collection. That is: 3x of every card that is collectible.
57 58 59 |
# File 'lib/runeterra_cards/metadata.rb', line 57 def full_set CardSet.new(all_collectible.keys.each_with_object({}) { |code, result| result[code] = 3 }) end |
#lookup_card(card_code) ⇒ CardMetadata
document errors if card_code doesn’t exist
Fetch card metadata for a card via its card code
43 44 45 |
# File 'lib/runeterra_cards/metadata.rb', line 43 def lookup_card(card_code) @cards.fetch(card_code) end |