mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Update gilded_rose.rb
This commit is contained in:
parent
2e30c563d8
commit
320445b08b
@ -1,56 +1,71 @@
|
|||||||
class GildedRose
|
class GildedRose
|
||||||
|
def self.update_quality(items)
|
||||||
def initialize(items)
|
items.each do |item|
|
||||||
@items = items
|
update_item_quality(item)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_quality()
|
private
|
||||||
@items.each do |item|
|
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
def self.update_item_quality(item)
|
||||||
if item.quality > 0
|
case item.name
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
when "Aged Brie"
|
||||||
item.quality = item.quality - 1
|
update_aged_brie(item)
|
||||||
end
|
when "Backstage passes to a TAFKAL80ETC concert"
|
||||||
end
|
update_backstage_passes(item)
|
||||||
else
|
when "Sulfuras, Hand of Ragnaros"
|
||||||
if item.quality < 50
|
# Sulfuras does not change, nothing to do
|
||||||
item.quality = item.quality + 1
|
when "Conjured"
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
update_conjured(item)
|
||||||
if item.sell_in < 11
|
else
|
||||||
if item.quality < 50
|
update_normal_item(item)
|
||||||
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
|
||||||
|
|
||||||
|
def self.update_aged_brie(item)
|
||||||
|
increase_quality(item)
|
||||||
|
decrease_sell_in(item)
|
||||||
|
increase_quality(item) if item.sell_in.negative?
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.update_backstage_passes(item)
|
||||||
|
increase_quality(item)
|
||||||
|
decrease_sell_in(item)
|
||||||
|
|
||||||
|
if item.sell_in < 10
|
||||||
|
increase_quality(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
if item.sell_in < 5
|
||||||
|
increase_quality(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
item.quality = 0 if item.sell_in.negative?
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.update_conjured(item)
|
||||||
|
decrease_quality(item, 2)
|
||||||
|
decrease_sell_in(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.update_normal_item(item)
|
||||||
|
decrease_quality(item)
|
||||||
|
decrease_sell_in(item)
|
||||||
|
decrease_quality(item, 1) if item.sell_in.negative?
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.decrease_quality(item, amount = 1)
|
||||||
|
item.quality -= amount if item.quality.positive?
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.increase_quality(item)
|
||||||
|
item.quality += 1 if item.quality < 50
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.decrease_sell_in(item)
|
||||||
|
item.sell_in -= 1 unless item.name == "Sulfuras, Hand of Ragnaros"
|
||||||
|
item.sell_in = 0 if item.name == "Aged Brie" && item.sell_in.negative?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user