Class: RuneterraCards::Cost
- Inherits:
-
Object
- Object
- RuneterraCards::Cost
- Defined in:
- lib/runeterra_cards/cost.rb
Overview
Represents the cost of a CardSet, as wildcards or shards. To get the cost of a CardSet you need to call Metadata#cost_of, as rarity (and therefore cost) is a property of metadata.
A Cost object tells you how many wildcards would be needed to craft a CardSet, or alternatively how many shards would be needed. You can figure out the cost of a mixture of wildcards and shards by creating a new Cost object representing the wildcards to be spent, and subtracting that from the original Cost object.
Instance Attribute Summary collapse
-
#champion ⇒ Fixnum
readonly
The number of Champion wildcards needed.
-
#common ⇒ Fixnum
readonly
The number of Common wildcards needed.
-
#epic ⇒ Fixnum
readonly
The number of Epic wildcards needed.
-
#rare ⇒ Fixnum
readonly
The number of Rare wildcards needed.
Instance Method Summary collapse
-
#-(other) ⇒ Cost
Subtracts another Cost from this one.
-
#==(other) ⇒ Boolean
Whether this Cost is equal to another.
-
#initialize(common, rare, epic, champion) ⇒ Cost
constructor
A new instance of Cost.
-
#shards ⇒ Fixnum
The number of shards needed.
Constructor Details
#initialize(common, rare, epic, champion) ⇒ Cost
Returns a new instance of Cost.
51 52 53 |
# File 'lib/runeterra_cards/cost.rb', line 51 def initialize(common, rare, epic, champion) @common, @rare, @epic, @champion = common, rare, epic, champion end |
Instance Attribute Details
#champion ⇒ Fixnum (readonly)
The number of Champion wildcards needed
45 46 47 |
# File 'lib/runeterra_cards/cost.rb', line 45 def champion @champion end |
#common ⇒ Fixnum (readonly)
The number of Common wildcards needed
33 34 35 |
# File 'lib/runeterra_cards/cost.rb', line 33 def common @common end |
#epic ⇒ Fixnum (readonly)
The number of Epic wildcards needed
41 42 43 |
# File 'lib/runeterra_cards/cost.rb', line 41 def epic @epic end |
#rare ⇒ Fixnum (readonly)
The number of Rare wildcards needed
37 38 39 |
# File 'lib/runeterra_cards/cost.rb', line 37 def rare @rare end |
Instance Method Details
#-(other) ⇒ Cost
This will not return negative values.
Subtracts another Cost from this one. Subtraction is performed by subtracting each wildcard type individually, not by operating on the shard count. The minimum value any wildcard will have is zero, so 5 - 7 = 0 for example.
86 87 88 89 90 91 92 93 |
# File 'lib/runeterra_cards/cost.rb', line 86 def -(other) Cost.new( [common - other.common, 0].max, [rare - other.rare, 0].max, [epic - other.epic, 0].max, [champion - other.champion, 0].max ) end |
#==(other) ⇒ Boolean
Whether this Cost is equal to another. Equality means exactly the same number of each wildcard, not just the same shard count.
68 69 70 71 72 73 |
# File 'lib/runeterra_cards/cost.rb', line 68 def ==(other) common.eql?(other.common) && rare.eql?(other.rare) && epic.eql?(other.epic) && champion.eql?(other.champion) end |
#shards ⇒ Fixnum
The number of shards needed. I.e. the equivalent amount of shards for all these wildcards.
57 58 59 60 61 62 |
# File 'lib/runeterra_cards/cost.rb', line 57 def shards (common * 100) + (rare * 300) + (epic * 1200) + (champion * 3000) end |