Sha256: 003ba2dd647ae530d26347764095a7dc42be583d6d0a678ef4e415956d3cc1df

Contents?: true

Size: 981 Bytes

Versions: 9

Compression:

Stored size: 981 Bytes

Contents

# frozen_string_literal: true

module BrInvoicesPdf
  module Nfce
    module Parser
      module Products
        extend Util::XmlLocate

        module_function

        FIELDS = { code: 'cProd',
                   description: 'xProd',
                   quantity: 'qCom',
                   unit_label: 'uCom',
                   unit_value: 'vUnCom',
                   total_value: 'vProd' }.freeze

        def execute(xml)
          node_products = xml.locate("#{root_path(xml)}/det")
          products_params(node_products) if node_products
        end

        def products_params(node_products)
          node_products.map(&method(:product_by))
        end
        private_class_method :products_params

        def product_by(element)
          FIELDS
            .map { |(key, field)| [key, node_locate(element, field).force_encoding('WINDOWS-1252').encode('UTF-8')] }
            .to_h
        end
        private_class_method :product_by
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
br_invoices_pdf-0.2.16 lib/br_invoices_pdf/nfce/parser/products.rb
br_invoices_pdf-0.2.15 lib/br_invoices_pdf/nfce/parser/products.rb
br_invoices_pdf-0.2.14 lib/br_invoices_pdf/nfce/parser/products.rb
br_invoices_pdf-0.2.14.alpha.23 lib/br_invoices_pdf/nfce/parser/products.rb
br_invoices_pdf-0.2.13 lib/br_invoices_pdf/nfce/parser/products.rb
br_invoices_pdf-0.2.13.alpha.22 lib/br_invoices_pdf/nfce/parser/products.rb
br_invoices_pdf-0.2.12.alpha.21 lib/br_invoices_pdf/nfce/parser/products.rb
br_invoices_pdf-0.2.12.alpha.20 lib/br_invoices_pdf/nfce/parser/products.rb
br_invoices_pdf-0.2.12 lib/br_invoices_pdf/nfce/parser/products.rb