From 94a717befa48b81fe87f38791730c868d544ead5 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 25 Apr 2019 23:55:00 +0200 Subject: [PATCH] Fix Pool.localizedId --- Passepartout/Sources/Services/Pool.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Passepartout/Sources/Services/Pool.swift b/Passepartout/Sources/Services/Pool.swift index 61e51601..5ddc4c8d 100644 --- a/Passepartout/Sources/Services/Pool.swift +++ b/Passepartout/Sources/Services/Pool.swift @@ -92,17 +92,23 @@ public struct Pool: Codable, Hashable { } extension Pool { - private static let localizedFormat = "%@ - %@" - public var localizedCountry: String { return Utils.localizedCountry(country) } public var localizedId: String { - return String.init(format: Pool.localizedFormat, localizedCountry, secondaryId) + var comps: [String] = [localizedCountry] + if let secondaryId = optionalSecondaryId { + comps.append(secondaryId) + } + return comps.joined(separator: " - ") } public var secondaryId: String { + return optionalSecondaryId ?? "" + } + + private var optionalSecondaryId: String? { var comps: [String] = [] if let extraCountries = extraCountries { comps.append(contentsOf: extraCountries.map { Utils.localizedCountry($0) }) @@ -113,6 +119,9 @@ extension Pool { if let num = num { comps.append("#\(num)") } + guard !comps.isEmpty else { + return nil + } var str = comps.joined(separator: " ") if let tags = tags { let suffix = tags.map { $0.uppercased() }.joined(separator: ",")