module FFaker::IdentificationBR

def cnpj

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

def cnpj_verification_digits(cnpj)

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

def cpf

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

def cpf_verification_digits(cpf)

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

def document_verification_digits(verification_multipliers, document = nil)

def document_verification_digits(verification_multipliers, document = nil)
  return false if document.nil?
  document_digits = document.to_s.scan(/[0-9]/).map(&:to_i)
  validation_digits = []
  if document_digits.size + 1 == verification_multipliers.size && document_digits.uniq.size > 1
    0.upto(1) do |i|
      sum = verification_multipliers.drop(1 - i).each_with_index.inject(0) do |val, (value, j)|
        val + document_digits[j] * value
      end
      validation_digits[i] = (sum %= 11) < 2 ? 0 : 11 - sum
      document_digits.push(validation_digits[i])
    end
    return validation_digits
  end
  []
end

def gender

def gender
  fetch_sample(GENDERS)
end

def pretty_cnpj

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

def pretty_cpf

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

def pretty_rg

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

def rg

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