Sha256: 29495271daefec7e28a9b7a6be2c52860c6b13935f20504328ebc4d1e68528eb

Contents?: true

Size: 579 Bytes

Versions: 1

Compression:

Stored size: 579 Bytes

Contents

module Egn
  module Validator

    def self.egn(egn)
      return false unless egn.length == 10

      year, month, day = egn.scan(/.{1,2}/)
      month = month.to_i
      day = day.to_i

      case month
      when (1..12)
        year = "19#{year}"
      when (21..32)
        month -= 20
        year = "18#{year}"
      when (41..52)
        month -= 40
        year = "20#{year}"
      end
      year = year.to_i

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

      checksum = Generator.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.2.0 lib/egn/validator.rb