struct CNPJ
- CNPJ
- Struct
- Value
- Object
Overview
Represents a CNPJ (Cadastro Nacional de Pessoas JurÃdica) identifier.
A CNPJ
object is designed to never hold an invalid value, so you can assume
that a CNPJ object will always hold a valid value.
cnpj = CNPJ.new("24.485.147/0001-87")
cnpj.value # => "24.485.147/0001-87"
cnpj.formatted # => "24.485.147/0001-87"
cnpj.unformatted # => ""24485147000187""
CNPJ.new("11111111111111") # => raises `ArgumentError`
CNPJ.parse("11111111111111") # => nil
CNPJ.parse("24.485.147/0001-87") # => #<CNPJ:0x104fe0ae0 @value="24.485.147/0001-87">
Defined in:
cnpj.crcnpj/validator.cr
Constant Summary
-
VERSION =
"1.0.0"
Constructors
-
.new(value : String) : CNPJ
Creates a
CNPJ
from aString
.
Class Method Summary
-
.parse(value : String) : CNPJ | Nil
Returns a
CNPJ
if the given String is a valid CNPJ identifier, otherwise returnsnil
.
Instance Method Summary
-
#formatted : String
Returns the formatted CNPJ identifier
-
#unformatted : String
Returns the unformatted CNPJ identifier
- #value : String
Constructor Detail
Creates a CNPJ
from a String
.
It accepts formatted and stripped strings
If the String isn't a valid CNPJ, an CNPJ::InvalidValueError
exception will be
raised. See .parse
if you want a safe way to initialize a CNPJ.
Class Method Detail
Returns a CNPJ
if the given String is a valid CNPJ identifier, otherwise
returns nil
.
Instance Method Detail
Returns the formatted CNPJ identifier
cpf = CNPJ.new("24485147000187")
cpf.formatted # => "24.485.147/0001-87"
Returns the unformatted CNPJ identifier
cpf = CNPJ.new("24.485.147/0001-87")
cpf.unformatted # => "24485147000187"