Sha256: eee656d809d5f367eece384fb86684250a68fcc34a75fcdec47bd5ef0affaf2c
Contents?: true
Size: 734 Bytes
Versions: 1
Compression:
Stored size: 734 Bytes
Contents
require "edacpfbr/version" module EdaCPFbr def self.validar(cpf) return false if cpf.length < 11 @cpf = cpf @first_block = @cpf[0..8] @dig1 = @cpf[9] @dig2 = @cpf[10] @second_block = @cpf[1..9] return false if not digito_correto(@first_block,@dig1) return false if not digito_correto(@second_block,@dig2) true end def self.validar_lote(lote) retorno_lote = Hash.new lote.each{ |cpf| retorno_lote[cpf] = validar(cpf) } retorno_lote end def self.digito_correto(bloco,dig) digito(bloco) == dig.to_i end def self.digito(bloco) total = 0 (1..9).each do |i| ind = i - 1 d = bloco[ind].to_i total += d*i end r = total % 11 (r>9) ? 0 : r end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
edacpfbr-0.1.0 | lib/edacpfbr.rb |