Class: PkiExpress::PkiBrazilCertificateFields

Inherits:
Object
  • Object
show all
Defined in:
lib/pki_express/pki_brazil_certificate_fields.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ PkiBrazilCertificateFields

Returns a new instance of PkiBrazilCertificateFields.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 9

def initialize(model)
  @certificate_type = nil
  @cpf = nil
  @cnpj = nil
  @responsavel = nil
  @date_of_birth = nil
  @company_name = nil
  @rg_numero = nil
  @rg_emissor = nil
  @rg_emissor_uf = nil
  @oab_numero = nil
  @oab_uf = nil

  unless model.nil?
    @certificate_type = model.fetch(:certificateType)
    @cpf = model.fetch(:cpf)
    @cnpj = model.fetch(:cnpj)
    @responsavel = model.fetch(:responsavel)
    @date_of_birth = model.fetch(:dateOfBirth)
    @company_name = model.fetch(:companyName)
    @rg_numero = model.fetch(:rgNumero)
    @rg_emissor = model.fetch(:rgEmissor)
    @rg_emissor_uf = model.fetch(:rgEmissorUF)
    @oab_numero = model.fetch(:oabNumero)
    @oab_uf = model.fetch(:oabUF)
  end
end

Instance Attribute Details

#certificate_typeObject

Returns the value of attribute certificate_type.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def certificate_type
  @certificate_type
end

#cnpjObject

Returns the value of attribute cnpj.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def cnpj
  @cnpj
end

#company_nameObject

Returns the value of attribute company_name.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def company_name
  @company_name
end

#cpfObject

Returns the value of attribute cpf.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def cpf
  @cpf
end

#date_of_birthObject

Returns the value of attribute date_of_birth.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def date_of_birth
  @date_of_birth
end

#oab_numeroObject

Returns the value of attribute oab_numero.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def oab_numero
  @oab_numero
end

#oab_ufObject

Returns the value of attribute oab_uf.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def oab_uf
  @oab_uf
end

#responsavelObject

Returns the value of attribute responsavel.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def responsavel
  @responsavel
end

#rg_emissorObject

Returns the value of attribute rg_emissor.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def rg_emissor
  @rg_emissor
end

#rg_emissor_ufObject

Returns the value of attribute rg_emissor_uf.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def rg_emissor_uf
  @rg_emissor_uf
end

#rg_numeroObject

Returns the value of attribute rg_numero.



5
6
7
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 5

def rg_numero
  @rg_numero
end

Instance Method Details

#cnpj_formattedObject



47
48
49
50
51
52
53
54
55
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 47

def cnpj_formatted
  unless @cnpj
    return nil
  end
  unless /^\d{14}$/.match(@cnpj)
    return @cnpj
  end
  "#{@cnpj[0..1]}.#{@cnpj[2..4]}.#{@cnpj[5..7]}/#{@cnpj[8..11]}-#{@cnpj[12..-1]}"
end

#cpf_formattedObject



37
38
39
40
41
42
43
44
45
# File 'lib/pki_express/pki_brazil_certificate_fields.rb', line 37

def cpf_formatted
  unless @cpf
    return nil
  end
  unless /^\d{11}$/.match(@cpf)
    return @cpf
  end
  "#{@cpf[0..2]}.#{@cpf[3..5]}.#{@cpf[6..8]}-#{@cpf[9..-1]}"
end