Class: Lutaml::Xml::Schema::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/schema/builder.rb,
lib/lutaml/xml/schema/builder/oga.rb,
lib/lutaml/xml/schema/builder/nokogiri.rb

Overview

SchemaBuilder provides an adapter-agnostic interface for XSD schema generation It wraps XML builders (Nokogiri, Oga) to generate XSD documents

NOTE: Schema generation is separate from XML parsing. While the XML parsing adapters (Nokogiri, Oga, Ox, REXML) handle reading/writing XML documents, schema generation requires an XML builder API which is only implemented for Nokogiri and Oga. When the configured XML adapter is Ox or REXML, we use Nokogiri for schema generation since it has the most complete builder API.

Defined Under Namespace

Classes: Nokogiri, Oga

Constant Summary collapse

SUPPORTED_BUILDERS =

Supported schema builders (separate from XML parsing adapters)

%i[nokogiri oga].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter_type: nil, options: {}) ⇒ Builder

Returns a new instance of Builder.



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

def initialize(adapter_type: nil, options: {}, &)
  # Use specified adapter, or configured XML adapter, or default to Nokogiri
  requested_adapter = adapter_type || Lutaml::Model::Config.xml_adapter_type || :nokogiri

  # Schema generation requires a builder API which only Nokogiri and Oga provide
  # Ox and REXML are valid XML parsing adapters but don't have schema builder implementations
  @adapter_type = if SUPPORTED_BUILDERS.include?(requested_adapter)
                    requested_adapter
                  else
                    :nokogiri
                  end
  @options = options
  @builder = create_builder(&)
end

Instance Attribute Details

#adapter_typeObject (readonly)

Returns the value of attribute adapter_type.



18
19
20
# File 'lib/lutaml/xml/schema/builder.rb', line 18

def adapter_type
  @adapter_type
end

#builderObject (readonly)

Returns the value of attribute builder.



18
19
20
# File 'lib/lutaml/xml/schema/builder.rb', line 18

def builder
  @builder
end

Instance Method Details

#to_xml(options = {}) ⇒ String

Generate the XSD schema XML string

Parameters:

  • options (Hash) (defaults to: {})

    formatting options

Options Hash (options):

  • :pretty (Boolean)

    Pretty print with indentation

Returns:

  • (String)

    XSD XML string



42
43
44
# File 'lib/lutaml/xml/schema/builder.rb', line 42

def to_xml(options = {})
  @builder.to_xml(options)
end