Sha256: 3b155acd9d89308c3643fda30d677b6b8c5cb80548eadc8326063533c0703243
Contents?: true
Size: 727 Bytes
Versions: 1
Compression:
Stored size: 727 Bytes
Contents
# frozen_string_literal: true require 'csv' module Arbetsformedlingen class OccupationCode DATA_PATH = File.expand_path('../../../data/occupation-codes.csv', __dir__) CODE_MAP = CSV.read(DATA_PATH).to_h.invert.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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arbetsformedlingen-0.7.0 | lib/arbetsformedlingen/codes/occupation_code.rb |