struct CPF
- CPF
- CadastroID
- Struct
- Value
- Object
Overview
Represents a CPF (Cadastro de Pessoas FĂsicas) identifier.
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: ...>Defined in:
cpf_cnpj/cpf/cpf.crcpf_cnpj/cpf/errors.cr
cpf_cnpj/cpf/validator.cr
cpf_cnpj/json.cr
cpf_cnpj/yaml.cr
Constructors
- 
        .from_json_object_key?(key : String) : self
        
          Deserializes the given JSON key into a CPF.
- 
        .new(context : YAML::ParseContext, node : YAML::Nodes::Node) : self
        
          Creates CPFfrom YAML usingYAML::ParseContext.
- 
        .new(value : String)
        
          Creates a CPFfrom aString.
- 
        .new(pull : JSON::PullParser) : self
        
          Creates CPFfrom JSON usingJSON::PullParser.
Class Method Summary
- 
        .parse?(value : String) : self | Nil
        
          Returns a CPFif the given String is a valid CPF identifier, otherwise returnsnil.
Instance Method Summary
- 
        #formatted : String
        
          Returns the formatted CPF identifier 
- 
        #unformatted : String
        
          Returns the unformatted CPF identifier 
- 
        #value : String
        
          The raw value used to initialize the CPF 
Instance methods inherited from struct CadastroID
  
  
    
      ==(other : self) : Bool
    ==, 
    
  
    
      formatted : String
    formatted, 
    
  
    
      to_json(json : JSON::Builder) : Nil
    to_json, 
    
  
    
      to_s(io : IO) : Nilto_s : String to_s, to_yaml(yaml : YAML::Nodes::Builder) : Nil to_yaml, unformatted : String unformatted, value : String value
Constructor methods inherited from struct CadastroID
  
  
    
      from_json_object_key?(key : String) : self
    from_json_object_key?, 
    
  
    
      new(context : YAML::ParseContext, node : YAML::Nodes::Node) : selfnew(value : String) : self
new(pull : JSON::PullParser) : self new
Class methods inherited from struct CadastroID
  
  
    
      from_rs(rs : DB::ResultSet) : self | Nil
    from_rs, 
    
  
    
      parse?(value : String) : self | Nil
    parse?
    
  
      
    
      
      
      
      
    
      
      
      
      
    
      
      
      
      
    
  Constructor Detail
Deserializes the given JSON key into a CPF.
NOTE  require "cpf_cnpj/json" is required to opt-in to this feature.
Creates CPF from YAML using YAML::ParseContext.
NOTE  require "cpf_cnpj/yaml" is required to opt-in to this feature.
require "yaml"
require "cpf_cnpj"
require "cpf_cnpj/yaml"
class Example
  include YAML::Serializable
  property cpf : CPF
end
example = Example.from_yaml("cpf: 466.828.070-40")
example.cpf # => #<CPF: ...>Creates a CPF from a String.
It accepts formatted and stripped strings
If the String isn't a valid CPF identifier, an CPF::InvalidValueError exception will be
raised. See .parse if you want a safe way to initialize a CPF.
CPF.new("640.061.830-97") # => #<CPF: ...>
CPF.new("64006183097")    # => #<CPF: ...>
CPF.new("1234")           # => raises `CPF::InvalidValueError`Creates CPF from JSON using JSON::PullParser.
NOTE  require "cpf_cnpj/json" is required to opt-in to this feature.
require "json"
require "cpf_cnpj"
require "cpf_cnpj/json"
class Example
  include JSON::Serializable
  property cpf : CPF
end
example = Example.from_json(%({"cpf": "466.828.070-40"}))
example.cpf # => #<CPF: ...>Class Method Detail
Returns a CPF if the given String is a valid CPF identifier, otherwise
returns nil.
CPF.parse?("640.061.830-97") # => #<CPF: ...>
CPF.parse?("64006183097")    # => #<CPF: ...>
CPF.parse?("1234")           # => nilInstance Method Detail
Returns the formatted CPF identifier
cpf = CPF.new("64006183097")
cpf.formatted # => "640.061.830-97"Returns the unformatted CPF identifier
cpf = CPF.new("640.061.830-97")
cpf.unformatted # => "64006183097"