From affab942d4edb57ceb32e9b92667109cea3d8e09 Mon Sep 17 00:00:00 2001 From: luiz_c Date: Mon, 10 Aug 2026 16:34:27 -0300 Subject: [PATCH] Add BrDanfe::Helper.address ahead of NFC-e renderer removal facil123's ThermoPrinter still calls BrDanfe::DanfeLib::NfceLib::Helper.address directly, so the NFC-e Prawn renderer in this gem can't be deleted yet without breaking that caller. This adds the same method as BrDanfe::Helper.address (non-breaking, additive) so facil123 can migrate its two call sites on its own schedule. Once that migration lands, a follow-up PR removes the now-unused NFC-e renderer entirely, including the old NfceLib::Helper. Ref asseinfo/br_danfe#279 Co-Authored-By: Claude Sonnet 5 --- Gemfile.lock | 2 +- lib/br_danfe/helper.rb | 4 ++++ lib/br_danfe/version.rb | 2 +- spec/br_danfe/helper_spec.rb | 25 +++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d5a34f77..f152430a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - br_danfe (2.1.0) + br_danfe (2.2.0) barby (= 0.6.9) br_documents (>= 0.1.3) i18n (>= 0.8.6) diff --git a/lib/br_danfe/helper.rb b/lib/br_danfe/helper.rb index d49c3b5e..39cec03f 100644 --- a/lib/br_danfe/helper.rb +++ b/lib/br_danfe/helper.rb @@ -37,5 +37,9 @@ def self.nfe?(xml) def self.format_cep(cep) cep.sub(/(\d{2})(\d{3})(\d{3})/, '\\1.\\2-\\3') end + + def self.address(ender_tag) + "#{ender_tag.css('xLgr').text}, #{ender_tag.css('nro').text}, #{ender_tag.css('xBairro').text}, #{ender_tag.css('xMun').text} - #{ender_tag.css('UF').text}" + end end end diff --git a/lib/br_danfe/version.rb b/lib/br_danfe/version.rb index 55c9fa17..660d230a 100644 --- a/lib/br_danfe/version.rb +++ b/lib/br_danfe/version.rb @@ -1,3 +1,3 @@ module BrDanfe - VERSION = '2.1.0'.freeze + VERSION = '2.2.0'.freeze end diff --git a/spec/br_danfe/helper_spec.rb b/spec/br_danfe/helper_spec.rb index 44c60d3e..a9e08baa 100644 --- a/spec/br_danfe/helper_spec.rb +++ b/spec/br_danfe/helper_spec.rb @@ -225,4 +225,29 @@ expect(described_class.format_cep('12345678')).to eql '12.345-678' end end + + describe '.address' do + let(:xml) do + xml = <<~XML + + Rua Tijucas + 99 + dwdwa + Centro + 4218004 + TIJUCAS + SC + 88200000 + 1058 + Brasil + + XML + + BrDanfe::XML.new(xml) + end + + it 'returns a formated address string' do + expect(described_class.address(xml)).to eql 'Rua Tijucas, 99, Centro, TIJUCAS - SC' + end + end end