Class: RuneterraCards::CardSet
- Inherits:
-
Object
- Object
- RuneterraCards::CardSet
- Defined in:
- lib/runeterra_cards/card_set.rb
Overview
TODO:
The API to this class is very unstable and will change a lot in a coming release.
TODO:
add #== !
Represents a collection of cards.
Instance Attribute Summary collapse
- #cards ⇒ Hash{String => Number} readonly deprecated Deprecated.
Class Method Summary collapse
-
.from_deck_code(deck_code) ⇒ CardSet
Parse a Deck Code.
Instance Method Summary collapse
-
#-(other) ⇒ CardSet
Subtract another CardSet from this one.
-
#as_card_codes ⇒ Enumerable<String => Number>
Return all cards in the card set as a map of card codes to counts.
- #as_cards ⇒ Enumerable<Card => Number>
-
#count_for_card_code(code) ⇒ Integer
Returns how many of the given card are in this CardSet.
-
#initialize(cards) ⇒ CardSet
constructor
A new instance of CardSet.
Constructor Details
#initialize(cards) ⇒ CardSet
Returns a new instance of CardSet.
20 21 22 |
# File 'lib/runeterra_cards/card_set.rb', line 20 def initialize(cards) @cards = cards end |
Instance Attribute Details
#cards ⇒ Hash{String => Number} (readonly)
Deprecated.
17 18 19 |
# File 'lib/runeterra_cards/card_set.rb', line 17 def cards @cards end |
Class Method Details
.from_deck_code(deck_code) ⇒ CardSet
Parse a Deck Code.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/runeterra_cards/card_set.rb', line 65 def self.from_deck_code(deck_code) binary_data = decode_base32(deck_code) format, version = decode_format_and_version(binary_data[0]) raise UnrecognizedVersionError.new(SUPPORTED_VERSION, version) unless version <= SUPPORTED_VERSION raise unless format.eql? 1 int_array = unpack_big_endian_varint(binary_data[1..]) cards = assemble_card_list(int_array) new(cards.to_h) end |
Instance Method Details
#-(other) ⇒ CardSet
28 29 30 31 32 33 34 35 36 |
# File 'lib/runeterra_cards/card_set.rb', line 28 def -(other) remaining_cards = cards.each_with_object({}) do |(code, count), result| new_count = count - other.count_for_card_code(code) result[code] = new_count unless new_count.eql?(0) end CardSet.new(remaining_cards) end |
#as_card_codes ⇒ Enumerable<String => Number>
Return all cards in the card set as a map of card codes to counts.
47 48 49 |
# File 'lib/runeterra_cards/card_set.rb', line 47 def as_card_codes cards end |
#as_cards ⇒ Enumerable<Card => Number>
39 40 41 |
# File 'lib/runeterra_cards/card_set.rb', line 39 def as_cards cards.transform_keys { |code| Card.new(code: code) } end |
#count_for_card_code(code) ⇒ Integer
Returns how many of the given card are in this CardSet.
54 55 56 |
# File 'lib/runeterra_cards/card_set.rb', line 54 def count_for_card_code(code) cards[code] || 0 end |