module

Burocracia::CNPJ

The CNPJ module offers methods to validate, generate and format Brazilian CNPJs.

Constants

BLACKLIST = ["12345678912345", "12345678900000", "12345678999999", "12345678911111"]
FORMATTED_REGEX = /^\d{2}.\d{3}.\d{3}\/\d{4}-\d{2}$/i
UNFORMATTED_REGEX = /^[0-9]{14}$/i

Instance methods

format(cnpj : String) : String

Formats a CNPJ using the pattern XX.XXX.XXX/XXXX-XX.

Source
formatted?(cnpj : String) : Bool

Checks whether a CNPJ is formatted correctly or not.

Source
generate(format : Bool = false) : String

Generates a randomic valid CNPJ.

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

Source
valid?(cnpj : String) : Bool

Returns whether a CNPJ is valid or not.

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

Source