Module: CountriesAndLanguages
- Extended by:
- CountriesAndLanguages
- Included in:
- CountriesAndLanguages
- Defined in:
- lib/countries_and_languages.rb,
lib/countries_and_languages/version.rb
Defined Under Namespace
Modules: Helpers
Constant Summary collapse
- VERSION =
Version = '0.1.4'
Instance Method Summary collapse
Instance Method Details
#clean_and_sort(data) ⇒ Object
27 28 29 30 |
# File 'lib/countries_and_languages.rb', line 27 def clean_and_sort(data) data = data.to_a.sort_by{|code,name| convert_umlaut_to_base(name)} data.map!{|code,name|[clean_name(name),code]} end |
#clean_name(name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/countries_and_languages.rb', line 32 def clean_name(name) #General fixes name = name.sub(/\s*[,;(].*/,'') #German fixes name.sub!(/-Sprache$/,'') name.sub!(/ Peoples Democratic Republics Democratic Republic/,'')#Lao name.sub!(/Demokratische Republik /,'')#Congo name end |
#convert_umlaut_to_base(input) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/countries_and_languages.rb', line 44 def convert_umlaut_to_base(input) $KCODE='u' if RUBY_VERSION < '1.9' %w(aáä AÁÄÅ oóö OÓÖ ií IÍ uúü UÚÜ eé EÉ sß).inject(input.dup) do |input, set| to, *from = set.split('') input.gsub(/[#{from}]/, to) end end |