sundawg_country_codes 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +44 -0
- data/Rakefile +1 -1
- data/lib/countries.yml +790 -26
- data/lib/country_iso_translater.rb +23 -0
- data/sundawg_country_codes.gemspec +2 -2
- data/test/country_iso_translater_test.rb +83 -0
- metadata +2 -2
data/README
CHANGED
@@ -2,6 +2,15 @@ ABOUT
|
|
2
2
|
-----
|
3
3
|
This project is a Ruby gem to manage ISO 3166 country names and their corresponding alpha-2 and alpha-3 codes.
|
4
4
|
|
5
|
+
Reference information can be found:
|
6
|
+
|
7
|
+
ISO3166 Country Codes
|
8
|
+
http://en.wikipedia.org/wiki/ISO_3166-1
|
9
|
+
|
10
|
+
ISO4217 Currency Information
|
11
|
+
http://www.xe.com/iso4217.php
|
12
|
+
http://www.xe.com/symbols.php
|
13
|
+
|
5
14
|
TEST
|
6
15
|
----
|
7
16
|
Tests can be executed by running:
|
@@ -26,6 +35,35 @@ To translate form a country's ISO Alpha-3 code to country name:
|
|
26
35
|
|
27
36
|
SunDawg::CountryIsoTranslater.translate_iso3166_alpha3_to_name("ESP")
|
28
37
|
|
38
|
+
To obtain currency information for a country:
|
39
|
+
|
40
|
+
currency = SunDawg::CountryIsoTranslater.get_iso4217_currency_by_iso3166_alpha2("US")
|
41
|
+
assert_equal currency["code"], "USD"
|
42
|
+
assert_equal currency["symbol"], "$"
|
43
|
+
assert_equal currency["name"], "Dollars"
|
44
|
+
assert_equal currency["unicode_hex"], 36
|
45
|
+
|
46
|
+
NOTE:
|
47
|
+
|
48
|
+
Not all countries have currency information and not all currency information contains both the symbol. Some currency information contain a second currency under the curreny["alt_currency"] which will then contain the same hash values for a currency.
|
49
|
+
|
50
|
+
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:
|
51
|
+
|
52
|
+
assert_equal currency["unicode_hex"].to_s(16), "24"
|
53
|
+
|
54
|
+
The unicode value, either in base 10 or base 16 will allow you to render the symbol properly in HTML:
|
55
|
+
|
56
|
+
$ or $
|
57
|
+
|
58
|
+
More information:
|
59
|
+
|
60
|
+
http://www.fileformat.info/info/unicode/char/0024/index.htm
|
61
|
+
|
62
|
+
To build the unicode HTML for a symbol:
|
63
|
+
|
64
|
+
currency = SunDawg::CountryIsoTranslater.get_iso4217_currency_by_iso3166_alpha2("UZ")
|
65
|
+
assert_equal SunDawg::CountryIsoTranslater.build_html_unicode(currency["unicode_hex"]), "лв"
|
66
|
+
|
29
67
|
DATA
|
30
68
|
----
|
31
69
|
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:
|
@@ -46,3 +84,9 @@ RAILS INSTALL
|
|
46
84
|
To include this gem in your Rails project, add the following to your config/environment.rb:
|
47
85
|
|
48
86
|
config.gem 'sundawg_country_codes', :lib => 'country_iso_translater'
|
87
|
+
|
88
|
+
VERSION HISTORY
|
89
|
+
---------------
|
90
|
+
v0.0.2b - Completed all currency information, unicode HTML utility, and bug fixes. Gem version re-published as 0.0.2.
|
91
|
+
v0.0.2 - Added ISO 4217 currency information.
|
92
|
+
v0.0.1 - Allows basic ISO 3166 translation.
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'echoe'
|
5
5
|
|
6
|
-
Echoe.new('sundawg_country_codes', '0.0.
|
6
|
+
Echoe.new('sundawg_country_codes', '0.0.2') do |p|
|
7
7
|
p.description = "Manage ISO 3166 Country Names and Codes."
|
8
8
|
p.url = "http://github.com/SunDawg/country_codes"
|
9
9
|
p.author = "Christopher Sun"
|