Sha256: 820c53067fbba98a4fe97bd40d912735d7e25d0c2cb920651eeaa5c72801fccb
Contents?: true
Size: 710 Bytes
Versions: 2
Compression:
Stored size: 710 Bytes
Contents
# frozen_string_literal: true require 'csv' module Arbetsformedlingen class MunicipalityCode CODE_MAP = CSV.read( File.expand_path('../../../data/municipality-codes.csv', __dir__) ).to_h.freeze CODES_MAP_INVERTED = CODE_MAP.invert.freeze def self.to_code(name) normalized = normalize(name) CODE_MAP.fetch(normalized) do normalized if CODES_MAP_INVERTED[normalized] end end def self.valid?(name) !to_code(name).nil? end def self.normalize(name) name.to_s.strip end def self.to_form_array(name_only: false) return CODE_MAP.to_a unless name_only CODE_MAP.map { |name, _code| [name, name] } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
arbetsformedlingen-0.7.0 | lib/arbetsformedlingen/codes/municipality_code.rb |
arbetsformedlingen-0.6.0 | lib/arbetsformedlingen/codes/municipality_code.rb |