Sha256: 53aa849bdcc5316d30f744269497121962a7261a5f032e69074e459e2ff8bc39

Contents?: true

Size: 1.62 KB

Versions: 17

Compression:

Stored size: 1.62 KB

Contents

module BrDanfe
  module DanfeLib
    module NfceLib
      class Recipient
        def initialize(pdf, xml)
          @pdf = pdf
          @xml = xml
        end

        def render
          @pdf.render_blank_line

          if identified_recipient?
            render_document

            @pdf.text @xml['dest/xNome'], options
            @pdf.text BrDanfe::DanfeLib::NfceLib::Helper.address(@xml.css('enderDest')), options
          else
            @pdf.text 'CONSUMIDOR NÃO IDENTIFICADO', options
          end
        end

        private

        def options
          { size: 9, align: :center }
        end

        def identified_recipient?
          @xml['dest/xNome'].present?
        end

        def render_document
          document_text = document

          @pdf.text document_text, options if document_text.present?
        end

        def document
          return company if company?
          return individual if individual?
          return foreign if foreign?

          ''
        end

        def company?
          @xml['dest/CNPJ'].present?
        end

        def company
          cnpj = BrDocuments::CnpjCpf::Cnpj.new @xml['dest/CNPJ']
          "CONSUMIDOR CNPJ: #{cnpj.formatted}"
        end

        def individual?
          @xml['dest/CPF'].present?
        end

        def individual
          cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
          "CONSUMIDOR CPF: #{cpf.formatted}"
        end

        def foreign?
          @xml['dest/idEstrangeiro'].present?
        end

        def foreign
          "CONSUMIDOR Id. Estrangeiro: #{@xml['dest/idEstrangeiro']}"
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
br_danfe-1.2.2 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-1.2.1 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-1.2.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-1.1.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-1.0.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.20.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.19.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.18.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.8 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.7 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.6 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.5 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.4 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.3 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.2 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.1 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.17.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb