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

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

Overview

Nokogiri adapter for XSD schema generation Wraps Nokogiri::XML::Builder to provide schema building capabilities

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Nokogiri

Returns a new instance of Nokogiri.



14
15
16
17
18
19
20
21
22
# File 'lib/lutaml/xml/schema/builder/nokogiri.rb', line 14

def initialize(options = {}, &block)
  encoding = options[:encoding] || "UTF-8"
  @builder = if block
               ::Nokogiri::XML::Builder.new(encoding: encoding,
&block)
             else
               ::Nokogiri::XML::Builder.new(encoding: encoding)
             end
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



12
13
14
# File 'lib/lutaml/xml/schema/builder/nokogiri.rb', line 12

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

  • :indent (Integer)

    Number of spaces for indentation (default: 2)

Returns:

  • (String)

    XSD XML string



29
30
31
32
33
34
35
36
# File 'lib/lutaml/xml/schema/builder/nokogiri.rb', line 29

def to_xml(options = {})
  if options[:pretty]
    indent = options[:indent] || 2
    @builder.to_xml(indent: indent)
  else
    @builder.to_xml
  end
end