module

Burocracia::CPF

The CPF module offers methods to validate, generate and format Brazilian CPFs.

Constants

BLACKLIST = ["12345678901", "1235678999", "12345678900"]
FORMATTED_REGEX = /^[0-9]{3}.[0-9]{3}.[0-9]{3}-[0-9]{2}$/i
UNFORMATTED_REGEX = /^[0-9]{11}$/i

Instance methods

format(cpf : String)

Formats a CPF using the pattern XXX.XXX.XXX-XX.

Source
formatted?(cpf : String)

Checks whether a CPF is formatted correctly or not.

Source
generate(format : Bool = false)

Generates a randomic valid CPF.

If you want to get a formatted new CPF, you can pass an argument to the format parameter.

Source
valid?(cpf : String)

Returns whether a CPF is valid or not.

NOTE: This will not fetch the CPF in the Receita Federal database to check the existance.

Source