Module: Glib::CountryList
- Defined in:
- app/models/glib/country_list.rb
Overview
ISO 3166 country data for country dropdowns.
Backed entirely by the countries gem, so there is no table to migrate or
seed, and renames (Türkiye, Czechia) arrive with a bundle update. Store
the alpha-2 code rather than the name, so a rename never invalidates
existing data.
Class Method Summary collapse
- .codes ⇒ Object
- .name_for(code) ⇒ Object
-
.options ⇒ Object
common_nameis what people actually call the place ("South Korea", "United Kingdom") rather than the formal ISO name ("Korea (Republic of)").
Class Method Details
.codes ⇒ Object
21 22 23 |
# File 'app/models/glib/country_list.rb', line 21 def codes @codes ||= .pluck(:value).freeze end |
.name_for(code) ⇒ Object
25 26 27 28 29 30 |
# File 'app/models/glib/country_list.rb', line 25 def name_for(code) return if code.blank? country = ISO3166::Country[code] country && (country.common_name || country.iso_short_name) end |
.options ⇒ Object
common_name is what people actually call the place ("South Korea",
"United Kingdom") rather than the formal ISO name ("Korea (Republic of)").
14 15 16 17 18 19 |
# File 'app/models/glib/country_list.rb', line 14 def @options ||= ISO3166::Country.all .map { |country| { value: country.alpha2, text: country.common_name || country.iso_short_name } } .sort_by { |option| option[:text] } .freeze end |