Class: BuhoCfdi::Certificate

Inherits:
Object
  • Object
show all
Defined in:
lib/buho_cfdi/certificate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Certificate

Returns a new instance of Certificate.



8
9
10
11
12
13
14
15
16
17
# File 'lib/buho_cfdi/certificate.rb', line 8

def initialize (file)
  if file.is_a? String
    file = file
  end
  certificate = OpenSSL::X509::Certificate.new(file)
  @certificate_number = '';
  certificate.serial.to_s(16).scan(/.{2}/).each { |v| @certificate_number += v[1]; }
  @certificate_value = certificate.to_s.gsub(/^-.+/, '').gsub(/\n/, '')
  
end

Instance Attribute Details

#certificate_numberObject (readonly)

Returns the value of attribute certificate_number.



6
7
8
# File 'lib/buho_cfdi/certificate.rb', line 6

def certificate_number
  @certificate_number
end

#certificate_valueObject (readonly)

Returns the value of attribute certificate_value.



6
7
8
# File 'lib/buho_cfdi/certificate.rb', line 6

def certificate_value
  @certificate_value
end

Instance Method Details

#certificate(xml) ⇒ Object



19
20
21
22
23
24
# File 'lib/buho_cfdi/certificate.rb', line 19

def certificate(xml)
  xml = Nokogiri::XML(xml)
  xml.at_css('cfdi|Comprobante').set_attribute('NoCertificado',@certificate_number)
  xml.at_css('cfdi|Comprobante').set_attribute('Certificado',@certificate_value)
  xml.to_xml
end