mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
- Adding Constants for Item Names
- Refactoring Code with Switch cases
This commit is contained in:
parent
3cdbf4bc87
commit
0830292975
@ -6,6 +6,38 @@ public class GildedRose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func updateQuality() {
|
public func updateQuality() {
|
||||||
|
for item in items {
|
||||||
|
switch item.name {
|
||||||
|
case ItemNameConstants.kBackstagePassesItem:
|
||||||
|
item.sellIn = item.sellIn - 1
|
||||||
|
if item.sellIn < 0 {
|
||||||
|
item.quality = 0
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item.quality = item.quality < 50 ? item.quality + 1 : 50
|
||||||
|
if item.sellIn < 10 {
|
||||||
|
item.quality = item.quality < 50 ? item.quality + 1 : 50
|
||||||
|
}
|
||||||
|
if item.sellIn < 5 {
|
||||||
|
item.quality = item.quality < 50 ? item.quality + 1 : 50
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case ItemNameConstants.kAgedBrieItem:
|
||||||
|
item.sellIn = item.sellIn - 1
|
||||||
|
item.quality = item.quality < 50 ? (item.quality + 1) : 50
|
||||||
|
case ItemNameConstants.kSulfurasItem:
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
item.sellIn = item.sellIn - 1
|
||||||
|
item.quality = item.quality > 0 ? (item.quality - 1) : 0
|
||||||
|
if(item.sellIn < 0) {
|
||||||
|
item.quality = item.quality > 0 ? (item.quality - 1) : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* public func updateQuality() {
|
||||||
for i in 0..<items.count {
|
for i in 0..<items.count {
|
||||||
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert") {
|
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert") {
|
||||||
if (items[i].quality > 0) {
|
if (items[i].quality > 0) {
|
||||||
@ -55,5 +87,5 @@ public class GildedRose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
|
|||||||
14
swift/Sources/GildedRose/GlidedRoseConstants.swift
Normal file
14
swift/Sources/GildedRose/GlidedRoseConstants.swift
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Created by Manali Mogre on 16/08/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct ItemNameConstants {
|
||||||
|
static let kAgedBrieItem: String = "Aged Brie"
|
||||||
|
static let kBackstagePassesItem: String = "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
static let kSulfurasItem: String = "Sulfuras, Hand of Ragnaros"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user