mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
refactor glided rose kata
This commit is contained in:
parent
e43a1a270f
commit
c7d64d3330
@ -7,12 +7,30 @@ class GildedRose
|
|||||||
def update_quality()
|
def update_quality()
|
||||||
@items.each do |item|
|
@items.each do |item|
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
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.quality > 0
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
if item.name != "Sulfuras, Hand of Ragnaros"
|
||||||
item.quality = item.quality - 1
|
item.quality = item.quality - 1
|
||||||
|
if item.name == "Conjured"
|
||||||
|
if item.quality > 0
|
||||||
|
item.quality = item.quality - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def quantity_less_than_50(item)
|
||||||
if item.quality < 50
|
if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
||||||
@ -29,10 +47,17 @@ class GildedRose
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_sell_in(item)
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
if item.name != "Sulfuras, Hand of Ragnaros"
|
||||||
item.sell_in = item.sell_in - 1
|
item.sell_in = item.sell_in - 1
|
||||||
end
|
end
|
||||||
if item.sell_in < 0
|
if item.sell_in < 0
|
||||||
|
check_expired_item(item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_expired_item(item)
|
||||||
if item.name != "Aged Brie"
|
if item.name != "Aged Brie"
|
||||||
if item.name != "Backstage passes to a TAFKAL80ETC concert"
|
if item.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||||
if item.quality > 0
|
if item.quality > 0
|
||||||
@ -49,7 +74,12 @@ class GildedRose
|
|||||||
end
|
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
|
end
|
||||||
|
check_expired_item(item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user