Module: ISO::Countries::ClassMethods
- Included in:
- ISO::Countries
- Defined in:
- lib/iso_countries.rb
Instance Method Summary collapse
-
#country_codes ⇒ Object
Returns an array with all the available country codes.
-
#get_code(name) ⇒ Object
Wrapper to get country code from country name.
-
#get_country(code) ⇒ Object
Wrapper to get country name from country code.
-
#language ⇒ Object
Gets te current translation language.
-
#set_language(lang) ⇒ Object
Sets the language for country translation.
Instance Method Details
#country_codes ⇒ Object
Returns an array with all the available country codes
58 59 60 |
# File 'lib/iso_countries.rb', line 58 def country_codes COUNTRIES.keys.map { |key| key.to_s } end |
#get_code(name) ⇒ Object
Wrapper to get country code from country name.
47 48 49 50 51 52 53 54 55 |
# File 'lib/iso_countries.rb', line 47 def get_code(name) if COUNTRIES.value?(name) COUNTRIES.each_pair do |k,v| if v.eql?(name) return k.to_s end end end end |
#get_country(code) ⇒ Object
Wrapper to get country name from country code. code
can be a symbol or a string containing the country code.
42 43 44 |
# File 'lib/iso_countries.rb', line 42 def get_country(code) _(COUNTRIES[code.to_sym]) rescue nil end |
#language ⇒ Object
Gets te current translation language
37 38 39 |
# File 'lib/iso_countries.rb', line 37 def language @@language || "en" end |
#set_language(lang) ⇒ Object
Sets the language for country translation
30 31 32 33 34 |
# File 'lib/iso_countries.rb', line 30 def set_language(lang) @@language = lang GetText.bindtextdomain "iso_countries", :path => "#{File.dirname(__FILE__)}/../locale" GetText.locale = lang end |