Sha256: 16c7ced9f10ca69b60d15e28e07f2827f553214f318ee689f521c9668592b745
Contents?: true
Size: 364 Bytes
Versions: 1
Compression:
Stored size: 364 Bytes
Contents
module PolishValidators class NipValidator def initialize(nip) @nip = nip.to_s end def valid? return unless @nip.match(/\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.0 | lib/polish_validators/nip_validator.rb |