class Arbetsformedlingen::MunicipalityCode

Constants

CODES_MAP_INVERTED
CODE_MAP

Public Class Methods

normalize(name) click to toggle source
# File lib/arbetsformedlingen/codes/municipality_code.rb, line 23
def self.normalize(name)
  name.to_s.strip
end
to_code(name) click to toggle source
# File lib/arbetsformedlingen/codes/municipality_code.rb, line 12
def self.to_code(name)
  normalized = normalize(name)
  CODE_MAP.fetch(normalized) do
    normalized if CODES_MAP_INVERTED[normalized]
  end
end
to_form_array(name_only: false) click to toggle source
# File lib/arbetsformedlingen/codes/municipality_code.rb, line 27
def self.to_form_array(name_only: false)
  return CODE_MAP.to_a unless name_only

  CODE_MAP.map { |name, _code| [name, name] }
end
valid?(name) click to toggle source
# File lib/arbetsformedlingen/codes/municipality_code.rb, line 19
def self.valid?(name)
  !to_code(name).nil?
end