mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-10 04:01:19 +00:00
customize current ruby code
This commit is contained in:
parent
eb11c58bdf
commit
a37f2a5225
@ -4,52 +4,66 @@ class GildedRose
|
|||||||
@items = items
|
@items = items
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_quality()
|
def update_quality
|
||||||
@items.each do |item|
|
@items.each { |item| update_item(item) }
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
end
|
||||||
if item.quality > 0
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
private
|
||||||
item.quality = item.quality - 1
|
|
||||||
end
|
def update_item(item)
|
||||||
end
|
validate_item(item)
|
||||||
else
|
case item.name
|
||||||
if item.quality < 50
|
when "Aged Brie"
|
||||||
item.quality = item.quality + 1
|
update_aged_brie(item)
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
when "Sulfuras, Hand of Ragnaros"
|
||||||
if item.sell_in < 11
|
item.quality = 80 # Ensure quality remains 80
|
||||||
if item.quality < 50
|
when "Backstage passes to a TAFKAL80ETC concert"
|
||||||
item.quality = item.quality + 1
|
update_backstage_passes(item)
|
||||||
end
|
else
|
||||||
end
|
update_standard_item(item)
|
||||||
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
|
||||||
|
item.sell_in -= 1 unless item.name == "Sulfuras, Hand of Ragnaros"
|
||||||
|
handle_expired(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_item(item)
|
||||||
|
raise StandardError, "Invalid sell_in value" unless item.sell_in.is_a?(Integer)
|
||||||
|
raise StandardError, "Invalid quality value" unless item.quality.is_a?(Integer)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_aged_brie(item)
|
||||||
|
increase_quality(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_backstage_passes(item)
|
||||||
|
increase_quality(item)
|
||||||
|
increase_quality(item) if item.sell_in <= 10
|
||||||
|
increase_quality(item) if item.sell_in <= 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_standard_item(item)
|
||||||
|
decrease_quality(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_expired(item)
|
||||||
|
return unless item.sell_in < 0
|
||||||
|
|
||||||
|
case item.name
|
||||||
|
when "Aged Brie"
|
||||||
|
increase_quality(item)
|
||||||
|
when "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
item.quality = 0
|
||||||
|
else
|
||||||
|
decrease_quality(item) unless item.name == "Sulfuras, Hand of Ragnaros"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def increase_quality(item)
|
||||||
|
item.quality += 1 if item.quality < 50
|
||||||
|
end
|
||||||
|
|
||||||
|
def decrease_quality(item)
|
||||||
|
item.quality -= 1 if item.quality > 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user