Class: Duxml::ChildrenRuleClass

Inherits:
RuleClass show all
Includes:
ChildrenRule, RngChildrenRule
Defined in:
lib/duxml/meta/grammar/rule/children_rule.rb,
lib/duxml/meta/grammar/relax_ng/children_rule.rb

Overview

do not subclass! rule that states what children and how many a given element is allowed to have where @statement is a DTD/Regexp of what children are allowed, how many, in what order and whether they are required

Instance Attribute Summary

Attributes inherited from RuleClass

#object, #statement

Attributes included from Reportable

#observer_peers

Attributes inherited from PatternClass

#subject

Attributes included from Duxml

#doc

Attributes included from Saxer

#io

Instance Method Summary collapse

Methods included from RngChildrenRule

#relaxng

Methods included from LazyOx

#method_missing

Methods included from ChildrenRule

#applies_to?, #qualify, #required_children

Methods included from Rule

#applies_to?, #description, #history, #qualify

Methods included from Reportable

#add_observer

Methods included from Pattern

#<=>, #abstract?, #concrete?, #description, #name, #object, #relationship, #simple_name, #xml

Methods included from Duxml

#load, #log, #save, #validate

Methods included from Saxer

#sax

Constructor Details

#initialize(_subject, _statement) ⇒ ChildrenRuleClass

child rules are initialized from DTD doc declarations e.g. (zeroOrMore|other-first-child)*,second-child-optional?,third-child-gt1+

Parameters:

  • _subject (String)

    name of the doc the rule applies

  • _statement (String)

    DTD-style statement of the rule



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/duxml/meta/grammar/rule/children_rule.rb', line 18

def initialize(_subject, _statement)
  formatted_statement = _statement
                            .gsub(/[\<>]/, '')
                            .gsub(/#PCDATA/, 'PCDATA')
                            .gsub('-','_dash_')
                            .gsub(/\b/,'\b')
                            .gsub(/PCDATA/, '#PCDATA')
                            .gsub('_dash_', '-')
                            .gsub(/\s/,'')
  super(_subject, formatted_statement)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Duxml::LazyOx