Sha256: 80d63bca1011abd9b3f5f9a86d2c64cc8b23861cfa54502e8b5c1ffd1f5b2e8a
Contents?: true
Size: 530 Bytes
Versions: 2
Compression:
Stored size: 530 Bytes
Contents
class Typero::OibType < Typero::Type def check? oib oib = oib.to_s return false if (oib =~ /\d{11}/) != 0 return false if oib.length != 11 a = 10 (0..9).each do |i| a = (a + oib[i,1].to_i) % 10 a = 10 if a == 0 a = (a * 2) % 11 end kontrolna = 11 - a kontrolna = 0 if kontrolna == 10 kontrolna == oib[10,1].to_i end def set @value = check?(@value) ? @value.to_i : nil end def validate raise TypeError.new('Not an OIB') unless check?(@value) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
typero-0.3.6 | ./lib/typero/type/oib.rb |
typero-0.3.4 | ./lib/typero/type/oib.rb |