Class: Nokogiri::XML::Schematron::Pattern

Inherits:
Base
  • Object
show all
Defined in:
lib/nokogiri/xml/schematron/pattern.rb

Overview

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

For example:

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

Instance Attribute Summary collapse

Attributes inherited from Base

#children, #options, #parent

Instance Method Summary collapse

Methods inherited from Base

attribute, element, #initialize, #to_builder

Constructor Details

This class inherits a constructor from Nokogiri::XML::Schematron::Base

Instance Attribute Details

#idString

Returns the value of the @id XML attribute.

Returns:

  • (String)

    the value of the @id XML attribute.



21
# File 'lib/nokogiri/xml/schematron/pattern.rb', line 21

attribute :id

#titleString

Returns the value of the @title XML element.

Returns:

  • (String)

    the value of the @title XML element.



25
# File 'lib/nokogiri/xml/schematron/pattern.rb', line 25

attribute :title

Instance Method Details

#context(context, **options) {|node| ... } ⇒ Nokogiri::XML::Schematron::Node::Context

Create a new Node::Context object.

Examples:

Denest an abstract syntax tree into a sequence of zero or more <sch:rule> XML elements.

# For example, the following...
context("/") do
  require("ex:A") do
    permit("ex:B") do
      reject("ex:C")
    end
  end
end

# ...is equivalent to:
rule(context: "/") do
  assert(test: "count(ex:A) &gt;= 1", message: "element \"ex:A\" is REQUIRED")
end
rule(context: "/ex:A") do
  assert(test: "count(ex:B) &gt;= 0", message: "element \"ex:B\" is OPTIONAL")
end
rule(context: "/ex:A/ex:B") do
  assert(test: "not(ex:C)", message: "element \"ex:C\" is NOT RECOMMENDED")
end

Create business rules for the XML representation of a set of values.

context("/") do
  require("ex:Example") do
    permit("ex:ExampleType") do
      validates_inclusion_of "text()", in: ["A", "B", "C"]
    end
  end
end

Create business rules for the XML representation of a set of values that is augmented with an “Other” value.

context("/") do
  require("ex:Example") do
    permit("ex:ExampleType") do
      validates_inclusion_of "text()", in: ["A", "B", "C", "Other"]
    end
  end
  permit("ex:Example[ex:ExampleType and (ex:ExampleType/text() != 'Other')]") do
    reject("ex:OtherExampleType")
  end
  permit("ex:Example[ex:ExampleType and (ex:ExampleType/text() = 'Other')]") do
    require("ex:OtherExampleType")
  end
  permit("ex:Example[ex:OtherExampleType]") do
    require("ex:ExampleType") do
      validates_inclusion_of "text()", in: ["Other"]
    end
  end
end

Create business rules for the XML representation of a set of zero or more key-value pairs.

context("/") do
  require("ex:KeyValuePairs") do
    permit("ex:KeyValuePair") do
      require("ex:Key") do
        validates_inclusion_of "text()", in: ["A", "B", "C"]
      end
      require("ex:Value")
    end
    permit("ex:KeyValuePair[ex:Key/text() = 'A']/ex:Value") do
      validates_inclusion_of "text()", in: ["a"]
    end
    permit("ex:KeyValuePair[ex:Key/text() = 'B']/ex:Value") do
      validates_inclusion_of "text()", in: ["b"]
    end
    permit("ex:KeyValuePair[ex:Key/text() = 'C']/ex:Value") do
      validates_inclusion_of "text()", in: ["c"]
    end
  end
end

Create business rules for an entity-relationship model.

context("//ex:UserAccount") do
  require("@ID") do
    validates_numericality_of "text()", greater_than_or_equal_to: 1
  end
  permit("ex:Username") do
    validates_exclusion_of "text()", in: ["admin"]
  end
  reject("ex:Password")
end

Parameters:

  • context (String)

    the XPath.

  • options (Hash<Symbol, Object>)

    the options.

Yield Parameters:

  • node (Nokogiri::XML::Schematron::Node::Context)

    the Node::Context object.

Yield Returns:

  • (void)

Returns:

  • (Nokogiri::XML::Schematron::Node::Context)

    the Node::Context object.



111
# File 'lib/nokogiri/xml/schematron/pattern.rb', line 111

element :context, Nokogiri::XML::Schematron::Nodes::Context

#p(**options) {|p| ... } ⇒ Nokogiri::XML::Schematron::Paragraph

Create a new Paragraph object.

Parameters:

  • options (Hash<Symbol, Object>)

    the options.

Options Hash (**options):

  • :message (String)

    the text content of the <sch:p> XML element.

Yield Parameters:

Yield Returns:

  • (void)

Returns:



120
# File 'lib/nokogiri/xml/schematron/pattern.rb', line 120

element :p, Nokogiri::XML::Schematron::Paragraph

#rule(**options) {|rule| ... } ⇒ Nokogiri::XML::Schematron::Rule

Create a new Rule object.

Parameters:

  • options (Hash<Symbol, Object>)

    the options.

Options Hash (**options):

  • :context (String)

    the value of the @context XML attribute.

  • :id (String)

    the value of the @id XML attribute.

Yield Parameters:

Yield Returns:

  • (void)

Returns:



130
# File 'lib/nokogiri/xml/schematron/pattern.rb', line 130

element :rule, Nokogiri::XML::Schematron::Rule