Module SunDawg::CountryIsoTranslater
In: lib/country_iso_translater.rb
lib/country_iso_translater.rb

Methods

Classes and Modules

Class SunDawg::CountryIsoTranslater::NoCountryError
Class SunDawg::CountryIsoTranslater::NoCurrencyError

Constants

FILE = File.expand_path(File.join(File.dirname(__FILE__), 'countries.yml')) unless defined?(FILE)   allows client application to override YAML hash
COUNTRIES = YAML.load_file(FILE) unless defined?(COUNTRIES)
FILE = File.expand_path(File.join(File.dirname(__FILE__), 'countries.yml')) unless defined?(FILE)   allows client application to override YAML hash
COUNTRIES = YAML.load_file(FILE) unless defined?(COUNTRIES)

Public Class methods

[Source]

    # File lib/country_iso_translater.rb, line 54
54:     def self.build_html_unicode(unicode_hex)
55:       s = ""
56:       if unicode_hex.class == Fixnum
57:         s = "&#x#{unicode_hex.to_s(16)}"
58:       elsif unicode_hex.class == Array
59:         unicode_hex.each { |i|
60:           s += "&#x#{i.to_s(16)}"
61:         }
62:       end 
63:       s
64:     end

[Source]

    # File lib/country_iso_translater.rb, line 54
54:     def self.build_html_unicode(unicode_hex)
55:       s = ""
56:       if unicode_hex.class == Fixnum
57:         s = "&#x#{unicode_hex.to_s(16)}"
58:       elsif unicode_hex.class == Array
59:         unicode_hex.each { |i|
60:           s += "&#x#{i.to_s(16)}"
61:         }
62:       end 
63:       s
64:     end

O(1) find for iso 4217 currency information

[Source]

    # File lib/country_iso_translater.rb, line 47
47:     def self.get_iso4217_currency_by_iso3166_alpha2(code)
48:       country = COUNTRIES[code]
49:       raise NoCountryError.new("[#{code}] IS NOT VALID") if country.nil?
50:       raise NoCurrencyError.new("[#{code}] HAS NO ISO4217 CURRENCY") if country["currency_iso4217"].nil?
51:       country["currency_iso4217"]
52:     end

O(1) find for iso 4217 currency information

[Source]

    # File lib/country_iso_translater.rb, line 47
47:     def self.get_iso4217_currency_by_iso3166_alpha2(code)
48:       country = COUNTRIES[code]
49:       raise NoCountryError.new("[#{code}] IS NOT VALID") if country.nil?
50:       raise NoCurrencyError.new("[#{code}] HAS NO ISO4217 CURRENCY") if country["currency_iso4217"].nil?
51:       country["currency_iso4217"]
52:     end

[Source]

    # File lib/country_iso_translater.rb, line 23
23:     def self.translate_iso3166_alpha2_to_alpha3(code)
24:       translate_standard(code, "alpha2", "alpha3")
25:     end

[Source]

    # File lib/country_iso_translater.rb, line 23
23:     def self.translate_iso3166_alpha2_to_alpha3(code)
24:       translate_standard(code, "alpha2", "alpha3")
25:     end

O(1) translation of iso3166 2-digit code to name

[Source]

    # File lib/country_iso_translater.rb, line 40
40:     def self.translate_iso3166_alpha2_to_name(code)
41:       country = COUNTRIES[code]
42:       raise NoCountryError.new("[#{code}] IS NOT VALID") if country.nil?
43:       country["name"]  
44:     end

O(1) translation of iso3166 2-digit code to name

[Source]

    # File lib/country_iso_translater.rb, line 40
40:     def self.translate_iso3166_alpha2_to_name(code)
41:       country = COUNTRIES[code]
42:       raise NoCountryError.new("[#{code}] IS NOT VALID") if country.nil?
43:       country["name"]  
44:     end

[Source]

    # File lib/country_iso_translater.rb, line 27
27:     def self.translate_iso3166_alpha3_to_name(code)
28:       translate_standard(code, "alpha3", "name")
29:     end

[Source]

    # File lib/country_iso_translater.rb, line 27
27:     def self.translate_iso3166_alpha3_to_name(code)
28:       translate_standard(code, "alpha3", "name")
29:     end

O(N) translation from iso3166 name to 2-digit code

[Source]

    # File lib/country_iso_translater.rb, line 15
15:     def self.translate_iso3166_name_to_alpha2(name)
16:       translate_standard(name, "name", "alpha2")
17:     end

O(N) translation from iso3166 name to 2-digit code

[Source]

    # File lib/country_iso_translater.rb, line 15
15:     def self.translate_iso3166_name_to_alpha2(name)
16:       translate_standard(name, "name", "alpha2")
17:     end

[Source]

    # File lib/country_iso_translater.rb, line 19
19:     def self.translate_iso3166_name_to_alpha3(name)
20:       translate_standard(name, "name", "alpha3")
21:     end

[Source]

    # File lib/country_iso_translater.rb, line 19
19:     def self.translate_iso3166_name_to_alpha3(name)
20:       translate_standard(name, "name", "alpha3")
21:     end

O(N) translation from one convention standard to another

[Source]

    # File lib/country_iso_translater.rb, line 32
32:     def self.translate_standard(s, from_standard, to_standard)
33:       COUNTRIES.each_pair { |key, value| 
34:         return value[to_standard] if value[from_standard] == s 
35:       }
36:       raise NoCountryError.new("[#{s}] IS NOT VALID")
37:     end

O(N) translation from one convention standard to another

[Source]

    # File lib/country_iso_translater.rb, line 32
32:     def self.translate_standard(s, from_standard, to_standard)
33:       COUNTRIES.each_pair { |key, value| 
34:         return value[to_standard] if value[from_standard] == s 
35:       }
36:       raise NoCountryError.new("[#{s}] IS NOT VALID")
37:     end

[Validate]