Sha256: 27dd35f709ce3a2910bea89059cebf7ca875e1b71ab7a6232cec1218dee523c0

Contents?: true

Size: 1.02 KB

Versions: 14

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

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

        module_function

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

        def execute(xml)
          node_products = xml.locate('infCFe/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

14 entries across 14 versions & 1 rubygems

Version Path
br_invoices_pdf-0.2.21 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.20 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.19 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.18 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.17 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.16 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.15 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.14 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.14.alpha.23 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.13 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.13.alpha.22 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.12.alpha.21 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.12.alpha.20 lib/br_invoices_pdf/cfe/parser/products_data.rb
br_invoices_pdf-0.2.12 lib/br_invoices_pdf/cfe/parser/products_data.rb