diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index ed7b98a4..106aa2bd 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -14,43 +14,7 @@ class GildedRose when 'Sulfuras, Hand of Ragnaros' update_sulfuras_quality(item) else - if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert" - if item.quality > 0 - item.quality = item.quality - 1 - 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 - item.sell_in = item.sell_in - 1 - if item.sell_in < 0 - if item.name != "Aged Brie" - if item.name != "Backstage passes to a TAFKAL80ETC concert" - if item.quality > 0 - item.quality = item.quality - 1 - end - else - item.quality = item.quality - item.quality - end - else - if item.quality < 50 - item.quality = item.quality + 1 - end - end - end + update_normal_quality(item) end end end @@ -73,6 +37,13 @@ class GildedRose item.quality = 50 if item.quality > 50 end + def update_normal_quality(item) + item.sell_in -= 1 + item.quality -= 1 + item.quality -= 1 if item.sell_in.negative? + item.quality = 0 if item.quality.negative? + 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 7f3d0c62..98828409 100644 --- a/ruby/specs/gilded_rose_spec.rb +++ b/ruby/specs/gilded_rose_spec.rb @@ -23,20 +23,6 @@ describe GildedRose do end end - context 'when sell by date has passed' do - let(:sell_in) { 0 } - - it 'lowers quality by 2' do - subject.update_quality - expect(items[0].quality).to eq 1 - end - - it 'lowers sell_in by 1' do - subject.update_quality - expect(items[0].sell_in).to eq -1 - end - end - context 'when 1 day left' do let(:sell_in) { 1 } @@ -51,9 +37,23 @@ describe GildedRose do end end + context 'when sell by date has passed' do + let(:sell_in) { 0 } + + it 'lowers quality by 2' do + subject.update_quality + expect(items[0].quality).to eq 1 + end + + it 'lowers sell_in by 1' do + subject.update_quality + expect(items[0].sell_in).to eq -1 + end + end + it 'does never lower the quality below 0' do items = [Item.new(item_name, sell_in, 0)] - subject.update_quality + GildedRose.new(items).update_quality expect(items[0].quality).to eq 0 end end