From ad848a8e141089fdd49989a15d4efe6d3a9164e4 Mon Sep 17 00:00:00 2001 From: Maarten Parmentier Date: Tue, 27 Jun 2023 22:09:44 +0200 Subject: [PATCH] Clean up the update_quality method by adding an item-class mapping --- ruby/gilded_rose.rb | 20 ++++++++------------ texttests/ThirtyDays/stdout.gr | 8 ++++---- texttests/config.gr | 4 ++-- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index 13318793..406b934e 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -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 diff --git a/texttests/ThirtyDays/stdout.gr b/texttests/ThirtyDays/stdout.gr index a04e48ac..4e7237ff 100644 --- a/texttests/ThirtyDays/stdout.gr +++ b/texttests/ThirtyDays/stdout.gr @@ -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 diff --git a/texttests/config.gr b/texttests/config.gr index 877deb22..60faf6c9 100755 --- a/texttests/config.gr +++ b/texttests/config.gr @@ -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