Make localizedName a subordinate method

To reuse localizedCountryArea for sorting regardless of display.
This commit is contained in:
Davide De Rosa 2019-03-21 11:04:01 +01:00
parent 42f64db0b7
commit dacd5653b4
1 changed files with 11 additions and 7 deletions

View File

@ -74,7 +74,7 @@ public struct Pool: Codable, Comparable, CustomStringConvertible {
// MARK: Comparable // MARK: Comparable
public static func <(lhs: Pool, rhs: Pool) -> Bool { public static func <(lhs: Pool, rhs: Pool) -> Bool {
return lhs.localizedName < rhs.localizedName return lhs.localizedCountryArea < rhs.localizedCountryArea
} }
// MARK: CustomStringConvertible // MARK: CustomStringConvertible
@ -91,6 +91,14 @@ extension Pool {
return Utils.localizedCountry(country) return Utils.localizedCountry(country)
} }
public var localizedCountryArea: String {
let countryString = localizedCountry
guard let area = area else {
return countryString
}
return String.init(format: Pool.localizedFormat, countryString, area.uppercased())
}
public var localizedName: String { public var localizedName: String {
// // XXX: name from API is not localized // // XXX: name from API is not localized
@ -98,11 +106,7 @@ extension Pool {
// return name // return name
// } // }
let countryString = localizedCountry return localizedCountryArea
guard let area = area else { // return localizedCountry
return countryString
}
return String.init(format: Pool.localizedFormat, countryString, area.uppercased())
// return countryString
} }
} }