duxml 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
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,31 +1,31 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/change')
4
-
5
- module Duxml
6
- module Add; end
7
-
8
- # created when an doc gains a child
9
- class AddClass < ChangeClass
10
- include Add
11
-
12
- def initialize(_subject, _child, _index)
13
- super _subject
14
- @child, @index = _child, _index
15
- end
16
-
17
- attr_reader :subject, :child, :index
18
- alias_method :parent, :subject
19
- alias_method :object, :child
20
- end
21
-
22
- module Add
23
- def description
24
- %(#{super} #{child.description} added to #{parent.description} at index #{index == -1 ? '0' : index.to_s}.)
25
- end
26
-
27
- def parent
28
- subject
29
- end
30
- end # class Add
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/change')
4
+
5
+ module Duxml
6
+ module Add; end
7
+
8
+ # created when an doc gains a child
9
+ class AddClass < ChangeClass
10
+ include Add
11
+
12
+ def initialize(_subject, _child, _index)
13
+ super _subject
14
+ @child, @index = _child, _index
15
+ end
16
+
17
+ attr_reader :subject, :child, :index
18
+ alias_method :parent, :subject
19
+ alias_method :object, :child
20
+ end
21
+
22
+ module Add
23
+ def description
24
+ %(#{super} #{child.description} added to #{parent.description} at index #{index == -1 ? '0' : index.to_s}.)
25
+ end
26
+
27
+ def parent
28
+ subject
29
+ end
30
+ end # class Add
31
31
  end # module Duxml
@@ -1,71 +1,71 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../grammar/pattern')
4
-
5
- module Duxml
6
- module Change; end
7
- # do not use - only for subclassing
8
- # changes represent events i.e. patterns with a fixed position in time,
9
- # and can include qualification and validation errors
10
- class ChangeClass < PatternClass
11
- include Change
12
-
13
- @time_stamp
14
-
15
- # all subclasses of Change must call this super method or implement the same function within their #initialize
16
- #
17
- # @param _subject [Duxml::Element] parent doc affected by change
18
- def initialize(_subject, *args)
19
- super _subject
20
- @time_stamp = Time.now
21
- args.each do |arg|
22
- if arg.is_a?(Duxml::Element)
23
- @object = arg
24
- break
25
- end
26
- end
27
- end
28
-
29
- attr_reader :time_stamp
30
- end # class ChangeClass < PatternClass
31
-
32
- module Change
33
- def abstract?
34
- false
35
- end
36
-
37
- # @return [String] gives its time stamp
38
- def description
39
- "at #{time_stamp}#{line_expr}:"
40
- end
41
-
42
- # @return [-1,0,1,nil] compares dates of changes
43
- def <=>(obj)
44
- return nil unless obj.is_a?(Duxml::Change)
45
- date <=> obj.date
46
- end
47
-
48
- # @return [Fixnum] line number of changed object; -l if not applicable
49
- def line
50
- case
51
- when object.respond_to?(:line) && object.line.is_a?(Numeric) && object.line >= 0
52
- object.line
53
- when object.respond_to?(:object) && object.object.respond_to?(:line) && object.object.line.is_a?(Numeric) && object.object.line >= 0
54
- object.object.line
55
- when object.respond_to?(:subject) && object.subject.respond_to?(:line) && object.subject.line.is_a?(Numeric) && object.subject.line >= 0
56
- object.subject.line
57
- when subject.respond_to?(:line) && subject.line.is_a?(Numeric) && subject.line >= 0
58
- subject.line
59
- else
60
- -1
61
- end
62
- end
63
-
64
- private
65
-
66
- # @return [String] string equivalent of object's line number
67
- def line_expr
68
- line >= 0 ? " on line #{line.to_s}" : ''
69
- end
70
- end # class Change
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../grammar/pattern')
4
+
5
+ module Duxml
6
+ module Change; end
7
+ # do not use - only for subclassing
8
+ # changes represent events i.e. patterns with a fixed position in time,
9
+ # and can include qualification and validation errors
10
+ class ChangeClass < PatternClass
11
+ include Change
12
+
13
+ @time_stamp
14
+
15
+ # all subclasses of Change must call this super method or implement the same function within their #initialize
16
+ #
17
+ # @param _subject [Duxml::Element] parent doc affected by change
18
+ def initialize(_subject, *args)
19
+ super _subject
20
+ @time_stamp = Time.now
21
+ args.each do |arg|
22
+ if arg.is_a?(Duxml::Element)
23
+ @object = arg
24
+ break
25
+ end
26
+ end
27
+ end
28
+
29
+ attr_reader :time_stamp
30
+ end # class ChangeClass < PatternClass
31
+
32
+ module Change
33
+ def abstract?
34
+ false
35
+ end
36
+
37
+ # @return [String] gives its time stamp
38
+ def description
39
+ "at #{time_stamp}#{line_expr}:"
40
+ end
41
+
42
+ # @return [-1,0,1,nil] compares dates of changes
43
+ def <=>(obj)
44
+ return nil unless obj.is_a?(Duxml::Change)
45
+ date <=> obj.date
46
+ end
47
+
48
+ # @return [Fixnum] line number of changed object; -l if not applicable
49
+ def line
50
+ case
51
+ when object.respond_to?(:line) && object.line.is_a?(Numeric) && object.line >= 0
52
+ object.line
53
+ when object.respond_to?(:object) && object.object.respond_to?(:line) && object.object.line.is_a?(Numeric) && object.object.line >= 0
54
+ object.object.line
55
+ when object.respond_to?(:subject) && object.subject.respond_to?(:line) && object.subject.line.is_a?(Numeric) && object.subject.line >= 0
56
+ object.subject.line
57
+ when subject.respond_to?(:line) && subject.line.is_a?(Numeric) && subject.line >= 0
58
+ subject.line
59
+ else
60
+ -1
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ # @return [String] string equivalent of object's line number
67
+ def line_expr
68
+ line >= 0 ? " on line #{line.to_s}" : ''
69
+ end
70
+ end # class Change
71
71
  end # module Duxml
@@ -1,34 +1,34 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/change')
4
-
5
- module Duxml
6
- module ChangeAttr; end
7
-
8
- # created when Element has an attribute already and its value has been changed
9
- class ChangeAttrClass < ChangeClass
10
- include ChangeAttr
11
-
12
- # @param _subject [Duxml::Element] parent doc whose attribute changed
13
- # @param _attr_name [String] name of the changed attribute
14
- # @param _old_value [String] old attribute value
15
- def initialize(_subject, _attr_name, _old_value)
16
- super _subject
17
- @attr_name, @old_value = _attr_name, _old_value
18
- end
19
-
20
- attr_reader :attr_name, :old_value
21
- end # class ChangeAttributeClass
22
-
23
- module ChangeAttr
24
- # @return [String] new value of attribute
25
- def value
26
- subject[attr_name]
27
- end
28
-
29
- # @return [String] self description
30
- def description
31
- "#{super} #{subject.description}'s @#{attr_name} changed value from '#{old_value}' to '#{value}'."
32
- end
33
- end # module ChangeAttribute
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/change')
4
+
5
+ module Duxml
6
+ module ChangeAttr; end
7
+
8
+ # created when Element has an attribute already and its value has been changed
9
+ class ChangeAttrClass < ChangeClass
10
+ include ChangeAttr
11
+
12
+ # @param _subject [Duxml::Element] parent doc whose attribute changed
13
+ # @param _attr_name [String] name of the changed attribute
14
+ # @param _old_value [String] old attribute value
15
+ def initialize(_subject, _attr_name, _old_value)
16
+ super _subject
17
+ @attr_name, @old_value = _attr_name, _old_value
18
+ end
19
+
20
+ attr_reader :attr_name, :old_value
21
+ end # class ChangeAttributeClass
22
+
23
+ module ChangeAttr
24
+ # @return [String] new value of attribute
25
+ def value
26
+ subject[attr_name]
27
+ end
28
+
29
+ # @return [String] self description
30
+ def description
31
+ "#{super} #{subject.description}'s @#{attr_name} changed value from '#{old_value}' to '#{value}'."
32
+ end
33
+ end # module ChangeAttribute
34
34
  end # module Duxml
@@ -1,33 +1,33 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/change')
4
-
5
- module Duxml
6
- module ChangeText; end
7
- # created when doc has text and text has been changed
8
- class ChangeTextClass < ChangeClass
9
- include ChangeText
10
-
11
- # @param _subject [Duxml::Element] parent doc whose text has changed
12
- # @param _index [Fixnum] index of parent's nodes that text is found at
13
- # @param _old_text [String] string that was replaced
14
- def initialize(_subject, _index, _old_text)
15
- super _subject
16
- @index, @old_text = _index, _old_text
17
- end
18
-
19
- attr_reader :index, :old_text
20
- end
21
-
22
- module ChangeText
23
- # @return [String] self description
24
- def description
25
- "#{super} #{subject.description}'s text at index #{index} changed from '#{old_text}' to '#{text}'."
26
- end
27
-
28
- # @return [String] new content (subsequent changes may mean this new content no longer exists in its original form!)
29
- def text
30
- subject.nodes[index]
31
- end
32
- end # module ChangeText
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/change')
4
+
5
+ module Duxml
6
+ module ChangeText; end
7
+ # created when doc has text and text has been changed
8
+ class ChangeTextClass < ChangeClass
9
+ include ChangeText
10
+
11
+ # @param _subject [Duxml::Element] parent doc whose text has changed
12
+ # @param _index [Fixnum] index of parent's nodes that text is found at
13
+ # @param _old_text [String] string that was replaced
14
+ def initialize(_subject, _index, _old_text)
15
+ super _subject
16
+ @index, @old_text = _index, _old_text
17
+ end
18
+
19
+ attr_reader :index, :old_text
20
+ end
21
+
22
+ module ChangeText
23
+ # @return [String] self description
24
+ def description
25
+ "#{super} #{subject.description}'s text at index #{index} changed from '#{old_text}' to '#{text}'."
26
+ end
27
+
28
+ # @return [String] new content (subsequent changes may mean this new content no longer exists in its original form!)
29
+ def text
30
+ subject.nodes[index]
31
+ end
32
+ end # module ChangeText
33
33
  end # module Duxml
@@ -1,25 +1,25 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/change')
4
-
5
- module Duxml
6
- module Error
7
- def error?
8
- true
9
- end
10
- end # class Error
11
-
12
- # do not use except to subclass
13
- class ErrorClass < ChangeClass
14
- include Error
15
-
16
- # @param _rule [Rule] rule that was violated
17
- # @param _change_or_pattern [ChangeClass, PatternClass] can be triggered by a change or a pattern found in a static document
18
- def initialize(_rule, _change_or_pattern)
19
- super(_rule)
20
- @object = _change_or_pattern
21
- end
22
- alias_method :rule, :subject
23
- end
24
-
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/change')
4
+
5
+ module Duxml
6
+ module Error
7
+ def error?
8
+ true
9
+ end
10
+ end # class Error
11
+
12
+ # do not use except to subclass
13
+ class ErrorClass < ChangeClass
14
+ include Error
15
+
16
+ # @param _rule [Rule] rule that was violated
17
+ # @param _change_or_pattern [ChangeClass, PatternClass] can be triggered by a change or a pattern found in a static document
18
+ def initialize(_rule, _change_or_pattern)
19
+ super(_rule)
20
+ @object = _change_or_pattern
21
+ end
22
+ alias_method :rule, :subject
23
+ end
24
+
25
25
  end # module Duxml
@@ -1,33 +1,33 @@
1
- # Copyright (c) 2016 Freescale Semiconductor Inc.
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/change')
4
-
5
- module Duxml
6
- module NewAttr; end
7
-
8
- # created when doc gains a new attribute
9
- class NewAttrClass < ChangeClass
10
- include NewAttr
11
-
12
- # @param _subject [Duxml::Element] parent doc
13
- # @param _attr_name
14
- def initialize(_subject, _attr_name)
15
- super(_subject)
16
- @attr_name = _attr_name
17
- end
18
-
19
- attr_reader :attr_name
20
- end
21
-
22
- module NewAttr
23
- # @return [String] value of the new attribute
24
- def value
25
- subject[attr_name]
26
- end
27
-
28
- # @return [String] self description
29
- def description
30
- "#{super} #{subject.description} given new attribute '#{attr_name}' with value '#{value}'."
31
- end
32
- end # module NewAttribute
1
+ # Copyright (c) 2016 Freescale Semiconductor Inc.
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/change')
4
+
5
+ module Duxml
6
+ module NewAttr; end
7
+
8
+ # created when doc gains a new attribute
9
+ class NewAttrClass < ChangeClass
10
+ include NewAttr
11
+
12
+ # @param _subject [Duxml::Element] parent doc
13
+ # @param _attr_name
14
+ def initialize(_subject, _attr_name)
15
+ super(_subject)
16
+ @attr_name = _attr_name
17
+ end
18
+
19
+ attr_reader :attr_name
20
+ end
21
+
22
+ module NewAttr
23
+ # @return [String] value of the new attribute
24
+ def value
25
+ subject[attr_name]
26
+ end
27
+
28
+ # @return [String] self description
29
+ def description
30
+ "#{super} #{subject.description} given new attribute '#{attr_name}' with value '#{value}'."
31
+ end
32
+ end # module NewAttribute
33
33
  end # module Duxml