Sha256: 5c6a152d2a47af49af6b47c3a96ad383ca281ccacf3f42bb75e4e0a7f8437e03

Contents?: true

Size: 521 Bytes

Versions: 2

Compression:

Stored size: 521 Bytes

Contents

# frozen_string_literal: true

require 'csv'
require 'set'

module Arbetsformedlingen
  class CountryCode
    CODES = CSV.read(
      File.expand_path('../../../data/country-codes.csv', __dir__)
    ).to_h.freeze

    COUNTRY_CODES = Set.new(CODES.values).freeze

    def self.to_code(country_code)
      normalize(country_code)
    end

    def self.valid?(country_code)
      COUNTRY_CODES.include?(normalize(country_code))
    end

    def self.normalize(country_code)
      country_code.to_s.upcase
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
arbetsformedlingen-0.7.0 lib/arbetsformedlingen/codes/country_code.rb
arbetsformedlingen-0.6.0 lib/arbetsformedlingen/codes/country_code.rb