From 6d4bc3f8afda7b36075cb99e73d06f9baa50f081 Mon Sep 17 00:00:00 2001 From: Maarten Parmentier Date: Tue, 27 Jun 2023 19:47:49 +0200 Subject: [PATCH] Extract the first item case: "Sulfuras" --- ruby/gilded_rose.rb | 73 +++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index e177a497..01261571 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -4,53 +4,54 @@ class GildedRose @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 - end + case item.name + when 'Sulfuras, Hand of Ragnaros' + update_sulfuras_quality(item) 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 + if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert" + if item.quality > 0 + item.quality = item.quality - 1 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 + item.sell_in = item.sell_in - 1 + if item.sell_in < 0 + if item.name != "Aged Brie" + if item.name != "Backstage passes to a TAFKAL80ETC concert" + if item.quality > 0 + item.quality = item.quality - 1 + end + else + item.quality = item.quality - item.quality + end + else + if item.quality < 50 + item.quality = item.quality + 1 + end end end end end end + + def update_sulfuras_quality(item); end end class Item