
Security News
Researcher Exposes Zero-Day Clickjacking Vulnerabilities in Major Password Managers
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
sundawg_country_codes
Advanced tools
= SunDawg Country Codes
== About
This project is a Ruby gem to manage ISO 3166 country names and their corresponding alpha-2 and alpha-3 codes. Additional support has been added for ISO 4127 currency information and standard conventions for states in the USA (based on the the 3166-2:US code).
Reference information can be found:
ISO 3166 Country Codes
http://en.wikipedia.org/wiki/ISO_3166-1
ISO 4217 Currency Information
http://www.xe.com/iso4217.php http://www.xe.com/symbols.php
ISO 3166-2:US Codes
http://code.google.com/apis/chart/statecodes.html http://en.wikipedia.org/wiki/ISO_3166-2:US
ISO 639 Languages
http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
== Testing
Tests can be executed by running:
bundle exec rake test
== Code Examples
To translate from a country's name to their ISO Alpha-2 code:
SunDawg::CountryIsoTranslater.translate_iso3166_name_to_alpha2("United States")
To translate from a country's name to their ISO Alpha-3 code:
SunDawg::CountryIsoTranslater.translate_iso3166_name_to_alpha3("Egypt")
To translate from a country's ISO Alpha-2 code to country name:
SunDawg::CountryIsoTranslater.translate_iso3166_alpha2_to_name("US")
To translate form a country's ISO Alpha-3 code to country name:
SunDawg::CountryIsoTranslater.translate_iso3166_alpha3_to_name("ESP")
To obtain currency information for a country:
currency = SunDawg::CountryIsoTranslater.get_iso4217_currency_by_iso3166_alpha2("US") assert_equal currency["code"], "USD" assert_equal currency["symbol"], "$" assert_equal currency["name"], "Dollars" assert_equal currency["unicode_hex"], 36
NOTE:
Not all countries have currency information and not all currency information contains both the symbol. Some currency information contain a second currency under currency["alt_currency"] which will then contain the same hash values for a currency.
Furthermore, while the hex value for representing the unicode symbol is stored in the .yml file, the import into Ruby is converting it into decimal. You can convert back to hex as so:
assert_equal currency["unicode_hex"].to_s(16), "24"
The unicode value, either in base 10 or base 16 will allow you to render the symbol properly in HTML:
$ or $
More information:
http://www.fileformat.info/info/unicode/char/0024/index.htm
To build the unicode HTML for a symbol:
currency = SunDawg::CountryIsoTranslater.get_iso4217_currency_by_iso3166_alpha2("UZ") assert_equal SunDawg::CountryIsoTranslater.build_html_unicode(currency["unicode_hex"]), "лв"
To translate to and from USA state name and the 2-digit code:
SunDawg::USAStateTranslater.translate_name_to_code('New York') SunDawg::USAStateTranslater.translate_code_to_name('NY')
To translate ISO-639 languages from alpha 2 code:
language = SunDawg::LanguageIsoTranslater.get_iso_639_1_translation("en") assert_equal "English", language['name'] assert_equal "eng", language['alpha3t']
NOTE: Some languages have an alternate alpha3b code per ISO-639-2/B to indicate the "B" alpha 3 letter code for the language.
== Data Files
All country code and names are stored in a countries.yml file that can be changed as you need. The latest codes and country names are derived from:
http://en.wikipedia.org/wiki/ISO_3166-1
== Gem Install
This gem is hosted on rubygems.org. Bundler and Rails instructions for your Gemfile are there.
http://rubygems.org/gems/sundawg_country_codes
== Rails 2 Install
To include this gem in your Rails project, add the following to your config/environment.rb:
config.gem 'sundawg_country_codes', :lib => 'country_iso_translater'
== History
FAQs
Unknown package
We found that sundawg_country_codes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.