Class: RuneterraCards::Card
- Inherits:
-
Object
- Object
- RuneterraCards::Card
- Defined in:
- lib/runeterra_cards/card.rb
Overview
Represents a card.
@todo: add getters for set, faction, card number
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
The card code, for example “01DE123”.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Returns
true
if this and other both have the same card code. -
#hash ⇒ Integer
Compute a hash code for this card.
-
#initialize(code: nil, set: nil, faction_number: nil, card_number: nil) ⇒ Card
constructor
A new instance of Card.
Constructor Details
#initialize(code: nil, set: nil, faction_number: nil, card_number: nil) ⇒ Card
Returns a new instance of Card.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/runeterra_cards/card.rb', line 15 def initialize(code: nil, set: nil, faction_number: nil, card_number: nil) if code raise if set || faction_number || card_number @code = code else padded_set = format('%<i>02d', i: set) faction = FACTION_IDENTIFIERS_FROM_INT.fetch(faction_number) { |key| raise UnrecognizedFactionError, key } padded_card_number = format('%<i>03d', i: card_number) @code = "#{padded_set}#{faction}#{padded_card_number}" end end |
Instance Attribute Details
#code ⇒ String (readonly)
The card code, for example “01DE123”
10 11 12 |
# File 'lib/runeterra_cards/card.rb', line 10 def code @code end |
Instance Method Details
#eql?(other) ⇒ Boolean
Returns true
if this and other both have the same card code.
32 33 34 |
# File 'lib/runeterra_cards/card.rb', line 32 def eql?(other) code.eql?(other.code) end |
#hash ⇒ Integer
Compute a hash code for this card. Two cards with the same card code will have the same hash code (and will compare using #eql?).
41 42 43 |
# File 'lib/runeterra_cards/card.rb', line 41 def hash code.hash end |