Sha256: 36305df4bfde1975f8fec4ae232726bc7f3139ed2ada316a28c904065dc59629
Contents?: true
Size: 399 Bytes
Versions: 1
Compression:
Stored size: 399 Bytes
Contents
module PolishValidators class PeselValidator def initialize(pesel) @pesel = pesel.to_s end def valid? return unless @pesel.match(/\A\d{11}\Z/) weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3] pesel = @pesel.split(//).collect(&:to_i) checksum = weights.reduce(0) { |a, e| a + pesel.shift * e } (10 - (checksum % 10)) % 10 == pesel.shift end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polish_validators-1.0.0 | lib/polish_validators/pesel_validator.rb |