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