Module: ItuCodes::Helpers
- Defined in:
- lib/itu_codes/helpers.rb
Constant Summary collapse
- ISO2ITU =
YAML.load_file( File.(File.dirname(__FILE__)) + '/../data/iso_code_to_itu_country_names.yml')
Class Method Summary collapse
-
.country_code_lookup(country_name) ⇒ Object
country name is the one used by ITU, not ISO.
- .country_name_lookup(iso_code) ⇒ Object
-
.keys_from_hash(hsh_or_array) ⇒ Object
ruby 1.8 support, since Hash#select returns an array.
Class Method Details
.country_code_lookup(country_name) ⇒ Object
country name is the one used by ITU, not ISO
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/itu_codes/helpers.rb', line 8 def self.country_code_lookup(country_name) hsh = ISO2ITU.select{|k,v| v === country_name} codes = ItuCodes::Helpers.keys_from_hash(hsh) if codes.empty? nil elsif codes.size === 1 codes.first else codes end end |
.country_name_lookup(iso_code) ⇒ Object
21 22 23 |
# File 'lib/itu_codes/helpers.rb', line 21 def self.country_name_lookup(iso_code) ISO2ITU[iso_code] end |
.keys_from_hash(hsh_or_array) ⇒ Object
ruby 1.8 support, since Hash#select returns an array
26 27 28 29 30 31 32 |
# File 'lib/itu_codes/helpers.rb', line 26 def self.keys_from_hash(hsh_or_array) if hsh_or_array.is_a?(Array) Hash[hsh_or_array] else hsh_or_array end.keys end |