class Laranja::Documento
Public Class Methods
cpf(uf = nil)
click to toggle source
# File lib/laranja/generators/pt-BR/documento.rb, line 4 def cpf(uf = nil) number = strf('########') + uf_code(uf) number + verification_digits(number).join end
cpf_formatado(uf = nil)
click to toggle source
# File lib/laranja/generators/pt-BR/documento.rb, line 9 def cpf_formatado(uf = nil) c = cpf(uf) '%03d.%03d.%03d-%02d' % [ c[0..2].to_i, c[3..5].to_i, c[6..8].to_i, c[9..10].to_i ] end
rg()
click to toggle source
# File lib/laranja/generators/pt-BR/documento.rb, line 14 def rg strf('#########') end
rg_formatado()
click to toggle source
# File lib/laranja/generators/pt-BR/documento.rb, line 18 def rg_formatado strf('##.###.###-#') end
Private Class Methods
uf_code(uf)
click to toggle source
# File lib/laranja/generators/pt-BR/documento.rb, line 24 def uf_code(uf) if uf data('codigo_uf')[uf.to_s.downcase].to_s else strf('#') end end
v1_digit(cpf)
click to toggle source
# File lib/laranja/generators/pt-BR/documento.rb, line 38 def v1_digit(cpf) v1 = (0..8).reduce(0) { |sum, i| sum + cpf[i].to_i * (10 - i) } v1 %= 11 if v1 < 2 0 else 11 - v1 end end
v2_digit(cpf, v1)
click to toggle source
# File lib/laranja/generators/pt-BR/documento.rb, line 48 def v2_digit(cpf, v1) v2 = (0..8).reduce(0) { |sum, i| sum + cpf[i].to_i * (11 - i) } v2 += v1 * 2 v2 %= 11 if v2 < 2 0 else 11 - v2 end end
verification_digits(cpf)
click to toggle source
# File lib/laranja/generators/pt-BR/documento.rb, line 32 def verification_digits(cpf) v1 = v1_digit(cpf) v2 = v2_digit(cpf, v1) [v1, v2] end