Class: ACube::Schema::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/acube/schema/document.rb

Constant Summary collapse

TRANSMISSION_FORMATS =
%w[FPR12 FPA12].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, body) ⇒ Document

Returns a new instance of Document.



9
10
11
12
# File 'lib/acube/schema/document.rb', line 9

def initialize(header, body)
  @header = header
  @body = body
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/acube/schema/document.rb', line 6

def body
  @body
end

#headerObject

Returns the value of attribute header.



6
7
8
# File 'lib/acube/schema/document.rb', line 6

def header
  @header
end

#progressiveObject

Returns the value of attribute progressive.



7
8
9
# File 'lib/acube/schema/document.rb', line 7

def progressive
  @progressive
end

#transmission_formatObject

Returns the value of attribute transmission_format.



7
8
9
# File 'lib/acube/schema/document.rb', line 7

def transmission_format
  @transmission_format
end

Instance Method Details

#fill_with(transmission_format:, progressive:) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/acube/schema/document.rb', line 14

def fill_with(transmission_format:, progressive:)
  @transmission_format = transmission_format
  @progressive = progressive

  header.transmission_format = transmission_format
  header.progressive = progressive
  body.set_progressive(progressive)
end

#to_xmlObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/acube/schema/document.rb', line 23

def to_xml
  Nokogiri::XML::Builder.new(encoding: 'UTF-8', namespace_inheritance:false) do |xml|
    xml["p"].FatturaElettronica(
      "versione" => header.transmission_format,
      "xmlns:ds" => "http://www.w3.org/2000/09/xmldsig#",
      "xmlns:p" => "http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2",
      "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
      "xsi:schemaLocation" => "http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd"
    ) do
      xml << header.to_xml
      xml << body.to_xml
    end
  end.to_xml
end