Sha256: dedaeeee0d348ce454158e35261f6e0aa8e92ace2757a612307b9b0ed96b851c

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

module BrDanfe
  module DanfeNfceLib
    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::DanfeNfceLib::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?
        return ''
      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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
br_danfe-0.12.1 lib/br_danfe/danfe_nfce_lib/recipient.rb
br_danfe-0.12.0 lib/br_danfe/danfe_nfce_lib/recipient.rb