Sha256: 889e5ee3fed8f16f358bc0a41a7860c8620506b422571fbfe23294c4bc0b5c71

Contents?: true

Size: 1.62 KB

Versions: 12

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: 7, 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

12 entries across 12 versions & 1 rubygems

Version Path
br_danfe-0.16.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.15.1 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.15.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.14.5 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.14.4 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.14.3 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.14.2 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.14.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.13.3 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.13.2 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.13.1 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb
br_danfe-0.13.0 lib/br_danfe/danfe_lib/nfce_lib/recipient.rb