Class: Hearthstone::Models::CardStore
- Inherits:
-
Object
- Object
- Hearthstone::Models::CardStore
- Defined in:
- lib/hearthstone/models/card_store.rb
Constant Summary collapse
- STORE_FILE =
"./AllSetsAllLanguages.json"
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
- #card_with_id(id) ⇒ Object
-
#initialize(lang = "enUS") ⇒ CardStore
constructor
A new instance of CardStore.
Constructor Details
#initialize(lang = "enUS") ⇒ CardStore
Returns a new instance of CardStore.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hearthstone/models/card_store.rb', line 11 def initialize(lang="enUS") filename = File.join(File.dirname(__FILE__), STORE_FILE) config = JSON(File.read(filename)) @cards = {} if config[lang] config[lang].each do |set, cards_data| cards_data.each do |data| card = Card.new card.name = data["name"] card.cost = data["cost"] card.type = data["type"] card.rarity = data["rarity"] card.faction = data["faction"] card.text = data["text"] card.mechanics = data["mechanics"] card.flavor = data["flavor"] card.artist = data["artist"] card.attack = data["attack"] card.health = data["health"] card.collectible = data["collectible"] card.id = data["id"] card.elite = data["elite"] @cards[card.id] = card end end else raise "language '#{lang}'' not found!" end end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
9 10 11 |
# File 'lib/hearthstone/models/card_store.rb', line 9 def cards @cards end |
Instance Method Details
#card_with_id(id) ⇒ Object
45 46 47 |
# File 'lib/hearthstone/models/card_store.rb', line 45 def card_with_id(id) @cards[id] end |