mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 23:41:27 +00:00
add item degradation map, comment legacy code
This commit is contained in:
parent
f7a3312e6b
commit
137dad8311
@ -5,50 +5,86 @@ class GildedRose
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_quality()
|
def update_quality()
|
||||||
|
non_degrading_items = ["Aged Brie", "Backstage passes to a TAFKAL80ETC concert", "Sulfuras, Hand of Ragnaros"]# Do not degrade in quality
|
||||||
|
|
||||||
|
item_degradation_map = {
|
||||||
|
# Item Type (substring to look for) | Quality Increment Per Day
|
||||||
|
"Aged Brie": 1,
|
||||||
|
"Backstage passes": {
|
||||||
|
default: 1,
|
||||||
|
ten_days_or_less: 2,
|
||||||
|
five_days_or_less: 3
|
||||||
|
},
|
||||||
|
"Conjured": -2,
|
||||||
|
"Sulfuras": 0,
|
||||||
|
"Default": -1
|
||||||
|
}
|
||||||
|
|
||||||
@items.each do |item|
|
@items.each do |item|
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
|
||||||
if item.quality > 0
|
# Item Quality can not be negative or over 50
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
|
||||||
item.quality = item.quality - 1
|
quality_update_allowed = item.quality == 0 || item.quality > 50 ? false : true
|
||||||
end
|
item_expired = item.sell_in < 0 ? true : false
|
||||||
end
|
|
||||||
else
|
if quality_update_allowed
|
||||||
if item.quality < 50
|
# Find the item type by substring
|
||||||
item.quality = item.quality + 1
|
puts "hi"
|
||||||
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
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if item.quality < 50
|
|
||||||
item.quality = item.quality + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# case item.name
|
||||||
|
# when "Aged Brie"
|
||||||
|
|
||||||
|
# when "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
|
||||||
|
# when "Sulfuras, Hand of Ragnaros"
|
||||||
|
|
||||||
|
# else
|
||||||
|
|
||||||
|
# end
|
||||||
|
# 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
|
||||||
|
# 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
|
||||||
|
# end
|
||||||
|
# else
|
||||||
|
# if item.quality < 50
|
||||||
|
# item.quality = item.quality + 1
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user