Sha256: c5449804333269dc6ce4586e271f170b2f0a1bc509ceb7763a2f66f0c406754b
Contents?: true
Size: 713 Bytes
Versions: 1
Compression:
Stored size: 713 Bytes
Contents
# frozen_string_literal: true require 'csv' module Arbetsformedlingen class OccupationCode CODE_MAP = CSV.read( File.expand_path('../../../data/occupation-codes.csv', __dir__) ).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.6.0 | lib/arbetsformedlingen/codes/occupation_code.rb |