Module: BrInvoicesPdf::Nfce::Parser::Payments

Extended by:
Util::XmlLocate
Defined in:
lib/br_invoices_pdf/nfce/parser/payments.rb

Class Method Summary collapse

Methods included from Util::XmlLocate

locate_element, node_locate, root_path

Class Method Details

.cashback_for(xml) ⇒ Object



33
34
35
# File 'lib/br_invoices_pdf/nfce/parser/payments.rb', line 33

def cashback_for(xml)
  locate_element(xml.locate("#{root_path(xml)}/pag")[0], 'vTroco')
end

.execute(xml) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/br_invoices_pdf/nfce/parser/payments.rb', line 11

def execute(xml)
  xml_version = xml.locate(root_path(xml).to_s)

  return payments_new_version(xml) if xml_version.any? && xml_version[0].attributes[:versao][0] == '4'

  payments_old_version(xml)
end

.payments_new_version(xml) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/br_invoices_pdf/nfce/parser/payments.rb', line 24

def payments_new_version(xml)
  node_payments = xml.locate("#{root_path(xml)}/pag/detPag")
  cashback = cashback_for(xml)

  node_payments.map do |payment|
    payment_by(payment, cashback: cashback)
  end
end

.payments_old_version(xml) ⇒ Object



19
20
21
22
# File 'lib/br_invoices_pdf/nfce/parser/payments.rb', line 19

def payments_old_version(xml)
  node_payments = xml.locate("#{root_path(xml)}/pag")
  node_payments.map(&method(:payment_by))
end