{"id":13483686,"url":"https://github.com/sshaw/normalize_country","last_synced_at":"2025-05-16T18:09:16.399Z","repository":{"id":8031910,"uuid":"9441497","full_name":"sshaw/normalize_country","owner":"sshaw","description":"Convert country names and codes to a standard.","archived":false,"fork":false,"pushed_at":"2025-02-22T10:51:02.000Z","size":76,"stargazers_count":70,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T18:15:15.246Z","etag":null,"topics":["conversion","country-codes","country-flags","emoji","iso3166","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sshaw.png","metadata":{"files":{"readme":"README.rdoc","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-15T05:36:05.000Z","updated_at":"2025-02-22T10:51:06.000Z","dependencies_parsed_at":"2022-08-26T01:43:23.550Z","dependency_job_id":null,"html_url":"https://github.com/sshaw/normalize_country","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fnormalize_country","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fnormalize_country/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fnormalize_country/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fnormalize_country/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshaw","download_url":"https://codeload.github.com/sshaw/normalize_country/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248601101,"owners_count":21131607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conversion","country-codes","country-flags","emoji","iso3166","ruby"],"created_at":"2024-07-31T17:01:14.160Z","updated_at":"2025-04-12T16:49:04.113Z","avatar_url":"https://github.com/sshaw.png","language":"Ruby","readme":"= NormalizeCountry\n\nConvert country names and codes to a standard.\n\n{\u003cimg src=\"https://github.com/sshaw/normalize_country/actions/workflows/ci.yml/badge.svg\" alt=\"Build Status\" /\u003e}[https://github.com/sshaw/normalize_country]\n\n=== Overview\n\n require \"normalize_country\"\n\n NormalizeCountry(\"America\")                       # \"United States\"\n NormalizeCountry(\"United States of America\")      # \"United States\"\n NormalizeCountry(\"USA\",  :to =\u003e :official)        # \"United States of America\"\n NormalizeCountry(\"Iran\", :to =\u003e :official)        # \"Islamic Republic of Iran\"\n NormalizeCountry(\"U.S.\", :to =\u003e :alpha2)          # \"US\"\n NormalizeCountry(\"U.S.\", :to =\u003e :numeric)         # \"840\"\n NormalizeCountry(\"US\",   :to =\u003e :fifa)            # \"USA\"\n NormalizeCountry(\"US\",   :to =\u003e :emoji)           # \"🇺🇸\"\n NormalizeCountry(\"US\",   :to =\u003e :shortcode)       # \":flag-us:\"\n NormalizeCountry(\"Iran\", :to =\u003e :alpha3)          # \"IRN\"\n NormalizeCountry(\"Iran\", :to =\u003e :ioc)             # \"IRI\"\n NormalizeCountry(\"DPRK\", :to =\u003e :short)           # \"North Korea\"\n NormalizeCountry(\"North Korea\", :to =\u003e :iso_name) # \"Korea, Democratic People's Republic Of\"\n\n # Or\n NormalizeCountry.convert(\"U.S.\", :to =\u003e :alpha2)  # \"US\"\n\n # Set the default\n NormalizeCountry.to = :alpha3\n NormalizeCountry.convert(\"Mexico\")                 # \"MEX\"\n NormalizeCountry.convert(\"United Mexican States\")  # \"MEX\"\n\n=== Installation\n\nRubygems ({part of Ruby}[https://www.ruby-lang.org]):\n\n  gem install normalize_country\n\n{Bundler}[http://bundler.io]:\n\n  gem \"normalize_country\"\n\n=== Supported Conversions\n\nIn addition to trying to convert from common, non-standardized names and abbrivations, +NormalizeCountry+\nwill convert to/from the following:\n\n[:alpha2] ISO 3166-1 alpha-2\n[:alpha3] ISO 3166-1 alpha-3\n[:emoji] The country's emoji\n[:fifa] FIFA (International Federation of Association Football)\n[:ioc] International Olympic Committee\n[:iso_name] Country name used by ISO 3166-1\n[:numeric] ISO 3166-1 numeric code\n[:official] The country's official name\n[:short] A shortned version of the country's name, commonly used when speaking and/or writing (US English)\n[:shortcode:] Emoji shortcode\n\nA list of valid formats can be obtained by calling +NormalizeCountry.formats+.\n\n=== Custom Database\n\nSet the +NORMALIZE_COUNTRY_DB+ environment variable.\nSee \u003ccode\u003elib/normalize_country/countries/en.yml\u003c/code\u003e for the expected format.\n\n=== Obtaining an Array or Hash\n\n NormalizeCountry.to_a                              # Defaults to NormalizeCountry.to\n NormalizeCountry.to_a(:ioc)                        # Array of IOC codes in ascending order\n NormalizeCountry.to_h(:ioc)                        # :ioc =\u003e NormalizeCountry.to\n NormalizeCountry.to_h(:ioc, :to =\u003e :numeric)       # :ioc =\u003e :numeric\n\n=== Conversion Utility\n\nA small script is included that can convert country names contained in a DB table or a set of XML or CSV files\n\n  shell \u003e normalize_country -h\n  usage: normalize_country [options] SOURCE\n      -h, --help                       Show this message\n      -f, --format FORMAT              The format of SOURCE\n      -t, --to CONVERSION              Convert country names to this format (see docs for valid formats)\n      -l, --location LOCATION          The location of the conversion\n\nSome examples\n\n normalize_country -t alpha2 -l 'Country Name' -f csv data.csv\n normalize_country -t numeric -l countries.code -f db postgres://usr:pass@localhost/conquests\n normalize_country -t fifa -l //teams[@sport = 'fútbol americano']//country -f xml data.xml\n\nIf the format is +xml+ or +csv+ you can spefify a directory instead of a filename\n\n normalize_country -t alpha2 -l 'Country Name' -f csv /home/sshaw/capital-losses/2008\n\nWith a format of +csv+ it will read all files with an extension of +csv+ or +tsv+.\nFor +csv+ and +xml+ \u003cb\u003ethe original file(s) will be overwritten with new file(s) containing the converted country names\u003c/b\u003e.\n\nTo convert an XML file with namespaces just include the namespace prefix defined in the file in the\nXPath query (+LOCATION+).\n\nThe +db+ format's +SOURCE+ argument must be a {Sequel connection string}[http://sequel.jeremyevans.net/rdoc/classes/Sequel.html#method-c-connect].\nHere +LOCATION+ is in the format +table.column+, which will be updated with the converted name.\n\n=== Random Country Data for Your Tests\n\nRandom data generating gems like {Faker}[http://rubygems.org/gems/faker] and {RandomData}[http://rubygems.org/gems/random_data] don't generate much country data.\nIf you'd like to use this gem to do so I suggest checking out this gist: https://gist.github.com/sshaw/6068404\n\n=== Faulty/Missing/Erroneous Country Names\n\nPlease submit a patch or {open an issue}[https://github.com/sshaw/normalize_country/issues].\n\n=== Why?\n\nThis code was -to some extent- part of a larger project that allowed users to perform a free-text search by country.\nCountry names were stored in the DB by their ISO names.\n\nSeveral years later at work we had to extract country names from a web service that didn't standardize\nthem. Sometimes they used UK, other times U.K. It then occured to me that this code could be useful outside\nof the original project. The web service was fixed but, nevertheless...\n\n=== Somewhat Similar Gems\n\nUpon further investigation I've found the following:\n\n* {Carmen}[https://github.com/jim/carmen]: ISO country names and states/subdivisions\n* {countries}[https://github.com/hexorx/countries] ISO country names, states/subdivisions, currency, E.164 phone numbers and language translations\n* {country_codes}[https://github.com/SunDawg/country_codes] ISO country names and currency data\n* {i18n_data}[https://github.com/grosser/i18n_data]: ISO country names in different languages, includes alpha codes\n* {ModelUN}[https://github.com/uhhuhyeah/model_un]: Similar to this gem but with less support for conversion, it does include US states\n\n=== See Also\n\n* {National Colors}[https://github.com/sshaw/national_colors]\n","funding_links":[],"categories":["Country Data","\u003ca name=\"text-processing\"\u003e\u003c/a\u003eText processing"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Fnormalize_country","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshaw%2Fnormalize_country","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Fnormalize_country/lists"}