Class: Lutaml::Model::Schema::SchemaBuilder::Oga

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/schema/schema_builder/oga.rb

Overview

Oga adapter for XSD schema generation Wraps Oga XML building to provide schema building capabilities

Defined Under Namespace

Classes: OgaBuilderWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|@builder| ... } ⇒ Oga

Returns a new instance of Oga.

Yields:



14
15
16
17
18
19
20
21
# File 'lib/lutaml/model/schema/schema_builder/oga.rb', line 14

def initialize(options = {})
  @encoding = options[:encoding] || "UTF-8"
  @document = ::Oga::XML::Document.new
  @builder = OgaBuilderWrapper.new(@document, @encoding)

  # Execute the block if provided
  yield(@builder) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object

Forward all other methods to the builder wrapper



34
35
36
# File 'lib/lutaml/model/schema/schema_builder/oga.rb', line 34

def method_missing(method_name, ...)
  @builder.public_send(method_name, ...)
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



12
13
14
# File 'lib/lutaml/model/schema/schema_builder/oga.rb', line 12

def builder
  @builder
end

#documentObject (readonly)

Returns the value of attribute document.



12
13
14
# File 'lib/lutaml/model/schema/schema_builder/oga.rb', line 12

def document
  @document
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/lutaml/model/schema/schema_builder/oga.rb', line 38

def respond_to_missing?(method_name, include_private = false)
  @builder.respond_to?(method_name, include_private) || super
end

#to_xml(_options = {}) ⇒ String

Generate the XSD schema XML string

Parameters:

  • options (Hash)

    formatting options

Returns:

  • (String)

    XSD XML string



27
28
29
30
31
# File 'lib/lutaml/model/schema/schema_builder/oga.rb', line 27

def to_xml(_options = {})
  xml = @document.to_xml
  # Add XML declaration with encoding
  "<?xml version=\"1.0\" encoding=\"#{@encoding}\"?>\n#{xml}"
end