Sha256: 05b92e82bbf54353f8aa48d703c5e6798715676a8b2007db1976a3feda7d74a2

Contents?: true

Size: 514 Bytes

Versions: 1

Compression:

Stored size: 514 Bytes

Contents

module Egn
  class Validator

    # Checks if a given EGN is valid
    def self.validate(egn)
      return false unless egn.length == 10

      # Extract the correct year and month
      year, month, day = egn.scan(/.{1,2}/).map(&:to_i)
      year, month = Util.determine_date(year, month)

      return false unless Date.valid_date? year, month, day

      # Calculate the checksum and check if the given one is correct
      checksum = Util.egn_checksum egn[0,9]
      checksum == egn[9].to_i
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
egn-0.4.0 lib/egn/validator.rb