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: ",")