-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94cea0d
commit c4365e5
Showing
4 changed files
with
97 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 39 additions & 45 deletions
84
...tions/gilded-rose-kata/gilded-rose-typescript/3-gilded-rose-refactored/src/gilded-rose.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,91 @@ | ||
'use strict'; | ||
|
||
import internal from "stream"; | ||
|
||
export class Item { | ||
name: string = ""; | ||
sellIn: number = 0; | ||
quality: number = 0; | ||
|
||
constructor(name:string , sellIn: number, quality: number) { | ||
constructor(name: string, sellIn: number, quality: number) { | ||
this.name = name; | ||
this.sellIn = sellIn; | ||
this.quality = quality; | ||
} | ||
|
||
updateQualityAfterSellIn() { | ||
if (this.quality > 0) | ||
this.quality = this.quality - 1; | ||
public incrementQuality() { | ||
if (this.quality < 50) | ||
this.quality = this.quality + 1; | ||
} | ||
|
||
updateQualityBeforeSellIn() { | ||
public decrementQuality() { | ||
if (this.quality > 0) | ||
this.quality = this.quality - 1; | ||
} | ||
|
||
incrementQuality() { | ||
if (this.quality < 50) | ||
this.quality = this.quality + 1; | ||
} | ||
|
||
updateProduct() { | ||
this.updateQualityBeforeSellIn(); | ||
public update() { | ||
this.decrementQuality(); | ||
this.sellIn = this.sellIn - 1; | ||
this.updateQualityAfterSellIn(); | ||
this.decrementQuality(); | ||
} | ||
|
||
toString() { | ||
public toString(): string { | ||
return "name: " + this.name + ", sellIn: " + this.sellIn + ", quality: " + this.quality | ||
} | ||
} | ||
|
||
export class BackstagePass extends Item { | ||
export class AgedBrie extends Item { | ||
constructor(sellIn: number, quality: number) { | ||
super('Backstage passes to a TAFKAL80ETC concert', sellIn, quality); | ||
super("Aged Brie", sellIn, quality); | ||
} | ||
|
||
updateQualityBeforeSellIn() { | ||
if (this.quality < 50) { | ||
this.quality = this.quality + 1; | ||
if (this.sellIn < 11) | ||
super.incrementQuality(); | ||
if (this.sellIn < 6) | ||
super.incrementQuality(); | ||
} | ||
} | ||
|
||
updateQualityAfterSellIn() { | ||
if (this.sellIn < 0) | ||
this.quality = 0; | ||
public update() { | ||
this.incrementQuality(); | ||
this.sellIn = this.sellIn - 1; | ||
this.incrementQuality(); | ||
} | ||
} | ||
|
||
export class AgedBrie extends Item { | ||
export class Sulfuras extends Item { | ||
constructor(sellIn: number, quality: number) { | ||
super('Aged Brie', sellIn, quality); | ||
super("Sulfuras, Hand of Ragnaros", sellIn, quality); | ||
} | ||
|
||
updateQualityBeforeSellIn() { | ||
super.incrementQuality(); | ||
} | ||
|
||
updateQualityAfterSellIn() { | ||
super.incrementQuality(); | ||
public update() { | ||
} | ||
} | ||
|
||
export class Sulfuras extends Item { | ||
export class BackstagePass extends Item { | ||
constructor(sellIn: number, quality: number) { | ||
super('Sulfuras, Hand of Ragnaros', sellIn, quality); | ||
super("Backstage passes to a TAFKAL80ETC concert", sellIn, quality); | ||
} | ||
|
||
updateProduct() { | ||
public update() { | ||
if (this.quality < 50) | ||
this.quality = this.quality + 1; | ||
if (this.sellIn < 11) | ||
if (this.quality < 50) | ||
this.quality = this.quality + 1; | ||
if (this.sellIn < 6) | ||
if (this.quality < 50) | ||
this.quality = this.quality + 1; | ||
|
||
this.sellIn = this.sellIn - 1; | ||
|
||
if (this.sellIn < 0) | ||
this.quality = 0; | ||
} | ||
} | ||
|
||
export class Shop { | ||
export class GildedRose { | ||
items: Array<Item>; | ||
|
||
constructor(items = [] as Array<Item>) { | ||
this.items = items; | ||
} | ||
|
||
updateQuality() { | ||
for (var i = 0; i < this.items.length; i++) | ||
this.items[i].updateProduct(); | ||
|
||
public updateQuality(): Array<Item> { | ||
this.items.forEach(item => item.update()); | ||
return this.items; | ||
} | ||
} |