diff --git a/GildedRose/python/gilded_rose.py b/GildedRose/python/gilded_rose.py index 67ea3849..69459ac3 100755 --- a/GildedRose/python/gilded_rose.py +++ b/GildedRose/python/gilded_rose.py @@ -1,38 +1,41 @@ # -*- coding: utf-8 -*- +class GildedRose(object): -def update_quality(items): - for item in items: - if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert": - if item.quality > 0: - if item.name != "Sulfuras, Hand of Ragnaros": - item.quality = item.quality - 1 - 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 - if item.sell_in < 6: - if item.quality < 50: - item.quality = item.quality + 1 - if item.name != "Sulfuras, Hand of Ragnaros": - 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: - if item.name != "Sulfuras, Hand of Ragnaros": - item.quality = item.quality - 1 - else: - item.quality = item.quality - item.quality + def __init__(self, items): + self.items = items + + def update_quality(self): + for item in self.items: + if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert": + if item.quality > 0: + if item.name != "Sulfuras, Hand of Ragnaros": + item.quality = item.quality - 1 else: if item.quality < 50: item.quality = item.quality + 1 - return items - + if item.name == "Backstage passes to a TAFKAL80ETC concert": + if item.sell_in < 11: + if item.quality < 50: + item.quality = item.quality + 1 + if item.sell_in < 6: + if item.quality < 50: + item.quality = item.quality + 1 + if item.name != "Sulfuras, Hand of Ragnaros": + 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: + if item.name != "Sulfuras, Hand of Ragnaros": + item.quality = item.quality - 1 + else: + item.quality = item.quality - item.quality + else: + if item.quality < 50: + item.quality = item.quality + 1 + class Item: def __init__(self, name, sell_in, quality): self.name = name diff --git a/GildedRose/python/test_gilded_rose.py b/GildedRose/python/test_gilded_rose.py index e615c2ca..51480d19 100644 --- a/GildedRose/python/test_gilded_rose.py +++ b/GildedRose/python/test_gilded_rose.py @@ -1,14 +1,15 @@ # -*- coding: utf-8 -*- import unittest -from gilded_rose import Item, update_quality + +from gilded_rose import Item, GildedRose class GildedRoseTest(unittest.TestCase): def test_foo(self): items = [Item("foo", 0, 0)] - update_quality(items) + gilded_rose = GildedRose(items) + gilded_rose.update_quality() self.assertEquals("fixme", items[0].name) - -if __name__ == "__main__": +if __name__ == '__main__': unittest.main() diff --git a/GildedRose/ruby/gilded_rose.rb b/GildedRose/ruby/gilded_rose.rb index 1107408a..76cd93c4 100755 --- a/GildedRose/ruby/gilded_rose.rb +++ b/GildedRose/ruby/gilded_rose.rb @@ -1,7 +1,11 @@ class GildedRose - def update_quality(items) - items.each do |item| + def initialize(items) + @items = items + end + + def update_quality() + @items.each do |item| if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert" if item.quality > 0 if item.name != "Sulfuras, Hand of Ragnaros" @@ -46,7 +50,6 @@ class GildedRose end end end - items end end @@ -62,4 +65,4 @@ class Item def to_s() "#{@name}, #{@sell_in}, #{@quality}" end -end +end \ No newline at end of file diff --git a/GildedRose/ruby/gilded_rose_spec.rb b/GildedRose/ruby/gilded_rose_spec.rb index e6dce6f4..9d86c230 100644 --- a/GildedRose/ruby/gilded_rose_spec.rb +++ b/GildedRose/ruby/gilded_rose_spec.rb @@ -5,7 +5,7 @@ describe GildedRose do describe "#update_quality" do it "does not change the name" do items = [Item.new("foo", 0, 0)] - GildedRose.new().update_quality(items) + GildedRose.new(items).update_quality() items[0].name.should == "fixme" end end