module BrInvoicesPdf::Nfce::Parser::Products

Constants

FIELDS

Public Instance Methods

execute(xml) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/products.rb, line 18
def execute(xml)
  node_products = xml.locate("#{root_path(xml)}/det")
  products_params(node_products) if node_products
end
product_by(element) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/products.rb, line 28
def product_by(element)
  FIELDS.map do |(key, field)|
    [key, node_locate(element, field).encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
                                     .force_encoding('WINDOWS-1252').encode('UTF-8')]
  end.to_h
end
products_params(node_products) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/products.rb, line 23
def products_params(node_products)
  node_products.map(&method(:product_by))
end