Sha256: d5da3a69de115663316d1612d1c8387963274b20f0a2ab4909dd2a50a0fdf3a5

Contents?: true

Size: 893 Bytes

Versions: 6

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

module BrInvoicesPdf
  module Cfe
    module Parser
      module Payments
        extend Util::XmlLocate

        module_function

        def execute(xml)
          node_payments = xml.locate('infCFe/pgto')

          return unless node_payments

          payments_by_nodes(node_payments) if node_payments.any?
        end

        def payments_by_nodes(node_payments)
          node_payments.first.nodes
                       .select { |element| element.value == 'MP' }
                       .map { |element| payment_by(element) }
        end
        private_class_method :payments_by_nodes

        def payment_by(element)
          {
            type: Util::Enum::PAYMENT_TYPES[locate_element(element, 'cMP')],
            amount: locate_element(element, 'vMP')
          }
        end
        private_class_method :payment_by
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
br_invoices_pdf-0.2.24 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.23 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.22 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.21 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.20 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.19 lib/br_invoices_pdf/cfe/parser/payments.rb