Module: CountrySelect

Defined in:
lib/country_select/version.rb,
lib/country_select/countries.rb

Constant Summary collapse

VERSION =
"1.3.1"

Class Method Summary collapse

Class Method Details

.countries(with_locale = nil) ⇒ Object

Localized Countries list



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/country_select/countries.rb', line 18

def self.countries(with_locale=nil)
  with_locale ||= locale

  ISO3166::Country.all.inject({}) do |hash,country_pair|
    default_name = country_pair.first
    code = country_pair.last
    country = Country.new(code)
    localized_name = country.translations[with_locale.to_s]

    # Codes should not be downcased, but they were previous to 1.3
    # which means they should continue to be until 2.0 is released in
    # order to prevent breakage with existing implementations
    hash[code.downcase] = localized_name || default_name
    hash
  end
end

.localeObject



13
14
15
# File 'lib/country_select/countries.rb', line 13

def self.locale
  I18n.locale
end

.use_iso_codesObject



5
6
7
# File 'lib/country_select/countries.rb', line 5

def self.use_iso_codes
  Thread.current[:country_select_use_iso_codes] ||= false
end

.use_iso_codes=(val) ⇒ Object



9
10
11
# File 'lib/country_select/countries.rb', line 9

def self.use_iso_codes=(val)
  Thread.current[:country_select_use_iso_codes] = val
end