Module: Geonames::Regions

Defined in:
lib/geonames_local/regions/abbr.rb

Class Method Summary collapse

Class Method Details

.abbr(name) ⇒ Object

Geonames does not have region/state abbr..#fail! This works 75% of the time in brazil heh



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/geonames_local/regions/abbr.rb', line 7

def self.abbr(name)
  table = { # exceptions
    'Amapá'       => 'AP',
    'Mato Grosso' => 'MT',
    'Paraíba'     => 'PB',
    'Paraná'      => 'PR',
    'Roraima'     => 'RR'
  }[name]
  return table if table
  s = name.split(' ')
  if s.length > 1 # Foo Bar -> 'FB'
    [s[0][0].chr, s[-1][0].chr].map(&:upcase).join
  else  # Foobar -> 'FO'
    s[0][0..1].upcase
  end
end