Class: UnovaFacturX::XmlGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/unova_factur_x/xml_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(document, type: :invoice, currency: "EUR", validate: true) ⇒ Nokogiri::XML::Document

Returns The generated XML document.

Parameters:

  • document (Hash)

    A hash representing an invoice or a credit note.

  • type (Symbol) (defaults to: :invoice)

    Document type: :invoice for a standard invoice, :credit for a credit note (:invoice by default).

  • currency (String) (defaults to: "EUR")

    ISO 4217 currency code.



8
9
10
11
12
13
# File 'lib/unova_factur_x/xml_generator.rb', line 8

def initialize(document, type: :invoice, currency: "EUR", validate: true)
  @document = document
  @type = type
  @currency = currency
  @validate = validate
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/unova_factur_x/xml_generator.rb', line 15

def call
  builder = ::Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
    xml['rsm'].CrossIndustryInvoice(
      'xmlns:rsm' => 'urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100',
      'xmlns:udt' => 'urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100',
      'xmlns:qdt' => 'urn:un:unece:uncefact:data:standard:QualifiedDataType:100',
      'xmlns:ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'
    ) do
      build_exchanged_document_context(xml)
      build_exchanged_document(xml)
      build_supply_chain_trade_transaction(xml)
    end
  end

  validate_with_xslt!(builder.doc) if @validate

  # Returns the XML document
  builder.doc
end