Class: NfseSjc::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/nfse_sjc/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(filepath, params = {}) ⇒ Document

Returns a new instance of Document.



6
7
8
9
# File 'lib/nfse_sjc/document.rb', line 6

def initialize(filepath, params = {})
  @params   = params
  @template = load_template(filepath)
end

Instance Method Details

#to_signed_xmlObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nfse_sjc/document.rb', line 15

def to_signed_xml
  unsigned_xml   = to_xml

  unsigned_temp_xml = Tempfile.new('unsigned-xml')
  signed_temp_xml   = Tempfile.new('signed-xml')
  result            = ''

  begin
    unsigned_temp_xml.write(unsigned_xml)
    unsigned_temp_xml.rewind

    %x{#{NfseSjc.config[:xmlsec_binary_path]} --sign --privkey-pem '#{NfseSjc.config[:ssl_cert_key_file]}','#{NfseSjc.config[:ssl_cert_file]}' --output '#{signed_temp_xml.path}' --pwd '#{NfseSjc.config[:ssl_cert_key_password]}' '#{unsigned_temp_xml.path}'}

    signed_temp_xml.rewind
    result = signed_temp_xml.read
  ensure
    signed_temp_xml.close
    unsigned_temp_xml.close

    signed_temp_xml.unlink
    unsigned_temp_xml.unlink
  end

  result
end

#to_xmlObject



11
12
13
# File 'lib/nfse_sjc/document.rb', line 11

def to_xml
  @template.result(binding)
end