diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index 622ae121..ed7b98a4 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -9,6 +9,8 @@ class GildedRose case item.name when 'Aged Brie' update_aged_brie_quality(item) + when 'Backstage passes to a TAFKAL80ETC concert' + update_backstage_passes_quality(item) when 'Sulfuras, Hand of Ragnaros' update_sulfuras_quality(item) else @@ -61,6 +63,16 @@ class GildedRose item.quality = 50 if item.quality > 50 end + def update_backstage_passes_quality(item) + item.sell_in -= 1 + return item.quality = 0 if item.sell_in.negative? + + item.quality += 1 + item.quality += 1 if item.sell_in < 10 + item.quality += 1 if item.sell_in < 5 + item.quality = 50 if item.quality > 50 + end + def update_sulfuras_quality(item); end end diff --git a/ruby/specs/gilded_rose_spec.rb b/ruby/specs/gilded_rose_spec.rb index e1213d7c..7f3d0c62 100644 --- a/ruby/specs/gilded_rose_spec.rb +++ b/ruby/specs/gilded_rose_spec.rb @@ -188,7 +188,7 @@ describe GildedRose do context 'when 1 day left' do let(:sell_in) { 1 } - it 'increases quality by 1' do + it 'increases quality by 3' do subject.update_quality expect(items[0].quality).to eq 6 end @@ -202,7 +202,7 @@ describe GildedRose do context 'when sell by date has passed' do let(:sell_in) { 0 } - it 'increases quality by 2' do + it 'sets the quality to 0' do subject.update_quality expect(items[0].quality).to eq 0 end