class Nokogiri::XML::Schematron::Schema

The internal representation of the +<sch:schema>+ XML element.

For example:

schema = Nokogiri::XML::Schematron::Schema.new(id: "schema1", title: "Example schema")
# => #<Nokogiri::XML::Schematron::Schema:0x00007fa1fb9e3b68 @parent=nil, @children=[], @options={:id=>"schema1", :title=>"Example schema"}>
schema.to_builder.to_xml
# => "<?xml version=\"1.0\"?>\n<sch:schema xmlns:sch=\"http://purl.oclc.org/dsdl/schematron\" id=\"schema1\">\n  <sch:title>Example schema</sch:title>\n</sch:schema>\n"

Public Class Methods

new(**options, &block) click to toggle source

Create a new Schema object.

@param options [Hash<Symbol, Object>] the options. @option options [#to_s] :id the value of the +@id+ XML attribute. @option options [#to_s] :title the value of the +@title+ XML element. @yieldparam schema [Nokogiri::XML::Schematron::Schema] the internal representation of the +<sch:schema>+ XML element. @yieldreturn [void]

Calls superclass method Nokogiri::XML::Schematron::Base::new
# File lib/nokogiri/xml/schematron/schema.rb, line 63
def initialize(**options, &block)
  super(nil, **options, &block)
end

Protected Instance Methods

build!(xml) click to toggle source
Calls superclass method Nokogiri::XML::Schematron::Base#build!
# File lib/nokogiri/xml/schematron/schema.rb, line 69
def build!(xml)
  xml["sch"].send(:schema, %w(id).inject(xmlns) { |acc, method_name|
    unless (s = send(method_name.to_sym)).nil?
      acc[method_name.to_s] = s
    end

    acc
  }) do
    %w(title).each do |method_name|
      unless (s = send(method_name.to_sym)).nil?
        xml["sch"].send(method_name.to_sym, xmlns) do
          xml.text(s)
        end
      end
    end

    super(xml)
  end

  return
end