mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
37 lines
778 B
Swift
37 lines
778 B
Swift
//
|
|
// SellInModificationRule.swift
|
|
//
|
|
//
|
|
// Created by Lucas van Dongen on 23/11/2020.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum SellInModificationRule: Rule {
|
|
typealias RuleType = Self
|
|
|
|
case regular, legendary
|
|
|
|
static func rule(for item: Item) -> RuleType {
|
|
switch item.name {
|
|
case "Sulfuras, Hand of Ragnaros":
|
|
return .legendary
|
|
default:
|
|
return .regular
|
|
}
|
|
}
|
|
|
|
func apply(to item: Item) -> Item {
|
|
switch self {
|
|
case .regular:
|
|
return applyRegularRule(to: item)
|
|
case .legendary:
|
|
return item // Unmodified
|
|
}
|
|
}
|
|
|
|
func applyRegularRule(to item: Item) -> Item {
|
|
return Item(name: item.name, sellIn: item.sellIn - 1, quality: item.quality)
|
|
}
|
|
}
|