Last active
April 24, 2017 15:37
-
-
Save seanlerner/1f3ea6ebfe6b2f40399cea058f1e3c4b to your computer and use it in GitHub Desktop.
Gilded Rose Ruby Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GildedRose | |
attr_reader :name, :days_remaining, :quality | |
∞ = Float::INFINITY | |
CHEESE = { | |
'Normal Item' => { -∞..0 => -2, 1..∞ => -1 }, | |
'Aged Brie' => { -∞..0 => 2, 1..∞ => 1 }, | |
'Conjured Mana Cake' => { -∞..0 => -4, 1..∞ => -2 }, | |
'Backstage passes to a TAFKAL80ETC concert' => { -∞..0 => -∞, 1..5 => 3, 6..10 => 2, 10..∞ => 1 } | |
} | |
def initialize(name:, days_remaining:, quality:) | |
@name = name | |
@days_remaining = days_remaining | |
@quality = quality | |
end | |
def tick | |
return if name == 'Sulfuras, Hand of Ragnaros' | |
@quality += CHEESE[name].select { |range| range === days_remaining }.values.first | |
@quality = quality.clamp(0, 50) | |
@days_remaining -= 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment