Sha256: 4931550bb6143d720fb0513e810824e73127ba46340670a58cc371bb440abb83

Contents?: true

Size: 968 Bytes

Versions: 2

Compression:

Stored size: 968 Bytes

Contents

# frozen_string_literal: true

module BrInvoicesPdf
  module Nfce
    module Parser
      module Customer
        extend Util::XmlLocate
        extend Util::MountParams

        module_function

        DEST_ROOT_PATH = "#{Util::XmlLocate::ROOT_PATH}/dest"

        def execute(xml)
          identification_type = identification_type_by(xml)
          {
            identification_type: identification_type,
            identification: locate_element(xml, "#{DEST_ROOT_PATH}/#{identification_type}"),
            address: mount(xml, address_params(DEST_ROOT_PATH, 'Dest'))
          }
        end

        def identification_type_by(xml)
          return 'CNPJ' if locate_element(xml, "#{DEST_ROOT_PATH}/CNPJ")
          return 'CPF' if locate_element(xml, "#{DEST_ROOT_PATH}/CPF")
          return 'idEstrangeiro' if locate_element(xml, "#{DEST_ROOT_PATH}/idEstrangeiro")
        end
        private_class_method :identification_type_by
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
br_invoices_pdf-0.2.7 lib/br_invoices_pdf/nfce/parser/customer.rb
br_invoices_pdf-0.2.6.alpha.19 lib/br_invoices_pdf/nfce/parser/customer.rb