diff --git a/ruby/.ruby-version b/ruby/.ruby-version new file mode 100644 index 00000000..35d16fb1 --- /dev/null +++ b/ruby/.ruby-version @@ -0,0 +1 @@ +2.5.7 diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index 3b299af0..22638f50 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -1,54 +1,48 @@ class GildedRose - def initialize(items) @items = items end - def update_quality() + def update_quality @items.each do |item| - if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert" - if item.quality > 0 - if item.name != "Sulfuras, Hand of Ragnaros" - item.quality = item.quality - 1 - end + next if item.name == 'Sulfuras, Hand of Ragnaros' + + item.sell_in -= 1 + + quality_change = case item.name + when 'Backstage passes to a TAFKAL80ETC concert' + if item.sell_in.negative? + item.quality = 0 + next end - else - if item.quality < 50 - item.quality = item.quality + 1 - if item.name == "Backstage passes to a TAFKAL80ETC concert" - if item.sell_in < 11 - if item.quality < 50 - item.quality = item.quality + 1 - end - end - if item.sell_in < 6 - if item.quality < 50 - item.quality = item.quality + 1 - end - end - end - end - end - if item.name != "Sulfuras, Hand of Ragnaros" - item.sell_in = item.sell_in - 1 - end - if item.sell_in < 0 - if item.name != "Aged Brie" - if item.name != "Backstage passes to a TAFKAL80ETC concert" - if item.quality > 0 - if item.name != "Sulfuras, Hand of Ragnaros" - item.quality = item.quality - 1 - end - end - else - item.quality = item.quality - item.quality - end + + if item.sell_in >= 10 + 1 + elsif item.sell_in >= 5 + 2 else - if item.quality < 50 - item.quality = item.quality + 1 - end + 3 end + when 'Conjured Mana Cake' + item.sell_in < 0 ? 4 : 2 + else + quality_degradation = item.sell_in < 0 ? 2 : 1 + + quality_degradation *= 2 if item.name.start_with?('Conjured') + + quality_degradation end + + new_quality = if [ + 'Aged Brie', + 'Backstage passes to a TAFKAL80ETC concert', + ].include?(item.name) + item.quality + quality_change + else + item.quality - quality_change + end + + item.quality = [[new_quality, 50].min, 0].max end end end