mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
extracted quality updates for backstage passes
This commit is contained in:
parent
146f686d14
commit
c0ae6e9988
@ -7,60 +7,50 @@ class GildedRose
|
||||
def self.update_quality(items)
|
||||
items.map do |item|
|
||||
if !special_item?(item)
|
||||
|
||||
update_normal_quality(item) if !sulfuras?(item)
|
||||
|
||||
else
|
||||
# start of block for brie and backstage quality logic
|
||||
if item.quality < 50
|
||||
item.quality = item.quality + 1
|
||||
if item.name.downcase.match /backstage/
|
||||
if item.sell_in < 11
|
||||
|
||||
item.quality = item.quality + 1
|
||||
|
||||
end
|
||||
if item.sell_in < 6
|
||||
|
||||
item.quality = item.quality + 1
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
# end of block for brie and backstage quality logic
|
||||
update_backstage_quality(item) if item.quality < 50
|
||||
end
|
||||
|
||||
# ______________________________________________________________________________________
|
||||
# start of block that reduces sell in
|
||||
if !sulfuras?(item)
|
||||
item.sell_in = item.sell_in - 1
|
||||
end
|
||||
# end of block that reduces sell in
|
||||
|
||||
|
||||
if item.sell_in < 0
|
||||
|
||||
if item.name != "Aged Brie"
|
||||
|
||||
if !item.name.downcase.match /backstage/
|
||||
update_normal_quality(item) unless sulfuras?(item)
|
||||
|
||||
update_normal_quality(item)
|
||||
else
|
||||
item.quality = 0
|
||||
end
|
||||
else
|
||||
if item.quality < 50
|
||||
item.quality = item.quality + 1
|
||||
end
|
||||
item.quality = item.quality + 1 if item.quality < 50
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_backstage_quality(item)
|
||||
case item.sell_in
|
||||
when (-(Float::INFINITY)..0)
|
||||
item.quality = 0
|
||||
when 0..5
|
||||
item.quality += 3
|
||||
when 6..10
|
||||
item.quality += 2
|
||||
when 10..Float::INFINITY
|
||||
item.quality += 1
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
def self.update_normal_quality(item)
|
||||
item.quality -= 1 unless item.quality.zero?
|
||||
|
||||
end
|
||||
|
||||
def self.sulfuras?(item)
|
||||
@ -72,6 +62,27 @@ class GildedRose
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Item
|
||||
attr_accessor :name, :sell_in, :quality
|
||||
|
||||
|
||||
@ -134,6 +134,37 @@ let(:sulfarus) { Item.new('Sulfuras, Hand of Ragnaros', 50, 80) }
|
||||
expect(GildedRose.special_item?(item_double)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_backstage_quality' do
|
||||
it 'increases in quality by one when sellIn is > 10 days' do
|
||||
items_double = double :item, name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 15, quality: 20
|
||||
expect(items_double).to receive(:quality=).with(21)
|
||||
GildedRose.update_backstage_quality(items_double)
|
||||
end
|
||||
|
||||
it 'increases in quality by 2 when sellin < 10 days' do
|
||||
items_double = double :item, name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 9, quality: 20
|
||||
expect(items_double).to receive(:quality=).with(22)
|
||||
GildedRose.update_backstage_quality(items_double)
|
||||
|
||||
end
|
||||
|
||||
it 'increases by 3 when sellin < 5' do
|
||||
items_double = double :item, name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 4, quality: 20
|
||||
expect(items_double).to receive(:quality=).with(23)
|
||||
GildedRose.update_backstage_quality(items_double)
|
||||
end
|
||||
|
||||
it 'decreases to 0 when sellin == 0' do
|
||||
items_double = double :item, name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 0, quality: 20
|
||||
expect(items_double).to receive(:quality=).with(0)
|
||||
GildedRose.update_backstage_quality(items_double)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_brie_quality' do
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user