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/district.rb,
lib/swissmatch/zipcodes.rb,
lib/swissmatch/community.rb,
lib/swissmatch/districts.rb,
lib/swissmatch/loaderror.rb,
lib/swissmatch/communities.rb,
lib/swissmatch/location/version.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 collapse

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


213
214
215
# File 'lib/swissmatch/location.rb', line 213

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

.cantons(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::cantons


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

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


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

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


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

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

.communities(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::communities


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

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

.community(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::community


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

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

.district(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::district


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

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

.districts(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::districts


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

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

.transliterate1(word) ⇒ Object

Used to transliterate city names



299
300
301
# File 'lib/swissmatch/location.rb', line 299

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

.transliterate2(word) ⇒ Object

Used to transliterate city names



305
306
307
# File 'lib/swissmatch/location.rb', line 305

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



311
312
313
# File 'lib/swissmatch/location.rb', line 311

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

.zip_code(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::zip_code


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

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

.zip_codes(*args, &block) ⇒ Object

See Also:

  • SwissMatch::Location::zip_codes


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

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