module CountriesAndLanguages

Constants

CONVERSIONS
RUBY_18
VERSION

Public Class Methods

clean_and_sort(data) click to toggle source
# File lib/countries_and_languages.rb, line 25
def self.clean_and_sort(data)
  data = data.to_a
  data.map!{|code,name| [clean_name(name), code] }
  data.sort_by{|code,_| convert_umlaut_to_base(code) }
end
clean_name(name) click to toggle source
# File lib/countries_and_languages.rb, line 31
def self.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) click to toggle source
# File lib/countries_and_languages.rb, line 59
def self.convert_umlaut_to_base(input)
  input = input.dup
  if RUBY_18
    old = $KCODE
    $KCODE='u'
    CONVERSIONS.each { |from, to| input.gsub!(/[#{from}]/, to) }
    $KCODE = old
  else
    CONVERSIONS.each { |from, to| input.tr!(from, to) }
  end
  input
end