Module: SwissMatch

Defined in:
lib/swissmatch/location.rb,
lib/swissmatch/name.rb,
lib/swissmatch/canton.rb,
lib/swissmatch/cantons.rb,
lib/swissmatch/zipcode.rb,
lib/swissmatch/zipcodes.rb,
lib/swissmatch/district.rb,
lib/swissmatch/community.rb,
lib/swissmatch/loaderror.rb,
lib/swissmatch/districts.rb,
lib/swissmatch/communities.rb,
lib/swissmatch/location/version.rb,
lib/swissmatch/location/converter.rb,
lib/swissmatch/location/datafiles.rb

Overview

Note:

All strings passed to SwissMatch are expected to be utf-8. All strings returned by SwissMatch are also in utf-8.

From SwissMatch::Location Deal with swiss zip codes, cities, communities and cantons.

Examples:

Load the data

require 'swissmatch/location'
SwissMatch::Location.load
# alternatively, just require 'swissmatch/location/autoload'

Get the ONRP for a given zip-code + city

require 'swissmatch/location/autoload'
SwissMatch.zip_code(8000, 'Zürich').ordering_number # => 4384
SwissMatch.zip_code(4384).name # => "Zürich"(de, 0)

Defined Under Namespace

Modules: Location Classes: Canton, Cantons, Communities, Community, District, Districts, LoadError, Name, ZipCode, ZipCodes

Constant Summary

Transliteration1 =

Used to transliterate city names

{
  "à" => "a",
  "â" => "a",
  "ä" => "a",
  "è" => "e",
  "é" => "e",
  "ê" => "e",
  "ë" => "e",
  "ì" => "i",
  "î" => "i",
  "ï" => "i",
  "ô" => "o",
  "ö" => "o",
  "ù" => "u",
  "ü" => "u",
}
Transliteration2 =

Used to transliterate city names

Transliteration1.merge({
  "ä" => "ae",
  "ö" => "oe",
  "ü" => "ue",
})
TransMatch1 =

Used to transliterate city names

/#{Transliteration1.keys.map { |k| Regexp.escape(k) }.join("|")}/
TransMatch2 =

Used to transliterate city names

/#{Transliteration2.keys.map { |k| Regexp.escape(k) }.join("|")}/

Class Method Summary collapse

Class Method Details

.canton(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::canton


217
218
219
# File 'lib/swissmatch/location.rb', line 217

def self.canton(*args, &block)
  SwissMatch::Location.canton(*args, &block)
end

.cantons(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::cantons


222
223
224
# File 'lib/swissmatch/location.rb', line 222

def self.cantons(*args, &block)
  SwissMatch::Location.cantons(*args, &block)
end

.cities_for_zip_code(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::cities_for_zip_code


262
263
264
# File 'lib/swissmatch/location.rb', line 262

def self.cities_for_zip_code(*args, &block)
  SwissMatch::Location.cities_for_zip_code(*args, &block)
end

.city(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::city


257
258
259
# File 'lib/swissmatch/location.rb', line 257

def self.city(*args, &block)
  SwissMatch::Location.city(*args, &block)
end

.communities(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::communities


242
243
244
# File 'lib/swissmatch/location.rb', line 242

def self.communities(*args, &block)
  SwissMatch::Location.communities(*args, &block)
end

.community(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::community


237
238
239
# File 'lib/swissmatch/location.rb', line 237

def self.community(*args, &block)
  SwissMatch::Location.community(*args, &block)
end

.district(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::district


227
228
229
# File 'lib/swissmatch/location.rb', line 227

def self.district(*args, &block)
  SwissMatch::Location.district(*args, &block)
end

.districts(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::districts


232
233
234
# File 'lib/swissmatch/location.rb', line 232

def self.districts(*args, &block)
  SwissMatch::Location.districts(*args, &block)
end

.transliterate1(word) ⇒ Object

Used to transliterate city names



303
304
305
# File 'lib/swissmatch/location.rb', line 303

def self.transliterate1(word)
  word.gsub(TransMatch1, Transliteration1).delete("^ A-Za-z").downcase
end

.transliterate2(word) ⇒ Object

Used to transliterate city names



309
310
311
# File 'lib/swissmatch/location.rb', line 309

def self.transliterate2(word)
  word.gsub(TransMatch2, Transliteration2).delete("^ A-Za-z").downcase
end

.transliterated_words(string) ⇒ Object

Transliterates a string into the unique transliterated (1 & 2) word list



315
316
317
# File 'lib/swissmatch/location.rb', line 315

def self.transliterated_words(string)
  "#{transliterate1(string)} #{transliterate2(string)}".split(" ").uniq
end

.zip_code(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::zip_code


252
253
254
# File 'lib/swissmatch/location.rb', line 252

def self.zip_code(*args, &block)
  SwissMatch::Location.zip_code(*args, &block)
end

.zip_codes(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::zip_codes


247
248
249
# File 'lib/swissmatch/location.rb', line 247

def self.zip_codes(*args, &block)
  SwissMatch::Location.zip_codes(*args, &block)
end