duxml 0.8.8 → 0.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/bin/validate_xml +30 -30
  3. data/lib/duxml.rb +76 -76
  4. data/lib/duxml/doc.rb +108 -91
  5. data/lib/duxml/doc/element.rb +250 -250
  6. data/lib/duxml/doc/lazy_ox.rb +167 -167
  7. data/lib/duxml/doc/node_set.rb +38 -38
  8. data/lib/duxml/meta.rb +72 -72
  9. data/lib/duxml/meta/grammar.rb +133 -133
  10. data/lib/duxml/meta/grammar/pattern.rb +111 -111
  11. data/lib/duxml/meta/grammar/pattern/attr_name_pattern.rb +36 -36
  12. data/lib/duxml/meta/grammar/pattern/attr_val_pattern.rb +36 -36
  13. data/lib/duxml/meta/grammar/pattern/child_pattern.rb +60 -60
  14. data/lib/duxml/meta/grammar/pattern/text_pattern.rb +31 -31
  15. data/lib/duxml/meta/grammar/pattern_maker.rb +68 -68
  16. data/lib/duxml/meta/grammar/relax_ng.rb +39 -39
  17. data/lib/duxml/meta/grammar/relax_ng/attrs_rule.rb +58 -58
  18. data/lib/duxml/meta/grammar/relax_ng/children_rule.rb +82 -82
  19. data/lib/duxml/meta/grammar/relax_ng/value_rule.rb +44 -44
  20. data/lib/duxml/meta/grammar/rule.rb +58 -58
  21. data/lib/duxml/meta/grammar/rule/attrs_rule.rb +77 -77
  22. data/lib/duxml/meta/grammar/rule/children_rule.rb +135 -135
  23. data/lib/duxml/meta/grammar/rule/text_rule.rb +39 -39
  24. data/lib/duxml/meta/grammar/rule/value_rule.rb +110 -110
  25. data/lib/duxml/meta/grammar/spreadsheet.rb +34 -34
  26. data/lib/duxml/meta/history.rb +88 -88
  27. data/lib/duxml/meta/history/add.rb +30 -30
  28. data/lib/duxml/meta/history/change.rb +70 -70
  29. data/lib/duxml/meta/history/change_attr.rb +33 -33
  30. data/lib/duxml/meta/history/change_text.rb +32 -32
  31. data/lib/duxml/meta/history/error.rb +24 -24
  32. data/lib/duxml/meta/history/new_attr.rb +32 -32
  33. data/lib/duxml/meta/history/new_text.rb +36 -36
  34. data/lib/duxml/meta/history/qualify_error.rb +21 -21
  35. data/lib/duxml/meta/history/remove.rb +27 -27
  36. data/lib/duxml/meta/history/undo.rb +23 -23
  37. data/lib/duxml/meta/history/validate_error.rb +20 -20
  38. data/lib/duxml/reportable.rb +28 -28
  39. data/lib/duxml/ruby_ext/fixnum.rb +55 -55
  40. data/lib/duxml/ruby_ext/module.rb +11 -11
  41. data/lib/duxml/ruby_ext/object.rb +13 -13
  42. data/lib/duxml/ruby_ext/regexp.rb +19 -19
  43. data/lib/duxml/ruby_ext/string.rb +37 -37
  44. data/lib/duxml/saxer.rb +75 -75
  45. metadata +12 -12
@@ -1,36 +1,36 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../grammar/pattern')
4
-
5
- module Duxml
6
- module AttrNamePattern; end
7
- # pattern representing relationship between an object and one of its attributes
8
- class AttrNamePatternClass < PatternClass
9
- include AttrNamePattern
10
-
11
- # @param _subject [Duxml::Element] subject doc
12
- # @param _attr_name [String] name of attribute
13
- def initialize(_subject, _attr_name)
14
- @attr_name = _attr_name
15
- super _subject
16
- end
17
-
18
- attr_reader :attr_name
19
- end
20
-
21
- module AttrNamePattern
22
- def relationship
23
- 'attribute'
24
- end
25
-
26
- # @return [Boolean] true if subject does not have the attr_name; false otherwise
27
- def abstract?
28
- subject[attr_name].nil?
29
- end
30
-
31
- def description
32
- abstract? ? "#{subject.description} does not have #{relationship} [#{attr_name}]" :
33
- "#{subject.description}'s #{relationship} [#{attr_name}]"
34
- end
35
- end # class AttrNamePattern
36
- end # module Duxml
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../grammar/pattern')
4
+
5
+ module Duxml
6
+ module AttrNamePattern; end
7
+ # pattern representing relationship between an object and one of its attributes
8
+ class AttrNamePatternClass < PatternClass
9
+ include AttrNamePattern
10
+
11
+ # @param _subject [Duxml::Element] subject doc
12
+ # @param _attr_name [String] name of attribute
13
+ def initialize(_subject, _attr_name)
14
+ @attr_name = _attr_name
15
+ super _subject
16
+ end
17
+
18
+ attr_reader :attr_name
19
+ end
20
+
21
+ module AttrNamePattern
22
+ def relationship
23
+ 'attribute'
24
+ end
25
+
26
+ # @return [Boolean] true if subject does not have the attr_name; false otherwise
27
+ def abstract?
28
+ subject[attr_name].nil?
29
+ end
30
+
31
+ def description
32
+ abstract? ? "#{subject.description} does not have #{relationship} [#{attr_name}]" :
33
+ "#{subject.description}'s #{relationship} [#{attr_name}]"
34
+ end
35
+ end # class AttrNamePattern
36
+ end # module Duxml
@@ -1,36 +1,36 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../grammar/pattern')
4
-
5
- module Duxml
6
- module AttrValPattern; end
7
-
8
- # pattern representing relationship between an object's attribute and its value
9
- class AttrValPatternClass < PatternClass
10
- include AttrValPattern
11
-
12
- # @param _subject [Element] subject element
13
- # @param _attr_name [String] name of attribute whose value is the object of this pattern
14
- def initialize(_subject, _attr_name)
15
- @attr_name = _attr_name
16
- super _subject
17
- end
18
-
19
- attr_reader :subject, :attr_name
20
- end
21
-
22
- module AttrValPattern
23
- def relationship
24
- 'value'
25
- end
26
-
27
- def description
28
- "#{subject.description}'s @#{attr_name} #{relationship} of '#{value}'"
29
- end
30
-
31
- # current value of this attribute
32
- def value
33
- subject[attr_name]
34
- end
35
- end # class AttrValPattern
36
- end # module Duxml
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../grammar/pattern')
4
+
5
+ module Duxml
6
+ module AttrValPattern; end
7
+
8
+ # pattern representing relationship between an object's attribute and its value
9
+ class AttrValPatternClass < PatternClass
10
+ include AttrValPattern
11
+
12
+ # @param _subject [Element] subject element
13
+ # @param _attr_name [String] name of attribute whose value is the object of this pattern
14
+ def initialize(_subject, _attr_name)
15
+ @attr_name = _attr_name
16
+ super _subject
17
+ end
18
+
19
+ attr_reader :subject, :attr_name
20
+ end
21
+
22
+ module AttrValPattern
23
+ def relationship
24
+ 'value'
25
+ end
26
+
27
+ def description
28
+ "#{subject.description}'s @#{attr_name} #{relationship} of '#{value}'"
29
+ end
30
+
31
+ # current value of this attribute
32
+ def value
33
+ subject[attr_name]
34
+ end
35
+ end # class AttrValPattern
36
+ end # module Duxml
@@ -1,60 +1,60 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../grammar/pattern')
4
- require File.expand_path(File.dirname(__FILE__) + '/../../../ruby_ext/fixnum')
5
-
6
- module Duxml
7
- module ChildPattern; end
8
- # pattern representing relationship between an object and its child
9
- class ChildPatternClass < PatternClass
10
- include ChildPattern
11
-
12
- # @param _subject [Duxml::Element] parent element
13
- # @param _child [Fixnum] child node
14
- def initialize(_subject, _child, _index)
15
- @child, @index = _child, _index
16
- super _subject
17
- end
18
-
19
- alias_method :parent, :subject
20
- attr_reader :child, :index
21
- end # class ChildPatternClass
22
-
23
- # null child patterns represent and parent child relationship where the child
24
- # is required by the Grammar but the element is missing that child
25
- class NullChildPatternClass < PatternClass
26
- include ChildPattern
27
-
28
- # @param _subject [Element] parent element
29
- # @param _missing_child [String] nmtoken for missing child element
30
- def initialize(_subject, _missing_child, _index=-1)
31
- @missing_child, @index = _missing_child, _index
32
- super _subject
33
- end
34
-
35
- def relationship
36
- 'missing child'
37
- end
38
-
39
- # @return [String] description of this child pattern
40
- def description
41
- "#{subject.description} #{relationship} <#{child}>"
42
- end
43
-
44
- attr_reader :missing_child, :index
45
- alias_method :child, :missing_child
46
- alias_method :parent, :subject
47
- end
48
-
49
- module ChildPattern
50
- # @return [String] describes relationship between parent and child
51
- def relationship
52
- "#{(index+1).ordinal_name} #{super}"
53
- end
54
-
55
- # @return [String] description of this child pattern
56
- def description
57
- "#{subject.description}'s #{relationship} #{child.description}"
58
- end
59
- end
60
- end # module Duxml
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../grammar/pattern')
4
+ require File.expand_path(File.dirname(__FILE__) + '/../../../ruby_ext/fixnum')
5
+
6
+ module Duxml
7
+ module ChildPattern; end
8
+ # pattern representing relationship between an object and its child
9
+ class ChildPatternClass < PatternClass
10
+ include ChildPattern
11
+
12
+ # @param _subject [Duxml::Element] parent element
13
+ # @param _child [Fixnum] child node
14
+ def initialize(_subject, _child, _index)
15
+ @child, @index = _child, _index
16
+ super _subject
17
+ end
18
+
19
+ alias_method :parent, :subject
20
+ attr_reader :child, :index
21
+ end # class ChildPatternClass
22
+
23
+ # null child patterns represent and parent child relationship where the child
24
+ # is required by the Grammar but the element is missing that child
25
+ class NullChildPatternClass < PatternClass
26
+ include ChildPattern
27
+
28
+ # @param _subject [Element] parent element
29
+ # @param _missing_child [String] nmtoken for missing child element
30
+ def initialize(_subject, _missing_child, _index=-1)
31
+ @missing_child, @index = _missing_child, _index
32
+ super _subject
33
+ end
34
+
35
+ def relationship
36
+ 'missing child'
37
+ end
38
+
39
+ # @return [String] description of this child pattern
40
+ def description
41
+ "#{subject.description} #{relationship} <#{child}>"
42
+ end
43
+
44
+ attr_reader :missing_child, :index
45
+ alias_method :child, :missing_child
46
+ alias_method :parent, :subject
47
+ end
48
+
49
+ module ChildPattern
50
+ # @return [String] describes relationship between parent and child
51
+ def relationship
52
+ "#{(index+1).ordinal_name} #{super}"
53
+ end
54
+
55
+ # @return [String] description of this child pattern
56
+ def description
57
+ "#{subject.description}'s #{relationship} #{child.description}"
58
+ end
59
+ end
60
+ end # module Duxml
@@ -1,31 +1,31 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../grammar/pattern')
4
-
5
- module Duxml
6
- module TextPattern; end
7
- # pattern representing relationship between an object and its text-only child
8
- class TextPatternClass < PatternClass
9
- include TextPattern
10
-
11
- # @param _subject [Ox::Element] parent of text node
12
- # @param _index [Fixnum] index of text node
13
- def initialize(_subject, _str, _index)
14
- @index = _index
15
- @string = _str
16
- super _subject
17
- end
18
-
19
- attr_reader :subject, :index, :str
20
- end
21
-
22
- module TextPattern
23
- def text
24
- subject.nodes[index]
25
- end
26
-
27
- def description
28
- "#{subject.description}'s #{relationship} is '#{text}'"
29
- end
30
- end # class ContentPattern
31
- end # module Duxml
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../grammar/pattern')
4
+
5
+ module Duxml
6
+ module TextPattern; end
7
+ # pattern representing relationship between an object and its text-only child
8
+ class TextPatternClass < PatternClass
9
+ include TextPattern
10
+
11
+ # @param _subject [Ox::Element] parent of text node
12
+ # @param _index [Fixnum] index of text node
13
+ def initialize(_subject, _str, _index)
14
+ @index = _index
15
+ @string = _str
16
+ super _subject
17
+ end
18
+
19
+ attr_reader :subject, :index, :str
20
+ end
21
+
22
+ module TextPattern
23
+ def text
24
+ subject.nodes[index]
25
+ end
26
+
27
+ def description
28
+ "#{subject.description}'s #{relationship} is '#{text}'"
29
+ end
30
+ end # class ContentPattern
31
+ end # module Duxml
@@ -1,69 +1,69 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/pattern/child_pattern')
4
- require File.expand_path(File.dirname(__FILE__) + '/pattern/text_pattern')
5
- require File.expand_path(File.dirname(__FILE__) + '/pattern/attr_name_pattern')
6
- require File.expand_path(File.dirname(__FILE__) + '/pattern/attr_val_pattern')
7
-
8
- module Duxml
9
- # helper methods to create Patterns from a given Element's relationships with its members
10
- module PatternMaker
11
- include Duxml
12
- # @param node [Duxml::Element] doc whose relationships are to be made into patterns
13
- # @return [Array[Duxml::Pattern]] array of patterns representing every relationship of this XMl node and its members
14
- def get_relationships(node)
15
- [get_child_patterns(node),
16
- get_null_child_patterns(node),
17
- get_existing_attr_patterns(node),
18
- get_null_attr_patterns(node)].flatten
19
- end
20
-
21
- # @param node [Duxml::Element] doc whose relationships are to be made into patterns
22
- # @return [Array[Duxml::AttrNamePattern, Duxml::AttrValPattern]] one pattern for each existing attribute
23
- def get_existing_attr_patterns(node)
24
- # check existing attributes
25
- node.attributes.collect do |k, v|
26
- [AttrNamePatternClass.new(node, k), AttrValPatternClass.new(node, k)]
27
- end.flatten
28
- end
29
-
30
- # @param node [Element] doc whose relationships are to be made into patterns
31
- # @return [Array[AttrNamePattern]] one pattern for each attribute that should but does not exist
32
- def get_null_attr_patterns(node)
33
- self.AttrsRuleClass.collect do |attr_rule|
34
- if attr_rule.required? && node.name == attr_rule.subject
35
- AttrNamePatternClass.new(node, attr_rule.attr_name) unless node[attr_rule.attr_name]
36
- end
37
- end.compact
38
- end
39
-
40
- # @param node [Duxml::Element] doc whose relationships are to be made into patterns
41
- # @return [Array[ChildPattern]] one pattern for each child that should be there but isn't
42
- def get_null_child_patterns(node)
43
- self.ChildrenRuleClass.each do |child_rule|
44
- if node.name == child_rule.subject
45
- return child_rule.required_children.collect do |required_child_type|
46
- unless node.nodes.any? do |n| n.name == required_child_type end
47
- NullChildPatternClass.new(node, required_child_type, -1)
48
- end
49
- end.compact
50
- end
51
- end
52
- []
53
- end
54
-
55
- # @param node [Duxml::Element] object whose relationships are to be made into patterns
56
- # @return [Array[Duxml::ChildPattern, Duxml::ContentPattern]] one pattern for each child that exists
57
- def get_child_patterns(node)
58
- i = -1
59
- node.nodes.collect do |child|
60
- i += 1
61
- if child.is_a?(String)
62
- TextPatternClass.new(node, child, i)
63
- else
64
- ChildPatternClass.new(node, child, i)
65
- end
66
- end
67
- end # def get_child_patterns
68
- end # module PatternMaker
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/pattern/child_pattern')
4
+ require File.expand_path(File.dirname(__FILE__) + '/pattern/text_pattern')
5
+ require File.expand_path(File.dirname(__FILE__) + '/pattern/attr_name_pattern')
6
+ require File.expand_path(File.dirname(__FILE__) + '/pattern/attr_val_pattern')
7
+
8
+ module Duxml
9
+ # helper methods to create Patterns from a given Element's relationships with its members
10
+ module PatternMaker
11
+ include Duxml
12
+ # @param node [Duxml::Element] doc whose relationships are to be made into patterns
13
+ # @return [Array[Duxml::Pattern]] array of patterns representing every relationship of this XMl node and its members
14
+ def get_relationships(node)
15
+ [get_child_patterns(node),
16
+ get_null_child_patterns(node),
17
+ get_existing_attr_patterns(node),
18
+ get_null_attr_patterns(node)].flatten
19
+ end
20
+
21
+ # @param node [Duxml::Element] doc whose relationships are to be made into patterns
22
+ # @return [Array[Duxml::AttrNamePattern, Duxml::AttrValPattern]] one pattern for each existing attribute
23
+ def get_existing_attr_patterns(node)
24
+ # check existing attributes
25
+ node.attributes.collect do |k, v|
26
+ [AttrNamePatternClass.new(node, k), AttrValPatternClass.new(node, k)]
27
+ end.flatten
28
+ end
29
+
30
+ # @param node [Element] doc whose relationships are to be made into patterns
31
+ # @return [Array[AttrNamePattern]] one pattern for each attribute that should but does not exist
32
+ def get_null_attr_patterns(node)
33
+ self.AttrsRuleClass.collect do |attr_rule|
34
+ if attr_rule.required? && node.name == attr_rule.subject
35
+ AttrNamePatternClass.new(node, attr_rule.attr_name) unless node[attr_rule.attr_name]
36
+ end
37
+ end.compact
38
+ end
39
+
40
+ # @param node [Duxml::Element] doc whose relationships are to be made into patterns
41
+ # @return [Array[ChildPattern]] one pattern for each child that should be there but isn't
42
+ def get_null_child_patterns(node)
43
+ self.ChildrenRuleClass.each do |child_rule|
44
+ if node.name == child_rule.subject
45
+ return child_rule.required_children.collect do |required_child_type|
46
+ unless node.nodes.any? do |n| n.name == required_child_type end
47
+ NullChildPatternClass.new(node, required_child_type, -1)
48
+ end
49
+ end.compact
50
+ end
51
+ end
52
+ []
53
+ end
54
+
55
+ # @param node [Duxml::Element] object whose relationships are to be made into patterns
56
+ # @return [Array[Duxml::ChildPattern, Duxml::ContentPattern]] one pattern for each child that exists
57
+ def get_child_patterns(node)
58
+ i = -1
59
+ node.nodes.collect do |child|
60
+ i += 1
61
+ if child.is_a?(String)
62
+ TextPatternClass.new(node, child, i)
63
+ else
64
+ ChildPatternClass.new(node, child, i)
65
+ end
66
+ end
67
+ end # def get_child_patterns
68
+ end # module PatternMaker
69
69
  end # module Duxml