Skip to content

Commit

Permalink
getCurrencies was added to SovereignRegion
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomHashTags committed Oct 20, 2022
1 parent 6db1054 commit f21a0db
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/SwiftSovereignStates/Country.swift
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public enum Country : String, CaseIterable, SovereignState {
return SovereignStateTimeZone.get(self)
}
/// The official currencies used within this country.
public func getCurrencies() -> [Currency]? {
public func getCurrencies() -> [Currency] {
return SovereignStateCurrencies.get(self)
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftSovereignStates/SovereignRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public protocol SovereignRegion : Codable, Hashable, LosslessStringConvertible {
func getWikipediaURLPrefix() -> String?
func getWikipediaURLSuffix() -> String?

/// The official currencies used within this SovereignRegion.
func getCurrencies() -> [Currency]
/// All the time zones this SovereignRegion recognizes within its administrative borders.
func getTimeZones() -> [SovereignStateTimeZone]?
/// All temperate zones this SovereignRegion contains within its administrative borders.
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSovereignStates/SovereignState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import Foundation

public protocol SovereignState : SovereignRegion {
/// The ISO 3166-1 alpha-2 code for this SovereignRegion. Country codes are defined at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 . Subdivision codes are defined at https://en.wikipedia.org/wiki/ISO_3166-2.
/// The ISO 3166-1 alpha-2 code for this SovereignState. Country codes are defined at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 . Subdivision codes are defined at https://en.wikipedia.org/wiki/ISO_3166-2 .
func getISOAlpha2() -> String?
/// The ISO 3166-1 alpha-3 code for this SovereignRegion. Country codes are defined at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 .
/// The ISO 3166-1 alpha-3 code for this SovereignState. Country codes are defined at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 .
func getISOAlpha3() -> String?
}
public extension SovereignState {
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftSovereignStates/SovereignStateCity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public extension SovereignStateCity {
func getCacheID() -> String {
return getSubdivision().getCacheID() + "_" + getIdentifier()
}
func getCurrencies() -> [Currency] {
return getSubdivision().getCurrencies()
}

func getDefaultType() -> SovereignStateCityType {
return SovereignStateCityType.city
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftSovereignStates/SovereignStateSubdivision.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public extension SovereignStateSubdivision {
func getISOAlpha3() -> String? {
return nil
}
func getCurrencies() -> [Currency] {
return getCountry().getCurrencies()
}

func getWikipediaURLSuffix() -> String? {
return "_" + getTypeSuffix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

internal enum SovereignStateCurrencies {
static func get(_ country: Country) -> [Currency]? {
static func get(_ country: Country) -> [Currency] {
switch country {
case .abkhazia: return [Currency.RUB]
case .afghanistan: return [Currency.AFN]
Expand Down Expand Up @@ -256,12 +256,21 @@ internal enum SovereignStateCurrencies {
case .zambia: return [Currency.ZMW]
case .zimbabwe: return [Currency.ZWL]


case .vatican_city: return [Currency.EUR]

case .wallis_and_futuna: return [Currency.XPF]
case .western_sahara: return [Currency.MAD]
default: return nil

case .curacao: return [Currency.ANG]
case .equatorial_guinea: return [Currency.XAF]
case .french_polynesia: return [Currency.XPF]
case .isle_of_man: return [Currency.GBP]
case .kosovo: return [Currency.EUR]
case .new_caledonia: return [Currency.XPF]
case .northern_cyprus: return [Currency.TRY]
case .scotland: return [Currency.GBP]
case .somaliland: return [Currency.SLS]
case .united_states_virgin_islands: return [Currency.USN, Currency.USD]
}
}
}

0 comments on commit f21a0db

Please sign in to comment.