mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-04 09:11:39 +00:00
refactoring gildedrose
This commit is contained in:
parent
a348b20789
commit
260659349e
@ -1,56 +1,49 @@
|
||||
class GildedRose
|
||||
|
||||
def initialize(items)
|
||||
@items = items
|
||||
end
|
||||
|
||||
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
|
||||
next if item.name == "Sulfuras, Hand of Ragnaros"
|
||||
|
||||
if item.name == "Aged Brie"
|
||||
item.quality += 1 if item.quality < 50
|
||||
elsif item.name == "Backstage passes to a TAFKAL80ETC concert"
|
||||
increases_proportionally_to_age(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
|
||||
decrease_quality(item)
|
||||
end
|
||||
|
||||
item.sell_in -= 1 if item.name != "Sulfuras, Hand of Ragnaros"
|
||||
|
||||
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.name == "Aged Brie"
|
||||
item.quality += 1 if item.quality < 50
|
||||
elsif item.name == "Backstage passes to a TAFKAL80ETC concert"
|
||||
item.quality = 0
|
||||
else
|
||||
if item.quality < 50
|
||||
item.quality = item.quality + 1
|
||||
end
|
||||
decrease_quality(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def decrease_quality(item)
|
||||
decrement = item.name == "Conjured" ? 2 : 1
|
||||
item.quality -= decrement if item.quality > 0
|
||||
end
|
||||
|
||||
def increases_proportionally_to_age(item)
|
||||
if item.sell_in <= 10
|
||||
item.quality += 1 if item.quality < 50
|
||||
end
|
||||
if item.sell_in <= 5
|
||||
item.quality += 1 if item.quality < 50
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Item
|
||||
|
||||
Loading…
Reference in New Issue
Block a user