module Rnfse::XMLBuilder::Abrasf10::ClassMethods
Public Instance Methods
build_cancelar_nfse_xml(hash = {})
click to toggle source
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 46 def build_cancelar_nfse_xml(hash = {}) if block_given? build_xml('CancelarNfseEnvio', hash, &Proc.new) else build_xml('CancelarNfseEnvio', hash) end end
build_consultar_lote_rps_xml(hash = {})
click to toggle source
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 38 def build_consultar_lote_rps_xml(hash = {}) if block_given? build_xml('ConsultarLoteRpsEnvio', hash, &Proc.new) else build_xml('ConsultarLoteRpsEnvio', hash) end end
build_consultar_nfse_por_rps_xml(hash = {})
click to toggle source
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 22 def build_consultar_nfse_por_rps_xml(hash = {}) if block_given? build_xml('ConsultarNfseRpsEnvio', hash, &Proc.new) else build_xml('ConsultarNfseRpsEnvio', hash) end end
build_consultar_nfse_xml(hash = {})
click to toggle source
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 30 def build_consultar_nfse_xml(hash = {}) if block_given? build_xml('ConsultarNfseEnvio', hash, &Proc.new) else build_xml('ConsultarNfseEnvio', hash) end end
build_consultar_situacao_lote_rps_xml(hash = {})
click to toggle source
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 14 def build_consultar_situacao_lote_rps_xml(hash = {}) if block_given? build_xml('ConsultarSituacaoLoteRpsEnvio', hash, &Proc.new) else build_xml('ConsultarSituacaoLoteRpsEnvio', hash) end end
build_recepcionar_lote_rps_xml(hash = {})
click to toggle source
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 6 def build_recepcionar_lote_rps_xml(hash = {}) if block_given? build_xml('EnviarLoteRpsEnvio', hash, &Proc.new) else build_xml('EnviarLoteRpsEnvio', hash) end end
Private Instance Methods
add_tc_namespace(hash)
click to toggle source
adiciona o namespace tc nas tags dentro de loteRps ou prestador
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 137 def add_tc_namespace(hash) regex = %r{ \A( LoteRps| Prestador| IdentificacaoRps| Tomador| IntermediarioServico| Pedido )\Z }x Rnfse::Hash.replace_key_values(hash, regex) do |key, value| { key => Rnfse::Hash.transform_keys(value) { |k| "tc:#{k}".to_sym } } end end
build_cancelar_nfse_xmlns()
click to toggle source
namespaces do xml cancelar_nfse
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 197 def build_cancelar_nfse_xmlns { 'xmlns' => 'http://www.abrasf.org.br/servico_cancelar_nfse_envio.xsd', 'xmlns:tc' => xmlns_tc } end
build_consultar_lote_rps_xmlns()
click to toggle source
namespaces do xml consultar_lote_rps
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 165 def build_consultar_lote_rps_xmlns { 'xmlns' => 'http://www.abrasf.org.br/servico_consultar_lote_rps_envio.xsd', 'xmlns:tc' => xmlns_tc } end
build_consultar_nfse_por_rps_xmlns()
click to toggle source
namespaces do xml consultar_nfse_por_rps
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 181 def build_consultar_nfse_por_rps_xmlns { 'xmlns' => 'http://www.abrasf.org.br/servico_consultar_situacao_lote_rps_envio.xsd', 'xmlns:tc' => xmlns_tc } end
build_consultar_nfse_xmlns()
click to toggle source
namespaces do xml consultar_nfse
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 189 def build_consultar_nfse_xmlns { 'xmlns' => 'http://www.abrasf.org.br/servico_consultar_nfse_envio.xsd', 'xmlns:tc' => xmlns_tc } end
build_consultar_situacao_lote_rps_xmlns()
click to toggle source
namespaces do xml consultar_situacao_lote_rps
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 173 def build_consultar_situacao_lote_rps_xmlns { 'xmlns' => 'http://www.abrasf.org.br/servico_consultar_situacao_lote_rps_envio.xsd', 'xmlns:tc' => xmlns_tc } end
build_recepcionar_lote_rps_xmlns()
click to toggle source
namespaces do xml recepcionar_lote_rps
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 157 def build_recepcionar_lote_rps_xmlns { 'xmlns' => 'http://www.abrasf.org.br/servico_enviar_lote_rps_envio.xsd', 'xmlns:tc' => xmlns_tc } end
build_xml(wrapper, hash = {}) { |XML(inner_xml)| ... }
click to toggle source
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 56 def build_xml(wrapper, hash = {}) hash = prepare_hash(hash) inner_xml = ::Gyoku.xml(hash, key_converter: :none) inner_xml = yield(Nokogiri::XML(inner_xml)) if block_given? xml_builder(wrapper, inner_xml).doc end
camelize_hash(hash)
click to toggle source
converte as chaves do hash para CamelCase
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 98 def camelize_hash(hash) Rnfse::Hash.camelize_and_symbolize_keys(hash) end
clean_numerics(hash)
click to toggle source
limpa tags que por precaução é melhor só conter números
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 92 def clean_numerics(hash) regex = /(Cep|Cnae|Cpf|Cnpj)\Z/ Rnfse::Hash.transform_values(hash, regex) { |val| val.gsub(/\D/, '') } end
date_to_utc(hash)
click to toggle source
converte datas para GMT-0
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 85 def date_to_utc(hash) Rnfse::Hash.transform_values(hash, /DataEmissao\Z/) do |val| DateTime.parse(val.to_s).new_offset(0).strftime('%FT%T') end end
fix_booleans(hash)
click to toggle source
converte booleanos para 1 ou 2
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 77 def fix_booleans(hash) regex = /((?<!Valor)IssRetido|OptanteSimplesNacional|IncentivadorCultural)\Z/ Rnfse::Hash.transform_values(hash, regex) do |val| val ? 1 : 2 end end
prepare_hash(hash)
click to toggle source
prepara um hash para ser convertido a xml com o Gyoku
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 64 def prepare_hash(hash) hash = camelize_hash(hash) hash = wrap_rps(hash) hash = wrap_periodo_emissao(hash) hash = wrap_identificacao_nfse(hash) hash = add_tc_namespace(hash) hash = clean_numerics(hash) hash = date_to_utc(hash) hash = fix_booleans(hash) hash end
wrap_identificacao_nfse(hash)
click to toggle source
encapsula a tag identificacao_nfse
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 124 def wrap_identificacao_nfse(hash) if hash[:IdentificacaoNfse] hash[:Pedido] = { :InfPedidoCancelamento => { :IdentificacaoNfse => hash.delete(:IdentificacaoNfse), :CodigoCancelamento => hash.delete(:CodigoCancelamento) } } end hash end
wrap_periodo_emissao(hash)
click to toggle source
encapsula as tags data_inicial e data_final em periodo_emissao
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 113 def wrap_periodo_emissao(hash) if hash[:DataInicial] or hash[:DataFinal] hash[:PeriodoEmissao] = { :DataInicial => hash.delete(:DataInicial), :DataFinal => hash.delete(:DataFinal) } end hash end
wrap_rps(hash)
click to toggle source
encapsula as rps dentro de listaRps com Rps/InfRps
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 103 def wrap_rps(hash) if hash[:LoteRps] hash[:LoteRps][:ListaRps] = { :Rps => hash[:LoteRps][:ListaRps].map { |rps| { :InfRps => rps} } } end hash end
xml_builder(root, inner_xml, xmlns = {})
click to toggle source
instancia o builder a ser utilizado na geracao do xml
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 205 def xml_builder(root, inner_xml, xmlns = {}) xmlns = self.send("#{Rnfse::CallChain.caller_method(2)}ns") if xmlns.empty? Nokogiri::XML::Builder.new(encoding: 'utf-8') do |xml| xml.send(root.to_sym, xmlns) do xml << inner_xml end end end
xmlns_tc()
click to toggle source
namespace dos tipos complexos
# File lib/rnfse/xml_builder/abrasf_1_0.rb, line 152 def xmlns_tc 'http://www.abrasf.org.br/tipos_complexos.xsd' end