2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
module Format; module Geography
|
|
|
|
|
|
|
|
StateCodes = [ 'AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'PR', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY' ]
|
|
|
|
|
|
|
|
StateMappings = {
|
|
|
|
'alabama' => 'AL',
|
|
|
|
'alaska' => 'AK',
|
|
|
|
'arizona' => 'AZ',
|
|
|
|
'arkansas' => 'AR',
|
|
|
|
'california' => 'CA',
|
|
|
|
'colorado' => 'CO',
|
|
|
|
'connecticut' => 'CT',
|
|
|
|
'delaware' => 'DE',
|
|
|
|
'district of columbia' => 'DC',
|
|
|
|
'florida' => 'FL',
|
|
|
|
'georgia' => 'GA',
|
|
|
|
'hawaii' => 'HI',
|
|
|
|
'idaho' => 'ID',
|
|
|
|
'illinois' => 'IL',
|
|
|
|
'indiana' => 'IN',
|
|
|
|
'iowa' => 'IA',
|
|
|
|
'kansas' => 'KS',
|
|
|
|
'kentucky' => 'KY',
|
|
|
|
'louisiana' => 'LA',
|
|
|
|
'maine' => 'ME',
|
|
|
|
'maryland' => 'MD',
|
|
|
|
'massachusetts' => 'MA',
|
|
|
|
'michigan' => 'MI',
|
|
|
|
'minnesota' => 'MN',
|
|
|
|
'mississippi' => 'MS',
|
|
|
|
'missouri' => 'MO',
|
|
|
|
'montana' => 'MT',
|
|
|
|
'nebraska' => 'NE',
|
|
|
|
'nevada' => 'NV',
|
|
|
|
'new hampshire' => 'NH',
|
|
|
|
'new jersey' => 'NJ',
|
|
|
|
'new mexico' => 'NM',
|
|
|
|
'new york' => 'NY',
|
|
|
|
'north carolina' => 'NC',
|
|
|
|
'north dakota' => 'ND',
|
|
|
|
'ohio' => 'OH',
|
|
|
|
'oklahoma' => 'OK',
|
|
|
|
'oregon' => 'OR',
|
|
|
|
'pennsylvania' => 'PA',
|
|
|
|
'puerto rico' => 'PR',
|
|
|
|
'rhode island' => 'RI',
|
|
|
|
'south carolina' => 'SC',
|
|
|
|
'south dakota' => 'SD',
|
|
|
|
'tennessee' => 'TN',
|
|
|
|
'texas' => 'TX',
|
|
|
|
'utah' => 'UT',
|
|
|
|
'vermont' => 'VT',
|
|
|
|
'virginia' => 'VA',
|
|
|
|
'washington' => 'WA',
|
|
|
|
'west virginia' => 'WV',
|
|
|
|
'wisconsin' => 'WI',
|
|
|
|
'wyoming' => 'WY'
|
|
|
|
}
|
|
|
|
|
|
|
|
Countries = [
|
|
|
|
"Afghanistan",
|
|
|
|
"Albania",
|
|
|
|
"Algeria",
|
|
|
|
"American Samoa",
|
|
|
|
"Andorra",
|
|
|
|
"Angola",
|
|
|
|
"Anguilla",
|
|
|
|
"Antarctica",
|
|
|
|
"Antigua and Barbuda",
|
|
|
|
"Argentina",
|
|
|
|
"Armenia",
|
|
|
|
"Aruba",
|
|
|
|
"Australia",
|
|
|
|
"Austria",
|
|
|
|
"Azerbaijan",
|
|
|
|
"Bahamas",
|
|
|
|
"Bahrain",
|
|
|
|
"Bangladesh",
|
|
|
|
"Barbados",
|
|
|
|
"Belarus",
|
|
|
|
"Belgium",
|
|
|
|
"Belize",
|
|
|
|
"Benin",
|
|
|
|
"Bermuda",
|
|
|
|
"Bhutan",
|
|
|
|
"Bolivia",
|
|
|
|
"Bosnia and Herzegovina",
|
|
|
|
"Botswana",
|
|
|
|
"Bouvet Island",
|
|
|
|
"Brazil",
|
|
|
|
"British Indian Ocean Territory",
|
|
|
|
"Brunei Darussalam",
|
|
|
|
"Bulgaria",
|
|
|
|
"Burkina Faso",
|
|
|
|
"Burundi",
|
|
|
|
"Cambodia",
|
|
|
|
"Cameroon",
|
|
|
|
"Canada",
|
|
|
|
"Cape Verde",
|
|
|
|
"Cayman Islands",
|
|
|
|
"Central African Republic",
|
|
|
|
"Chad",
|
|
|
|
"Chile",
|
|
|
|
"China",
|
|
|
|
"Christmas Island",
|
|
|
|
"Cocos (Keeling) Islands",
|
|
|
|
"Colombia",
|
|
|
|
"Comoros",
|
|
|
|
"Congo",
|
|
|
|
"Cook Islands",
|
|
|
|
"Costa Rica",
|
|
|
|
"Cote D'ivoire",
|
|
|
|
"Croatia",
|
|
|
|
"Cuba",
|
|
|
|
"Cyprus",
|
|
|
|
"Czech Republic",
|
|
|
|
"Denmark",
|
|
|
|
"Djibouti",
|
|
|
|
"Dominica",
|
|
|
|
"Dominican Republic",
|
|
|
|
"Ecuador",
|
|
|
|
"Egypt",
|
|
|
|
"El Salvador",
|
|
|
|
"Equatorial Guinea",
|
|
|
|
"Eritrea",
|
|
|
|
"Estonia",
|
|
|
|
"Ethiopia",
|
|
|
|
"Falkland Islands (Malvinas)",
|
|
|
|
"Faroe Islands",
|
|
|
|
"Fiji",
|
|
|
|
"Finland",
|
|
|
|
"France",
|
|
|
|
"French Guiana",
|
|
|
|
"French Polynesia",
|
|
|
|
"French Southern Territories",
|
|
|
|
"Gabon",
|
|
|
|
"Gambia",
|
|
|
|
"Georgia",
|
|
|
|
"Germany",
|
|
|
|
"Ghana",
|
|
|
|
"Gibraltar",
|
|
|
|
"Greece",
|
|
|
|
"Greenland",
|
|
|
|
"Grenada",
|
|
|
|
"Guadeloupe",
|
|
|
|
"Guam",
|
|
|
|
"Guatemala",
|
|
|
|
"Guinea",
|
|
|
|
"Guinea-bissau",
|
|
|
|
"Guyana",
|
|
|
|
"Haiti",
|
|
|
|
"Heard Island and Mcdonald Islands",
|
|
|
|
"Honduras",
|
|
|
|
"Hong Kong",
|
|
|
|
"Hungary",
|
|
|
|
"Iceland",
|
|
|
|
"India",
|
|
|
|
"Indonesia",
|
|
|
|
"Iran",
|
|
|
|
"Iraq",
|
|
|
|
"Ireland",
|
|
|
|
"Israel",
|
|
|
|
"Italy",
|
|
|
|
"Jamaica",
|
|
|
|
"Japan",
|
|
|
|
"Jordan",
|
|
|
|
"Kazakhstan",
|
|
|
|
"Kenya",
|
|
|
|
"Kiribati",
|
|
|
|
"Korea (South)",
|
|
|
|
"Kuwait",
|
|
|
|
"Kyrgyzstan",
|
|
|
|
"Lao People's Democratic Republic",
|
|
|
|
"Latvia",
|
|
|
|
"Lebanon",
|
|
|
|
"Lesotho",
|
|
|
|
"Liberia",
|
|
|
|
"Libyan Arab Jamahiriya",
|
|
|
|
"Liechtenstein",
|
|
|
|
"Lithuania",
|
|
|
|
"Luxembourg",
|
|
|
|
"Macao",
|
|
|
|
"Macedonia",
|
|
|
|
"Madagascar",
|
|
|
|
"Malawi",
|
|
|
|
"Malaysia",
|
|
|
|
"Maldives",
|
|
|
|
"Mali",
|
|
|
|
"Malta",
|
|
|
|
"Marshall Islands",
|
|
|
|
"Martinique",
|
|
|
|
"Mauritania",
|
|
|
|
"Mauritius",
|
|
|
|
"Mayotte",
|
|
|
|
"Mexico",
|
|
|
|
"Micronesia",
|
|
|
|
"Moldova",
|
|
|
|
"Monaco",
|
|
|
|
"Mongolia",
|
|
|
|
"Montserrat",
|
|
|
|
"Morocco",
|
|
|
|
"Mozambique",
|
|
|
|
"Myanmar",
|
|
|
|
"Namibia",
|
|
|
|
"Nauru",
|
|
|
|
"Nepal",
|
|
|
|
"Netherlands",
|
|
|
|
"Netherlands Antilles",
|
|
|
|
"New Caledonia",
|
|
|
|
"New Zealand",
|
|
|
|
"Nicaragua",
|
|
|
|
"Niger",
|
|
|
|
"Nigeria",
|
|
|
|
"Niue",
|
|
|
|
"Norfolk Island",
|
|
|
|
"Northern Mariana Islands",
|
|
|
|
"Norway",
|
|
|
|
"Oman",
|
|
|
|
"Pakistan",
|
|
|
|
"Palau",
|
|
|
|
"Palestinian Territory",
|
|
|
|
"Panama",
|
|
|
|
"Papua New Guinea",
|
|
|
|
"Paraguay",
|
|
|
|
"Peru",
|
|
|
|
"Philippines",
|
|
|
|
"Pitcairn",
|
|
|
|
"Poland",
|
|
|
|
"Portugal",
|
|
|
|
"Puerto Rico",
|
|
|
|
"Qatar",
|
|
|
|
"Reunion",
|
|
|
|
"Romania",
|
|
|
|
"Russia",
|
|
|
|
"Rwanda",
|
|
|
|
"Saint Helena",
|
|
|
|
"Saint Kitts and Nevis",
|
|
|
|
"Saint Lucia",
|
|
|
|
"Saint Pierre and Miquelon",
|
|
|
|
"Saint Vincent and The Grenadines",
|
|
|
|
"Samoa",
|
|
|
|
"San Marino",
|
|
|
|
"Sao Tome and Principe",
|
|
|
|
"Saudi Arabia",
|
|
|
|
"Senegal",
|
|
|
|
"Serbia and Montenegro",
|
|
|
|
"Seychelles",
|
|
|
|
"Sierra Leone",
|
|
|
|
"Singapore",
|
|
|
|
"Slovakia",
|
|
|
|
"Slovenia",
|
|
|
|
"Solomon Islands",
|
|
|
|
"Somalia",
|
|
|
|
"South Africa",
|
|
|
|
"South Georgia and The South Sandwich Islands",
|
|
|
|
"Spain",
|
|
|
|
"Sri Lanka",
|
|
|
|
"Sudan",
|
|
|
|
"Suriname",
|
|
|
|
"Svalbard and Jan Mayen",
|
|
|
|
"Swaziland",
|
|
|
|
"Sweden",
|
|
|
|
"Switzerland",
|
|
|
|
"Syria ",
|
|
|
|
"Taiwan",
|
|
|
|
"Tajikistan",
|
|
|
|
"Tanzania",
|
|
|
|
"Thailand",
|
|
|
|
"Timor-leste",
|
|
|
|
"Togo",
|
|
|
|
"Tokelau",
|
|
|
|
"Tonga",
|
|
|
|
"Trinidad and Tobago",
|
|
|
|
"Tunisia",
|
|
|
|
"Turkey",
|
|
|
|
"Turkmenistan",
|
|
|
|
"Tuvalu",
|
|
|
|
"Uganda",
|
|
|
|
"Ukraine",
|
|
|
|
"United Arab Emirates",
|
|
|
|
"United Kingdom",
|
|
|
|
"United States",
|
|
|
|
"Uruguay",
|
|
|
|
"Uzbekistan",
|
|
|
|
"Vanuatu",
|
|
|
|
"Venezuela",
|
|
|
|
"Viet Nam",
|
|
|
|
"Virgin Islands",
|
|
|
|
"Wallis and Futuna",
|
|
|
|
"Western Sahara",
|
|
|
|
"Yemen",
|
|
|
|
"Zambia",
|
|
|
|
"Zimbabwe"
|
|
|
|
]
|
|
|
|
|
|
|
|
# Convert a full state name like "New Mexico" into a code like "NM"
|
|
|
|
# Will leave strings that are already state codes alone
|
|
|
|
def self.full_state_to_code(str)
|
|
|
|
str = str.strip
|
|
|
|
return str if StateCodes.include?(str.upcase)
|
|
|
|
return StateMappings[str.downcase]
|
|
|
|
end
|
|
|
|
|
|
|
|
end; end
|