Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
View
69 lib/snail.rb
@@ -39,11 +39,33 @@ class UnknownCountryError < ArgumentError; end
end
def self.home_country
- @home_country ||= "USA"
+ @home_country ||= "US"
end
def self.home_country=(val)
- @home_country = val
+ @home_country = lookup_country_iso(val)
+ end
+
+ def self.lookup_country_iso(val)
+ return nil if val.blank?
+ val = val.upcase
+ if iso = ::Snail::Iso3166::ALPHA2[val]
+ iso
+ elsif iso = ::Snail::Iso3166::ALPHA2_EXCEPTIONS[val]
+ iso
+ elsif iso = ::Snail::Iso3166::ALPHA3_TO_ALPHA2[val]
+ iso
+ elsif iso_pair = ::Snail::Iso3166::ALPHA2.find { |a2, names| names.include?(val) }
+ ActiveSupport::Deprecation.warn("Country name lookup will be deprecated in the near future. Please pass ISO3166 country codes to Snail instead.")
+ iso_pair.first
+ else
+ nil
+ end
+ end
+
+ # Store country as ISO-3166 Alpha 2
+ def country=(val)
+ @country = Snail.lookup_country_iso(val)
end
def to_s
@@ -58,45 +80,45 @@ def to_html
# currently it's based on the sampling of city line formats from frank's compulsive guide.
def city_line
case country
- when 'China', 'India'
+ when 'CN', 'IN'
"#{city}, #{region} #{postal_code}"
- when 'Brazil'
+ when 'BR'
"#{postal_code} #{city}-#{region}"
- when 'Mexico', 'Slovakia'
+ when 'MX', 'SK'
"#{postal_code} #{city}, #{region}"
- when 'Italy'
+ when 'IT'
"#{postal_code} #{city} (#{region})"
- when 'Belarus'
+ when 'BY'
"#{postal_code} #{city}-(#{region})"
- when 'USA', 'Canada', 'Australia', nil, ""
+ when 'US', 'CA', 'AU', nil, ""
"#{city} #{region} #{postal_code}"
- when 'Israel', 'Denmark', 'Finland', 'France', 'Germany', 'Greece', 'Italy', 'Norway', 'Spain', 'Sweden', 'Turkey', 'Cyprus', 'Portugal', 'Macedonia', 'Bosnia and Herzegovina'
+ when 'IL', 'DK', 'FI', 'FR', 'DE', 'GR', 'IT', 'NO', 'ES', 'SE', 'TR', 'CY', 'PT', 'MK', 'BA'
"#{postal_code} #{city}"
- when 'Kuwait', 'Syria', 'Oman', 'Estonia','Luxembourg', 'Belgium', 'Iceland', 'Switzerland', 'Austria', 'Moldova', 'Montenegro', 'Serbia', 'Bulgaria', 'Georgia', 'Poland', 'Armenia', 'Croatia', 'Romania', 'Azerbaijan'
+ when 'KW', 'SY', 'OM', 'EE', 'LU', 'BE', 'IS', 'CH', 'AT', 'MD', 'ME', 'RS', 'BG', 'GE', 'PL', 'AM', 'HR', 'RO', 'AZ'
"#{postal_code} #{city}"
- when 'Netherlands'
+ when 'NL'
"#{postal_code} #{city}"
- when 'Ireland'
+ when 'IE'
"#{city}, #{region}"
- when 'England', 'Scotland', 'Wales', 'United Kingdom', 'Russia', 'Russian Federation', 'Ukraine', 'Jordan', 'Lebanon','Iran, Islamic Republic of', 'Iran', 'Saudi Arabia', 'New Zealand'
+ when 'GB', 'RU', 'UA', 'JO', 'LB', 'IR', 'SA', 'NZ'
"#{city} #{postal_code}" # Locally these may be on separate lines. The USPS prefers the city line above the country line, though.
- when 'Ecuador'
+ when 'EC'
"#{postal_code} #{city}"
- when 'Hong Kong', 'Syria', 'Iraq', 'Yemen', 'Qatar', 'Albania'
+ when 'HK', 'IQ', 'YE', 'QA', 'AL'
"#{city}"
- when 'United Arab Emirates'
+ when 'AE'
"#{postal_code}\n#{city}"
- when 'Japan'
+ when 'JP'
"#{city}, #{region}\n#{postal_code}"
- when 'Egypt', 'South Africa','Isle of Man', 'Kazakhstan', 'Hungary'
+ when 'EG', 'ZA', 'IM', 'KZ', 'HU'
"#{city}\n#{postal_code}"
- when 'Latvia'
+ when 'LV'
"#{city}, LV-#{postal_code}"
- when 'Lithuania'
+ when 'LT'
"LT-#{postal_code} #{city}"
- when 'Slovenia'
+ when 'SI'
"SI-#{postal_code} #{city}"
- when 'Czech Republic'
+ when 'CZ'
"#{postal_code} #{region}\n#{city}"
else
if Kernel.const_defined?("Rails")
@@ -106,7 +128,8 @@ def city_line
end
end
+ # TODO after country name lookup deprecation, add localized country names to this
def country_line
- self.class.home_country.to_s.upcase == country.to_s.upcase ? nil : country.to_s.upcase
+ self.class.home_country == country ? nil : ::Snail::Iso3166::ALPHA2[country]
end
end
View
509 lib/snail/constants.rb
@@ -345,5 +345,514 @@ class Snail
CA_PROVINCES = REGIONS[:ca]
AU_REGIONS = REGIONS[:au]
+ module Iso3166
+ # as of June 3rd, 2010
+ # pulled http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
+ ALPHA2 = {
+ 'AD' => ["ANDORRA"],
+ 'AE' => ["UNITED ARAB EMIRATES"],
+ 'AF' => ["AFGHANISTAN"],
+ 'AG' => ["ANTIGUA AND BARBUDA"],
+ 'AI' => ["ANGUILLA"],
+ 'AL' => ["ALBANIA"],
+ 'AM' => ["ARMENIA"],
+ 'AN' => ["NETHERLANDS ANTILLES"],
+ 'AO' => ["ANGOLA"],
+ 'AQ' => ["ANTARCTICA"],
+ 'AR' => ["ARGENTINA"],
+ 'AS' => ["AMERICAN SAMOA"],
+ 'AT' => ["AUSTRIA"],
+ 'AU' => ["AUSTRALIA"],
+ 'AW' => ["ARUBA"],
+ 'AX' => ["ALAND ISLANDS"],
+ 'AZ' => ["AZERBAIJAN"],
+ 'BA' => ["BOSNIA AND HERZEGOVINA"],
+ 'BB' => ["BARBADOS"],
+ 'BD' => ["BANGLADESH"],
+ 'BE' => ["BELGIUM"],
+ 'BF' => ["BURKINA FASO"],
+ 'BG' => ["BULGARIA"],
+ 'BH' => ["BAHRAIN"],
+ 'BI' => ["BURUNDI"],
+ 'BJ' => ["BENIN"],
+ 'BL' => ["SAINT BARTHELEMY"],
+ 'BM' => ["BERMUDA"],
+ 'BN' => ["BRUNEI DARUSSALAM"],
+ 'BO' => ["BOLIVIA"],
+ 'BR' => ["BRAZIL"],
+ 'BS' => ["BAHAMAS"],
+ 'BT' => ["BHUTAN"],
+ 'BV' => ["BOUVET ISLAND"],
+ 'BW' => ["BOTSWANA"],
+ 'BY' => ["BELARUS"],
+ 'BZ' => ["BELIZE"],
+ 'CA' => ["CANADA"],
+ 'CC' => ["COCOS (KEELING) ISLANDS"],
+ 'CD' => ["DEMOCRATIC REPUBLIC OF THE CONGO"],
+ 'CF' => ["CENTRAL AFRICAN REPUBLIC"],
+ 'CG' => ["CONGO", "REPUBLIC OF THE CONGO"],
+ 'CH' => ["SWITZERLAND"],
+ 'CI' => ["COTE D'IVOIRE"],
+ 'CK' => ["COOK ISLANDS"],
+ 'CL' => ["CHILE"],
+ 'CM' => ["CAMEROON"],
+ 'CN' => ["CHINA", "PEOPLE'S REPUBLIC OF CHINA"],
+ 'CO' => ["COLOMBIA"],
+ 'CR' => ["COSTA RICA"],
+ 'CU' => ["CUBA"],
+ 'CV' => ["CAPE VERDE"],
+ 'CX' => ["CHRISTMAS ISLAND"],
+ 'CY' => ["CYPRUS"],
+ 'CZ' => ["CZECH REPUBLIC"],
+ 'DE' => ["GERMANY"],
+ 'DJ' => ["DJIBOUTI"],
+ 'DK' => ["DENMARK"],
+ 'DM' => ["DOMINICA"],
+ 'DO' => ["DOMINICAN REPUBLIC"],
+ 'DZ' => ["ALGERIA"],
+ 'EC' => ["ECUADOR"],
+ 'EE' => ["ESTONIA"],
+ 'EG' => ["EGYPT"],
+ 'EH' => ["WESTERN SAHARA"],
+ 'ER' => ["ERITREA"],
+ 'ES' => ["SPAIN"],
+ 'ET' => ["ETHIOPIA"],
+ 'FI' => ["FINLAND"],
+ 'FJ' => ["FIJI"],
+ 'FK' => ["FALKLAND ISLANDS"],
+ 'FM' => ["MICRONESIA"],
+ 'FO' => ["FAROE ISLANDS"],
+ 'FR' => ["FRANCE"],
+ 'GA' => ["GABON"],
+ 'GB' => ["UNITED KINGDOM", "ENGLAND", "NORTHERN IRELAND", "SCOTLAND", "WALES"],
+ 'GD' => ["GRENADA"],
+ 'GE' => ["GEORGIA"],
+ 'GF' => ["FRENCH GUIANA"],
+ 'GG' => ["GUERNSEY"],
+ 'GH' => ["GHANA"],
+ 'GI' => ["GIBRALTAR"],
+ 'GL' => ["GREENLAND"],
+ 'GM' => ["GAMBIA"],
+ 'GN' => ["GUINEA"],
+ 'GP' => ["GUADELOUPE"],
+ 'GQ' => ["EQUATORIAL GUINEA"],
+ 'GR' => ["GREECE"],
+ 'GS' => ["SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS"],
+ 'GT' => ["GUATEMALA"],
+ 'GU' => ["GUAM"],
+ 'GW' => ["GUINEA-BISSAU"],
+ 'GY' => ["GUYANA"],
+ 'HK' => ["HONG KONG"],
+ 'HM' => ["HEARD ISLAND AND MCDONALD ISLANDS"],
+ 'HN' => ["HONDURAS"],
+ 'HR' => ["CROATIA"],
+ 'HT' => ["HAITI"],
+ 'HU' => ["HUNGARY"],
+ 'ID' => ["INDONESIA"],
+ 'IE' => ["IRELAND"],
+ 'IL' => ["ISRAEL"],
+ 'IM' => ["ISLE OF MAN"],
+ 'IN' => ["INDIA"],
+ 'IO' => ["BRITISH INDIAN OCEAN TERRITORY"],
+ 'IQ' => ["IRAQ"],
+ 'IR' => ["IRAN", "ISLAMIC REPUBLIC OF IRAN"],
+ 'IS' => ["ICELAND"],
+ 'IT' => ["ITALY"],
+ 'JE' => ["JERSEY"],
+ 'JM' => ["JAMAICA"],
+ 'JO' => ["JORDAN"],
+ 'JP' => ["JAPAN"],
+ 'KE' => ["KENYA"],
+ 'KG' => ["KYRGYZSTAN"],
+ 'KH' => ["CAMBODIA"],
+ 'KI' => ["KIRIBATI"],
+ 'KM' => ["COMOROS"],
+ 'KN' => ["SAINT KITTS AND NEVIS"],
+ 'KP' => ["NORTH KOREA", "DEMOCRATIC PEOPLE'S REPUBLIC OF KOREA"],
+ 'KR' => ["SOUTH KOREA", "KOREA", "REPUBLIC OF KOREA"],
+ 'KW' => ["KUWAIT"],
+ 'KY' => ["CAYMAN ISLANDS"],
+ 'KZ' => ["KAZAKHSTAN"],
+ 'LA' => ["LAOS"],
+ 'LB' => ["LEBANON"],
+ 'LC' => ["SAINT LUCIA"],
+ 'LI' => ["LIECHTENSTEIN"],
+ 'LK' => ["SRI LANKA"],
+ 'LR' => ["LIBERIA"],
+ 'LS' => ["LESOTHO"],
+ 'LT' => ["LITHUANIA"],
+ 'LU' => ["LUXEMBOURG"],
+ 'LV' => ["LATVIA"],
+ 'LY' => ["LIBYAN ARAB JAMAHIRIYA"],
+ 'MA' => ["MOROCCO"],
+ 'MC' => ["MONACO"],
+ 'MD' => ["MOLDOVA"],
+ 'ME' => ["MONTENEGRO"],
+ 'MF' => ["SAINT MARTIN"],
+ 'MG' => ["MADAGASCAR"],
+ 'MH' => ["MARSHALL ISLANDS"],
+ 'MK' => ["MACEDONIA"],
+ 'ML' => ["MALI"],
+ 'MM' => ["MYANMAR"],
+ 'MN' => ["MONGOLIA"],
+ 'MO' => ["MACAO"],
+ 'MP' => ["NORTHERN MARIANA ISLANDS"],
+ 'MQ' => ["MARTINIQUE"],
+ 'MR' => ["MAURITANIA"],
+ 'MS' => ["MONTSERRAT"],
+ 'MT' => ["MALTA"],
+ 'MU' => ["MAURITIUS"],
+ 'MV' => ["MALDIVES"],
+ 'MW' => ["MALAWI"],
+ 'MX' => ["MEXICO"],
+ 'MY' => ["MALAYSIA"],
+ 'MZ' => ["MOZAMBIQUE"],
+ 'NA' => ["NAMIBIA"],
+ 'NC' => ["NEW CALEDONIA"],
+ 'NE' => ["NIGER"],
+ 'NF' => ["NORFOLK ISLAND"],
+ 'NG' => ["NIGERIA"],
+ 'NI' => ["NICARAGUA"],
+ 'NL' => ["NETHERLANDS"],
+ 'NO' => ["NORWAY"],
+ 'NP' => ["NEPAL"],
+ 'NR' => ["NAURU"],
+ 'NU' => ["NIUE"],
+ 'NZ' => ["NEW ZEALAND"],
+ 'OM' => ["OMAN"],
+ 'PA' => ["PANAMA"],
+ 'PE' => ["PERU"],
+ 'PF' => ["FRENCH POLYNESIA"],
+ 'PG' => ["PAPUA NEW GUINEA"],
+ 'PH' => ["PHILIPPINES"],
+ 'PK' => ["PAKISTAN"],
+ 'PL' => ["POLAND"],
+ 'PM' => ["SAINT PIERRE AND MIQUELON"],
+ 'PN' => ["PITCAIRN"],
+ 'PR' => ["PUERTO RICO"],
+ 'PS' => ["PALESTINIAN TERRITORIES"],
+ 'PT' => ["PORTUGAL"],
+ 'PW' => ["PALAU"],
+ 'PY' => ["PARAGUAY"],
+ 'QA' => ["QATAR"],
+ 'RE' => ["REUNION"],
+ 'RO' => ["ROMANIA"],
+ 'RS' => ["SERBIA"],
+ 'RU' => ["RUSSIAN FEDERATION", "RUSSIA"],
+ 'RW' => ["RWANDA"],
+ 'SA' => ["SAUDI ARABIA"],
+ 'SB' => ["SOLOMON ISLANDS"],
+ 'SC' => ["SEYCHELLES"],
+ 'SD' => ["SUDAN"],
+ 'SE' => ["SWEDEN"],
+ 'SG' => ["SINGAPORE"],
+ 'SH' => ["SAINT HELENA"],
+ 'SI' => ["SLOVENIA"],
+ 'SJ' => ["SVALBARD AND JAN MAYEN"],
+ 'SK' => ["SLOVAKIA"],
+ 'SL' => ["SIERRA LEONE"],
+ 'SM' => ["SAN MARINO"],
+ 'SN' => ["SENEGAL"],
+ 'SO' => ["SOMALIA"],
+ 'SR' => ["SURINAME"],
+ 'SS' => ["SOUTH SUDAN"],
+ 'ST' => ["SAO TOME AND PRINCIPE"],
+ 'SV' => ["EL SALVADOR"],
+ 'SY' => ["SYRIAN ARAB REPUBLIC", "SYRIA"],
+ 'SZ' => ["SWAZILAND"],
+ 'TC' => ["TURKS AND CAICOS ISLANDS"],
+ 'TD' => ["CHAD"],
+ 'TF' => ["FRENCH SOUTHERN TERRITORIES"],
+ 'TG' => ["TOGO"],
+ 'TH' => ["THAILAND"],
+ 'TJ' => ["TAJIKISTAN"],
+ 'TK' => ["TOKELAU"],
+ 'TL' => ["TIMOR-LESTE"],
+ 'TM' => ["TURKMENISTAN"],
+ 'TN' => ["TUNISIA"],
+ 'TO' => ["TONGA"],
+ 'TR' => ["TURKEY"],
+ 'TT' => ["TRINIDAD AND TOBAGO"],
+ 'TV' => ["TUVALU"],
+ 'TW' => ["TAIWAN"],
+ 'TZ' => ["TANZANIA"],
+ 'UA' => ["UKRAINE"],
+ 'UG' => ["UGANDA"],
+ 'UM' => ["UNITED STATES MINOR OUTLYING ISLANDS"],
+ 'US' => ["UNITED STATES", "UNITED STATES OF AMERICA"],
+ 'UY' => ["URUGUAY"],
+ 'UZ' => ["UZBEKISTAN"],
+ 'VA' => ["VATICAN CITY"],
+ 'VC' => ["SAINT VINCENT AND THE GRENADINES"],
+ 'VE' => ["VENEZUELA"],
+ 'VG' => ["VIRGIN ISLANDS, BRITISH"],
+ 'VI' => ["VIRGIN ISLANDS, U.S."],
+ 'VN' => ["VIET NAM"],
+ 'VU' => ["VANUATU"],
+ 'WF' => ["WALLIS AND FUTUNA"],
+ 'WS' => ["SAMOA"],
+ 'YE' => ["YEMEN"],
+ 'YT' => ["MAYOTTE"],
+ 'ZA' => ["SOUTH AFRICA"],
+ 'ZM' => ["ZAMBIA"],
+ 'ZW' => ["ZIMBABWE"]
+ }
+
+ ALPHA2_EXCEPTIONS = {
+ 'UK' => 'GB', # great britain aka united kingdom
+ 'FX' => 'FR', # france
+ 'SU' => 'RU' # russia
+ }
+
+ ALPHA3_TO_ALPHA2 = {
+ "ABW" => "AW",
+ "AFG" => "AF",
+ "AGO" => "AO",
+ "AIA" => "AI",
+ "ALA" => "AX",
+ "ALB" => "AL",
+ "AND" => "AD",
+ "ANT" => "AN",
+ "ARE" => "AE",
+ "ARG" => "AR",
+ "ARM" => "AM",
+ "ASM" => "AS",
+ "ATA" => "AQ",
+ "ATF" => "TF",
+ "ATG" => "AG",
+ "AUS" => "AU",
+ "AUT" => "AT",
+ "AZE" => "AZ",
+ "BDI" => "BI",
+ "BEL" => "BE",
+ "BEN" => "BJ",
+ "BFA" => "BF",
+ "BGD" => "BD",
+ "BGR" => "BG",
+ "BHR" => "BH",
+ "BHS" => "BS",
+ "BIH" => "BA",
+ "BLM" => "BL",
+ "BLR" => "BY",
+ "BLZ" => "BZ",
+ "BMU" => "BM",
+ "BOL" => "BO",
+ "BRA" => "BR",
+ "BRB" => "BB",
+ "BRN" => "BN",
+ "BTN" => "BT",
+ "BVT" => "BV",
+ "BWA" => "BW",
+ "CAF" => "CF",
+ "CAN" => "CA",
+ "CCK" => "CC",
+ "CHE" => "CH",
+ "CHL" => "CL",
+ "CHN" => "CN",
+ "CIV" => "CI",
+ "CMR" => "CM",
+ "COD" => "CD",
+ "COG" => "CG",
+ "COK" => "CK",
+ "COL" => "CO",
+ "COM" => "KM",
+ "CPV" => "CV",
+ "CRI" => "CR",
+ "CUB" => "CU",
+ "CXR" => "CX",
+ "CYM" => "KY",
+ "CYP" => "CY",
+ "CZE" => "CZ",
+ "DEU" => "DE",
+ "DJI" => "DJ",
+ "DMA" => "DM",
+ "DNK" => "DK",
+ "DOM" => "DO",
+ "DZA" => "DZ",
+ "ECU" => "EC",
+ "EGY" => "EG",
+ "ERI" => "ER",
+ "ESH" => "EH",
+ "ESP" => "ES",
+ "EST" => "EE",
+ "ETH" => "ET",
+ "FIN" => "FI",
+ "FJI" => "FJ",
+ "FLK" => "FK",
+ "FRA" => "FR",
+ "FRO" => "FO",
+ "FSM" => "FM",
+ "GAB" => "GA",
+ "GBR" => "GB",
+ "GEO" => "GE",
+ "GGY" => "GG",
+ "GHA" => "GH",
+ "GIB" => "GI",
+ "GIN" => "GN",
+ "GLP" => "GP",
+ "GMB" => "GM",
+ "GNB" => "GW",
+ "GNQ" => "GQ",
+ "GRC" => "GR",
+ "GRD" => "GD",
+ "GRL" => "GL",
+ "GTM" => "GT",
+ "GUF" => "GF",
+ "GUM" => "GU",
+ "GUY" => "GY",
+ "HKG" => "HK",
+ "HMD" => "HM",
+ "HND" => "HN",
+ "HRV" => "HR",
+ "HTI" => "HT",
+ "HUN" => "HU",
+ "IDN" => "ID",
+ "IMN" => "IM",
+ "IND" => "IN",
+ "IOT" => "IO",
+ "IRL" => "IE",
+ "IRN" => "IR",
+ "IRQ" => "IQ",
+ "ISL" => "IS",
+ "ISR" => "IL",
+ "ITA" => "IT",
+ "JAM" => "JM",
+ "JEY" => "JE",
+ "JOR" => "JO",
+ "JPN" => "JP",
+ "KAZ" => "KZ",
+ "KEN" => "KE",
+ "KGZ" => "KG",
+ "KHM" => "KH",
+ "KIR" => "KI",
+ "KNA" => "KN",
+ "KOR" => "KR",
+ "KWT" => "KW",
+ "LAO" => "LA",
+ "LBN" => "LB",
+ "LBR" => "LR",
+ "LBY" => "LY",
+ "LCA" => "LC",
+ "LIE" => "LI",
+ "LKA" => "LK",
+ "LSO" => "LS",
+ "LTU" => "LT",
+ "LUX" => "LU",
+ "LVA" => "LV",
+ "MAC" => "MO",
+ "MAF" => "MF",
+ "MAR" => "MA",
+ "MCO" => "MC",
+ "MDA" => "MD",
+ "MDG" => "MG",
+ "MDV" => "MV",
+ "MEX" => "MX",
+ "MHL" => "MH",
+ "MKD" => "MK",
+ "MLI" => "ML",
+ "MLT" => "MT",
+ "MMR" => "MM",
+ "MNE" => "ME",
+ "MNG" => "MN",
+ "MNP" => "MP",
+ "MOZ" => "MZ",
+ "MRT" => "MR",
+ "MSR" => "MS",
+ "MTQ" => "MQ",
+ "MUS" => "MU",
+ "MWI" => "MW",
+ "MYS" => "MY",
+ "MYT" => "YT",
+ "NAM" => "NA",
+ "NCL" => "NC",
+ "NER" => "NE",
+ "NFK" => "NF",
+ "NGA" => "NG",
+ "NIC" => "NI",
+ "NIU" => "NU",
+ "NLD" => "NL",
+ "NOR" => "NO",
+ "NPL" => "NP",
+ "NRU" => "NR",
+ "NZL" => "NZ",
+ "OMN" => "OM",
+ "PAK" => "PK",
+ "PAN" => "PA",
+ "PCN" => "PN",
+ "PER" => "PE",
+ "PHL" => "PH",
+ "PLW" => "PW",
+ "PNG" => "PG",
+ "POL" => "PL",
+ "PRI" => "PR",
+ "PRK" => "KP",
+ "PRT" => "PT",
+ "PRY" => "PY",
+ "PSE" => "PS",
+ "PYF" => "PF",
+ "QAT" => "QA",
+ "REU" => "RE",
+ "ROU" => "RO",
+ "RUS" => "RU",
+ "RWA" => "RW",
+ "SAU" => "SA",
+ "SDN" => "SD",
+ "SEN" => "SN",
+ "SGP" => "SG",
+ "SGS" => "GS",
+ "SHN" => "SH",
+ "SJM" => "SJ",
+ "SLB" => "SB",
+ "SLE" => "SL",
+ "SLV" => "SV",
+ "SMR" => "SM",
+ "SOM" => "SO",
+ "SPM" => "PM",
+ "SRB" => "RS",
+ "SSD" => "SS",
+ "STP" => "ST",
+ "SUR" => "SR",
+ "SVK" => "SK",
+ "SVN" => "SI",
+ "SWE" => "SE",
+ "SWZ" => "SZ",
+ "SYC" => "SC",
+ "SYR" => "SY",
+ "TCA" => "TC",
+ "TCD" => "TD",
+ "TGO" => "TG",
+ "THA" => "TH",
+ "TJK" => "TJ",
+ "TKL" => "TK",
+ "TKM" => "TM",
+ "TLS" => "TL",
+ "TON" => "TO",
+ "TTO" => "TT",
+ "TUN" => "TN",
+ "TUR" => "TR",
+ "TUV" => "TV",
+ "TWN" => "TW",
+ "TZA" => "TZ",
+ "UGA" => "UG",
+ "UKR" => "UA",
+ "UMI" => "UM",
+ "URY" => "UY",
+ "USA" => "US",
+ "UZB" => "UZ",
+ "VAT" => "VA",
+ "VCT" => "VC",
+ "VEN" => "VE",
+ "VGB" => "VG",
+ "VIR" => "VI",
+ "VNM" => "VN",
+ "VUT" => "VU",
+ "WLF" => "WF",
+ "WSM" => "WS",
+ "YEM" => "YE",
+ "ZAF" => "ZA",
+ "ZMB" => "ZM",
+ "ZWE" => "ZW"
+ }
+ end
end
View
2  snail.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "snail"
- s.version = "0.5.7"
+ s.version = "0.5.9"
s.summary = "Easily format snail mail addresses for international delivery"
s.description = "International snail mail addressing is a pain. This begins to make it easier."
s.author = "Lance Ivy"
View
20 test/snail_test.rb
@@ -81,6 +81,26 @@ def setup
assert s.to_s[-5,5] == "12345"
end
+ test "store country from country name in alpha2" do
+ s = Snail.new(@ca.merge(:country => 'Slovenia'))
+ assert_equal "SI", s.country
+ end
+
+ test "store country from uppercase country name in alpha2" do
+ s = Snail.new(@ca.merge(:country => 'JAPAN'))
+ assert_equal "JP", s.country
+ end
+
+ test "store country from country alpha3 in alpha2" do
+ s = Snail.new(@ca.merge(:country => 'SVN'))
+ assert_equal "SI", s.country
+ end
+
+ test "store country from country alpha2 exception in alpha2" do
+ s = Snail.new(@ca.merge(:country => 'UK'))
+ assert_equal "GB", s.country
+ end
+
test "country names are uppercased" do
s = Snail.new(@ca)
assert s.to_s.match(/CANADA/)

No commit comments for this range

Something went wrong with that request. Please try again.