Class: Facturae::FileHeaderBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/facturae/builders/file_header_builder.rb

Overview

Builds the XML representation of the file header.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_header) ⇒ FileHeaderBuilder

Returns a new instance of FileHeaderBuilder.



7
8
9
# File 'lib/facturae/builders/file_header_builder.rb', line 7

def initialize(file_header)
  @file_header = file_header
end

Instance Attribute Details

#file_headerFacturae::FileHeader (readonly)

The file header.

Returns:



6
7
8
# File 'lib/facturae/builders/file_header_builder.rb', line 6

def file_header
  @file_header
end

Instance Method Details

#build(xml, file_header = @file_header) ⇒ Object

rubocop:disable Metrics/AbcSize



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/facturae/builders/file_header_builder.rb', line 12

def build(xml, file_header = @file_header)
  # reason for passing file_header as an argument:
  # we need to copy the instance variable to a local one,
  # as the block will be executed in a different context
  # (blame instance_eval: https://github.com/sparklemotion/nokogiri/blob/main/lib/nokogiri/xml/builder.rb#L329)
  batch_hash = file_header.batch

  xml.FileHeader do
    xml.SchemaVersion(file_header.schema_version)
    xml.Modality(file_header.modality)
    xml.InvoiceIssuerType(file_header.invoice_issuer_type)
    xml.Batch do
      xml.BatchIdentifier(batch_hash[:series_invoice_number])
      xml.InvoicesCount(batch_hash[:invoices_count])
      xml.TotalInvoicesAmount do
        xml.TotalAmount(batch_hash[:total_invoice_amount])
      end
      xml.TotalOutstandingAmount do
        xml.TotalAmount(batch_hash[:total_tax_outputs])
      end
      xml.TotalExecutableAmount do
        xml.TotalAmount(batch_hash[:total_tax_inputs])
      end
      xml.InvoiceCurrencyCode(batch_hash[:invoice_currency_code])
    end
  end
  # rubocop:enable Metrics/AbcSize
end