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.
Represents a collection of cards.
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Class Method Summary collapse
- .from_card_and_counts(set) ⇒ Object deprecated Deprecated.
- .from_deck_code(deck_code) ⇒ Object
Instance Method Summary collapse
- #-(other) ⇒ Object
- #as_card_and_counts ⇒ Object deprecated Deprecated.
- #count_for_card_code(code) ⇒ Object
-
#initialize(cards) ⇒ CardSet
constructor
A new instance of CardSet.
Constructor Details
#initialize(cards) ⇒ CardSet
Returns a new instance of CardSet.
12 13 14 |
# File 'lib/runeterra_cards/card_set.rb', line 12 def initialize(cards) @cards = cards end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
10 11 12 |
# File 'lib/runeterra_cards/card_set.rb', line 10 def cards @cards end |
Class Method Details
.from_card_and_counts(set) ⇒ Object
Deprecated.
17 18 19 |
# File 'lib/runeterra_cards/card_set.rb', line 17 def self.from_card_and_counts(set) new(Hash[set.map { |cac| [cac.code, cac.count] }]) end |
.from_deck_code(deck_code) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/runeterra_cards/card_set.rb', line 45 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.equal? 1 int_array = binary_data[1..].unpack('w*') cards = assemble_card_list(int_array) from_card_and_counts(cards) end |
Instance Method Details
#-(other) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/runeterra_cards/card_set.rb', line 21 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.equal?(0) end CardSet.new(remaining_cards) end |
#as_card_and_counts ⇒ Object
Deprecated.
32 33 34 |
# File 'lib/runeterra_cards/card_set.rb', line 32 def as_card_and_counts cards.map { |code, count| CardAndCount.new(code: code, count: count) } end |
#count_for_card_code(code) ⇒ Object
36 37 38 |
# File 'lib/runeterra_cards/card_set.rb', line 36 def count_for_card_code(code) cards[code] || 0 end |