Sha256: a1b97fe775d3adb043cdaa8fba3abdb8e017271ec76db68c9e8ce3a10aa886ec
Contents?: true
Size: 360 Bytes
Versions: 1
Compression:
Stored size: 360 Bytes
Contents
module PolishValidators class NipValidator def initialize(nip) @nip = nip.to_s end def valid? return unless @nip =~ /\A\d{10}\Z/ weights = [6, 5, 7, 2, 3, 4, 5, 6, 7] nip = @nip.split(//).collect(&:to_i) checksum = weights.reduce(0) { |a, e| a + nip.shift * e } checksum % 11 == nip.shift end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polish_validators-1.0.1 | lib/polish_validators/nip_validator.rb |