Module: FFaker::IdentificationBR

Extended by:
IdentificationBR, ModuleUtils
Included in:
IdentificationBR
Defined in:
lib/ffaker/identification_br.rb

Constant Summary collapse

GENDERS =
%w[Feminino Masculino].freeze
CPF_VERIFICATION_MULTIPLIERS =
[11, 10, 9, 8, 7, 6, 5, 4, 3, 2].freeze
CNPJ_VERIFICATION_MULTIPLIERS =
[6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2].freeze

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore, unique

Methods included from RandomUtils

#fetch_sample, #rand, #shuffle

Instance Method Details

#cnpjObject


27
28
29
30
31
# File 'lib/ffaker/identification_br.rb', line 27

def cnpj
  cnpj = FFaker.numerify('############')
  validators = cnpj_verification_digits(cnpj)
  cnpj + validators.join
end

#cnpj_verification_digits(cnpj) ⇒ Object


59
60
61
# File 'lib/ffaker/identification_br.rb', line 59

def cnpj_verification_digits(cnpj)
  document_verification_digits(CNPJ_VERIFICATION_MULTIPLIERS, cnpj)
end

#cpfObject


12
13
14
15
16
# File 'lib/ffaker/identification_br.rb', line 12

def cpf
  cpf = FFaker.numerify('#########')
  validators = cpf_verification_digits(cpf)
  cpf + validators.join
end

#cpf_verification_digits(cpf) ⇒ Object


55
56
57
# File 'lib/ffaker/identification_br.rb', line 55

def cpf_verification_digits(cpf)
  document_verification_digits(CPF_VERIFICATION_MULTIPLIERS, cpf)
end

#genderObject


51
52
53
# File 'lib/ffaker/identification_br.rb', line 51

def gender
  fetch_sample(GENDERS)
end

#pretty_cnpjObject


33
34
35
36
37
38
39
40
41
# File 'lib/ffaker/identification_br.rb', line 33

def pretty_cnpj
  cnpj_numbers = cnpj.to_s.rjust(14, '0')
  format('%s.%s.%s/%s-%s',
         cnpj_numbers[0..1],
         cnpj_numbers[2..4],
         cnpj_numbers[5..7],
         cnpj_numbers[8..11],
         cnpj_numbers[12..14])
end

#pretty_cpfObject


18
19
20
21
22
23
24
25
# File 'lib/ffaker/identification_br.rb', line 18

def pretty_cpf
  cpf_numbers = cpf
  format('%s.%s.%s-%s',
         cpf_numbers[0..2],
         cpf_numbers[3..5],
         cpf_numbers[6..8],
         cpf_numbers[9..10])
end

#pretty_rgObject


47
48
49
# File 'lib/ffaker/identification_br.rb', line 47

def pretty_rg
  FFaker.numerify('###.###.###')
end

#rgObject


43
44
45
# File 'lib/ffaker/identification_br.rb', line 43

def rg
  FFaker.numerify('#########')
end