Module: Duxml::PatternMaker
Overview
helper methods to create Patterns from a given Element’s relationships with its members
Constant Summary
Constants included from Duxml
Constants included from Meta
Instance Attribute Summary
Attributes included from Duxml
Attributes included from Saxer
Instance Method Summary collapse
-
#get_child_patterns(node) ⇒ Array[Duxml::ChildPattern, Duxml::ContentPattern]
One pattern for each child that exists.
-
#get_existing_attr_patterns(node) ⇒ Array[Duxml::AttrNamePattern, Duxml::AttrValPattern]
One pattern for each existing attribute.
-
#get_null_attr_patterns(node) ⇒ Array[AttrNamePattern]
One pattern for each attribute that should but does not exist.
-
#get_null_child_patterns(node) ⇒ Array[ChildPattern]
One pattern for each child that should be there but isn’t.
-
#get_relationships(node) ⇒ Array[Duxml::Pattern]
Array of patterns representing every relationship of this XMl node and its members.
Methods included from Duxml
#create, #load, #log, #relaxng, #save, #validate
Methods included from Meta
Methods included from Saxer
Instance Method Details
#get_child_patterns(node) ⇒ Array[Duxml::ChildPattern, Duxml::ContentPattern]
Returns one pattern for each child that exists.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/duxml/meta/grammar/pattern_maker.rb', line 57 def get_child_patterns(node) i = -1 node.nodes.collect do |child| i += 1 if child.is_a?(String) TextPatternClass.new(node, i) else ChildPatternClass.new(node, i) end end end |
#get_existing_attr_patterns(node) ⇒ Array[Duxml::AttrNamePattern, Duxml::AttrValPattern]
Returns one pattern for each existing attribute.
23 24 25 26 27 28 |
# File 'lib/duxml/meta/grammar/pattern_maker.rb', line 23 def get_existing_attr_patterns(node) # check existing attributes node.attributes.collect do |k, v| [AttrNamePatternClass.new(node, k), AttrValPatternClass.new(node, k)] end.flatten end |
#get_null_attr_patterns(node) ⇒ Array[AttrNamePattern]
Returns one pattern for each attribute that should but does not exist.
32 33 34 35 36 37 38 |
# File 'lib/duxml/meta/grammar/pattern_maker.rb', line 32 def get_null_attr_patterns(node) self.AttrsRuleClass.collect do |attr_rule| if attr_rule.required? && node.name == attr_rule.subject AttrNamePatternClass.new(node, attr_rule.attr_name) unless node[attr_rule.attr_name] end end.compact end |
#get_null_child_patterns(node) ⇒ Array[ChildPattern]
Returns one pattern for each child that should be there but isn’t.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/duxml/meta/grammar/pattern_maker.rb', line 42 def get_null_child_patterns(node) self.ChildrenRuleClass.each do |child_rule| if node.name == child_rule.subject return child_rule.required_children.collect do |required_child_type| unless node.nodes.any? do |n| n.name == required_child_type end NullChildPatternClass.new(node, required_child_type) end end.compact end end [] end |
#get_relationships(node) ⇒ Array[Duxml::Pattern]
Returns array of patterns representing every relationship of this XMl node and its members.
14 15 16 17 18 19 |
# File 'lib/duxml/meta/grammar/pattern_maker.rb', line 14 def get_relationships(node) [get_child_patterns(node), get_null_child_patterns(node), get_existing_attr_patterns(node), get_null_attr_patterns(node)].flatten end |