def sign_xml(xml, sign_nodes=[])
			return xml unless certificate
			signer = Signer.new(xml)
			signer.cert        = certificate
			signer.private_key = certificate_key

			# Como o documento não é um envelope SOAP preciso setar o security_node e o security_token_id
			signer.security_node = signer.document.root
			signer.security_token_id = ""

			sign_nodes.each do |options|
				node_ids = [options[:node_ids]].flatten
				signer.document.xpath(options[:node_path], options[:node_namespaces]).each_with_index do |node, i|
					# digo quais tags devem ser assinadas
					signer.digest!(node, id: "#{node_ids[i]}", enveloped: true)
				end				
			end
			
			# Assina o XML
			signer.sign!(security_token: false, issuer_serial: true)

			signer.to_xml
		end
def sign_xml(xml, sign_nodes=[])
			return xml unless certificate
			signer = Signer.new(xml)
			signer.cert        = certificate
			signer.private_key = certificate_key

			# Como o documento não é um envelope SOAP preciso setar o security_node e o security_token_id
			signer.security_node = signer.document.root
			signer.security_token_id = ""

			sign_nodes.each do |options|
				node_ids = [options[:node_ids]].flatten
				signer.document.xpath(options[:node_path], options[:node_namespaces]).each_with_index do |node, i|
					# digo quais tags devem ser assinadas
					signer.digest!(node, id: "#{node_ids[i]}", enveloped: true)
				end				
			end
			
			# Assina o XML
			signer.sign!(security_token: false, issuer_serial: true)

			signer.to_xml
		end
USE EXAMPLE
  @xml = <?xml version="1.0" encoding="ISO-8859-1"?>
          <EnviarLoteRpsEnvio xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd">
            <LoteRps id="L2">
              ...
              <ListaRps>
                <Rps>
                  <InfRps id="R2">
                    ...
                  </>InfRps
                </Rps>
                <Rps>
                  <InfRps id="R3">
                    ...
                  </>InfRps
                </Rps>
              </ListaRps>
            </LoteRps>
          </EnviarLoteRpsEnvio>
 sign_nodes = [
   {
 	   node_path: "//nf:EnviarLoteRpsEnvio/nf:LoteRps/nf:ListaRps/nf:Rps/nf:InfRps",
 	   node_namespaces: {nf: 'http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd'},
 	   node_ids: ['R2','R3']
   },
   {
     node_path: "//nf:EnviarLoteRpsEnvio/nf:LoteRps",
     node_namespaces: {nf: 'http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd'},
     node_ids: ['L2']
   },
 ]

 Call Method:
 sign_xml(@xml, sign_nodes)