Sha256: 68a3f2cfcbbcbeabd5f19e1c91408eb1e27bedc97a9a3284938b47cc2ae4f64a

Contents?: true

Size: 695 Bytes

Versions: 8

Compression:

Stored size: 695 Bytes

Contents

require 'set'

module Arbetsformedlingen
  module DriversLicenseCode
    CODES = Set.new([
      'AM', 'A1', 'A2', 'A', 'B', 'Utökad B', 'BE', 'C1', 'C1E', 'C', 'CE', 'D1', 'D1E', 'D', 'DE'
    ]).freeze

    def self.codes
      CODES.to_a
    end

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

    def self.valid?(drivers_license)
      to_a(drivers_license).all? { |dl| CODES.include?(dl) }
    end

    def self.normalize(drivers_license)
      to_a(drivers_license).join(',')
    end

    def self.to_a(drivers_license)
      drivers_license.to_s.
        split(',').
        map(&:strip).
        reject(&:empty?).
        map(&:upcase)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
arbetsformedlingen-0.5.0 lib/arbetsformedlingen/codes/drivers_license_code.rb
arbetsformedlingen-0.4.1 lib/arbetsformedlingen/codes/drivers_license_code.rb
arbetsformedlingen-0.4.0 lib/arbetsformedlingen/codes/drivers_license_code.rb
arbetsformedlingen-0.3.0 lib/arbetsformedlingen/codes/drivers_license_code.rb
arbetsformedlingen-0.2.0 lib/arbetsformedlingen/codes/drivers_license_code.rb
arbetsformedlingen-0.1.2 lib/arbetsformedlingen/codes/drivers_license_code.rb
arbetsformedlingen-0.1.1 lib/arbetsformedlingen/codes/drivers_license_code.rb
arbetsformedlingen-0.1.0 lib/arbetsformedlingen/codes/drivers_license_code.rb