Class: RuneterraCards::Card

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

Overview

Represents a card.

@todo: add getters for set, faction, card number

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code: nil, set: nil, faction_number: nil, card_number: nil) ⇒ Card

Returns a new instance of Card.

Parameters:

  • set (Fixnum) (defaults to: nil)
  • faction_number (Fixnum) (defaults to: nil)
  • card_number (Fixnum) (defaults to: nil)


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

#codeString (readonly)

The card code, for example “01DE123”

Returns:

  • (String)


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.

Parameters:

Returns:

  • (Boolean)


32
33
34
# File 'lib/runeterra_cards/card.rb', line 32

def eql?(other)
  code.eql?(other.code)
end

#hashInteger

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?).

Returns:

  • (Integer)

See Also:

  • Object#hash.


41
42
43
# File 'lib/runeterra_cards/card.rb', line 41

def hash
  code.hash
end