From c7d64d3330c9b65e65f494d987dc868ea68efcfa Mon Sep 17 00:00:00 2001 From: shivani-330 <81970141+shivani-330@users.noreply.github.com> Date: Fri, 19 Jan 2024 19:32:27 +0530 Subject: [PATCH] refactor glided rose kata --- ruby/gilded_rose.rb | 98 +++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 34 deletions(-) diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index e177a497..f2c3b30b 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -7,50 +7,80 @@ class GildedRose def update_quality() @items.each do |item| if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert" + quality_greater_than_0(item) + else + quantity_less_than_50(item) + end + update_sell_in(item) + end + end + + private + + def quality_greater_than_0(item) + if item.quality > 0 + if item.name != "Sulfuras, Hand of Ragnaros" + item.quality = item.quality - 1 + if item.name == "Conjured" + if item.quality > 0 + item.quality = item.quality - 1 + end + end + end + end + end + + def quantity_less_than_50(item) + 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 + + def update_sell_in(item) + if item.name != "Sulfuras, Hand of Ragnaros" + item.sell_in = item.sell_in - 1 + end + if item.sell_in < 0 + check_expired_item(item) + end + end + + def check_expired_item(item) + 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 - 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 + item.quality = item.quality - item.quality 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 - else - if item.quality < 50 - item.quality = item.quality + 1 - end - end + else + if item.quality < 50 + item.quality = item.quality + 1 end end end + + def update_sell_in(item) + if item.name != "Sulfuras, Hand of Ragnaros" + item.sell_in = item.sell_in - 1 + end + check_expired_item(item) + end end class Item