Class: SDL::Exporters::XMLServiceExporter

Inherits:
ServiceExporter show all
Defined in:
lib/sdl/exporters/xml_service_exporter.rb

Instance Attribute Summary

Attributes inherited from Exporter

#options

Instance Method Summary collapse

Methods inherited from ServiceExporter

#export_service_to_file

Methods inherited from Exporter

#export_to_file, #initialize

Constructor Details

This class inherits a constructor from SDL::Exporters::Exporter

Instance Method Details

#build_service(service, xml) ⇒ Object



10
11
12
13
14
# File 'lib/sdl/exporters/xml_service_exporter.rb', line 10

def build_service(service, xml)
  xml.service('xmlns' => 'http://www.open-service-compendium.org', 'uri' => service.uri) do
    serialize_type_instance service, xml
  end
end

#export_service(service) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/sdl/exporters/xml_service_exporter.rb', line 2

def export_service(service)
  builder = Nokogiri::XML::Builder.new do |xml|
    build_service(service, xml)
  end

  builder.to_xml
end

#serialize_type_instance(type_instance, xml) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sdl/exporters/xml_service_exporter.rb', line 16

def serialize_type_instance(type_instance, xml)
  type_instance.property_values.each do |property, value|
    [value].flatten.each do |v|
      xml.send(property.xsd_element_name + '_', v.xml_attributes) do
        if v.class < SDL::Base::Type
          serialize_type_instance(v, xml)
        else
          xml.text v.xml_value
        end
      end
    end
  end
end