This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apple doesn't guarantee that the ISO code will be present and recommended to match country names against common spellings instead. This will use the country code if it's provided, but otherwise attempt to map the country name to the corresponding ISO code.
- Loading branch information
Luuk Veenis
committed
Nov 18, 2016
1 parent
f37a5c7
commit 070b4fd
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module SolidusPaypalBraintree | ||
module CountryMapper | ||
extend ActiveSupport::Concern | ||
|
||
USA_VARIANTS = [ | ||
"the united states of america", | ||
"united states of america", | ||
"the united states", | ||
"united states", | ||
"us of a", | ||
"u.s.a.", | ||
"usa", | ||
"u.s.", | ||
"us", | ||
] | ||
|
||
CANADA_VARIANTS = [ | ||
"canada", | ||
"ca", | ||
] | ||
|
||
# Generates a hash mapping each variant of the country name to the same ISO | ||
# ie: { "usa" => "US", "united states" => "US", "canada" => "CA", ... } | ||
COUNTRY_MAP = { | ||
USA_VARIANTS => "US", | ||
CANADA_VARIANTS => "CA" | ||
}.flat_map { |variants, iso| variants.map { |v| [v, iso] } }.to_h | ||
|
||
included do | ||
def iso_from_name country_name | ||
COUNTRY_MAP[country_name.downcase.strip] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters