mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Clean up the update_quality method by adding an item-class mapping
This commit is contained in:
parent
fbae17fd32
commit
ad848a8e14
@ -8,24 +8,20 @@ class GildedRose
|
||||
QUALITY_LOWER_LIMIT = 0
|
||||
QUALITY_UPPER_LIMIT = 50
|
||||
|
||||
SPECIALITY_ITEM_MAPPER = {
|
||||
'Aged Brie' => BrieItem,
|
||||
'Backstage passes to a TAFKAL80ETC concert' => BackstagePassItem,
|
||||
'Conjured Mana Cake' => ConjuredItem,
|
||||
'Sulfuras, Hand of Ragnaros' => SulfuraItem
|
||||
}.freeze
|
||||
|
||||
def initialize(items)
|
||||
@items = items
|
||||
end
|
||||
|
||||
def update_quality
|
||||
@items.each do |item|
|
||||
case item.name
|
||||
when 'Aged Brie'
|
||||
BrieItem.new(item).spend_day_in_shop
|
||||
when 'Backstage passes to a TAFKAL80ETC concert'
|
||||
BackstagePassItem.new(item).spend_day_in_shop
|
||||
when 'Conjured Mana Cake'
|
||||
ConjuredItem.new(item).spend_day_in_shop
|
||||
when 'Sulfuras, Hand of Ragnaros'
|
||||
SulfuraItem.new(item).spend_day_in_shop
|
||||
else
|
||||
NormalItem.new(item).spend_day_in_shop
|
||||
end
|
||||
(SPECIALITY_ITEM_MAPPER[item.name] || NormalItem).new(item).spend_day_in_shop
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -21,7 +21,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 14, 21
|
||||
Backstage passes to a TAFKAL80ETC concert, 9, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 4, 50
|
||||
Conjured Mana Cake, 2, 5
|
||||
Conjured Mana Cake, 2, 4
|
||||
|
||||
-------- day 2 --------
|
||||
name, sellIn, quality
|
||||
@ -33,7 +33,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 13, 22
|
||||
Backstage passes to a TAFKAL80ETC concert, 8, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 3, 50
|
||||
Conjured Mana Cake, 1, 4
|
||||
Conjured Mana Cake, 1, 2
|
||||
|
||||
-------- day 3 --------
|
||||
name, sellIn, quality
|
||||
@ -45,7 +45,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 12, 23
|
||||
Backstage passes to a TAFKAL80ETC concert, 7, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 2, 50
|
||||
Conjured Mana Cake, 0, 3
|
||||
Conjured Mana Cake, 0, 0
|
||||
|
||||
-------- day 4 --------
|
||||
name, sellIn, quality
|
||||
@ -57,7 +57,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 11, 24
|
||||
Backstage passes to a TAFKAL80ETC concert, 6, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 1, 50
|
||||
Conjured Mana Cake, -1, 1
|
||||
Conjured Mana Cake, -1, 0
|
||||
|
||||
-------- day 5 --------
|
||||
name, sellIn, quality
|
||||
|
||||
@ -17,8 +17,8 @@ diff_program:meld
|
||||
# note you'll also need to update the file environment.gr with your classpath if you keep your classfiles somewhere unusual
|
||||
|
||||
# Settings for the Ruby version
|
||||
#executable:${TEXTTEST_HOME}/ruby/texttest_fixture.rb
|
||||
#interpreter:ruby
|
||||
executable:${TEXTTEST_HOME}/ruby/texttest_fixture.rb
|
||||
interpreter:ruby
|
||||
|
||||
# Settings for the C# version
|
||||
#executable:${TEXTTEST_HOME}/csharp/bin/Debug/csharp.exe
|
||||
|
||||
Loading…
Reference in New Issue
Block a user