class CPF
- CPF
- Reference
- Object
Overview
Represents a CPF (Cadastro de Pessoas FĂsicas) number.
A CPF object is designed to never hold an invalid value, so you can assume
that a CPF object will always hold a valid value.
cpf = CPF.new("640.061.830-97")
cpf.value # => "640.061.830-97"
cpf.formatted # => "640.061.830-97"
cpf.unformatted # => "64006183097"
CPF.new("11111111111") # => raises `ArgumentError`
CPF.parse("11111111111") # => nil
CPF.parse("640.061.830-97") # => #<CPF:0x104fe0ae0 @value="640.061.830-97">
Defined in:
cpf.crcpf/validator.cr
Constant Summary
-
VERSION =
"1.0.0"
Constructors
-
.new(value : String) : CPF
Creates a
CPFfrom aString.
Class Method Summary
-
.parse(value : String) : CPF | Nil
Returns a
CPFif the given String is a valid CPF number, otherwise returnsnil.
Instance Method Summary
-
#formatted : String
Returns the formatted CPF number
-
#unformatted : String
Returns the unformatted CPF number
-
#value : String
Returns the value provived on initialization
Constructor Detail
Creates a CPF from a String.
It accepts formatted and stripped strings
If the String isn't a valid CPF, an ArgumentError exception will be
raised. See .parse if you want a safe way to initialize a CPF.
Class Method Detail
Returns a CPF if the given String is a valid CPF number, otherwise
returns nil.
Instance Method Detail
Returns the formatted CPF number
cpf = CPF.new("64006183097")
cpf.formatted # => "640.061.830-97"
Returns the unformatted CPF number
cpf = CPF.new("640.061.830-97")
cpf.unformatted # => "64006183097"
Returns the value provived on initialization
cpf = CPF.new("640.061.830-97")
cpf.value # => "640.061.830-97"