Module: Ksef::FA3::RowReader

Extended by:
NodeReader
Defined in:
lib/ksef/fa3/row_reader.rb

Overview

Reads the FaWiersz rows of an invoice into Line objects.

Split out of Parser because a row is where FA(3)'s optionality is at its most aggressive: every child of FaWiersz except NrWierszaFa is minOccurs="0", so most of what this does is decide which absences the model can absorb and which it cannot.

Constant Summary

Constants included from NodeReader

NodeReader::NAMESPACES, NodeReader::PREFIX

Class Method Summary collapse

Class Method Details

.lines_from(fa_node, required: true) ⇒ Object

The row number is read as stated; Invoice.positioned is what reduces it to nil when it merely repeats the position. One place decides, and it is the one that knows what a line's position is.

Parameters:

  • fa_node (Nokogiri::XML::Node) —

    the Fa element

  • required (Boolean) (defaults to: true) —

    whether an invoice with no rows is an error. False for a correction that states its own totals: FaWiersz is minOccurs="0" and the Ministry's own collective corrections carry none (docs/REFERENCE.md §8.4).

Raises:



22
23
24
25
26
27
# File 'lib/ksef/fa3/row_reader.rb', line 22

def lines_from(fa_node, required: true)
  rows = elements(fa_node, "FaWiersz")
  raise ValidationError, "Invoice has no FaWiersz rows" if rows.empty? && required

  rows.map { |row| line_from(row) }
end