Module: CountriesAndLanguages
- Defined in:
- lib/countries_and_languages.rb,
lib/countries_and_languages/version.rb
Defined Under Namespace
Modules: Helpers
Constant Summary collapse
- CONVERSIONS =
[ ['áä', 'a'], ['ÁÄÅ', 'A'], ['óö', 'o'], ['ÓÖ', 'O'], ['í', 'i'], ['Í', 'I'], ['úü', 'u'], ['ÚÜ', 'U'], ['é', 'e'], ['É', 'E'], ['ß', 's'], ]
- RUBY_18 =
RUBY_VERSION < "1.9"
- VERSION =
Version = '0.2.0'
Class Method Summary collapse
Class Method Details
.clean_and_sort(data) ⇒ Object
25 26 27 28 29 |
# 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) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 |