gravitext-xmlprod 1.5.1-java → 1.6.0-java

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.
data/History.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ === 1.6.0 (2012-6-23)
2
+ * Add Element.find_r, select_r recursive variants
3
+
1
4
  === 1.5.1 (2012-4-5)
2
5
  * Upgrade to gravitext-util ~> 1.6.1
3
6
  * StAXConsumer: fully non-private, non-final
data/Manifest.txt CHANGED
@@ -12,4 +12,4 @@ test/setup.rb
12
12
  test/test_dom.rb
13
13
  test/test_tree.rb
14
14
  test/xml/huffingtonpost.full.atom.xml
15
- lib/gravitext-xmlprod/gravitext-xmlprod-1.5.1.jar
15
+ lib/gravitext-xmlprod/gravitext-xmlprod-1.6.0.jar
@@ -54,6 +54,14 @@ module Gravitext::XMLProd
54
54
  end
55
55
  end
56
56
 
57
+ # Return Array of descendant elements matching tag and/or where
58
+ # yielding to block returns true. Elements failing the tag/block
59
+ # test will be recursed into, in search of more matches.
60
+ def select_r( tag = nil, &block )
61
+ tag = Tag.new( tag, Tag.WILDCARD_NS ) unless tag.nil? || tag.is_a?( Tag )
62
+ _select_r( [], tag, block || TRUTH )
63
+ end
64
+
57
65
  # Return first child element matching tag and/or where yielding to
58
66
  # block returns true. Without a block is equivalent to
59
67
  # first_element.
@@ -68,6 +76,15 @@ module Gravitext::XMLProd
68
76
  end
69
77
  end
70
78
 
79
+ # Return first descendant element matching the specified tag
80
+ # and/or where yielding to block returns true. Elements failing
81
+ # the tag/block test will be recursed into, in search of the first
82
+ # match.
83
+ def find_r( tag = nil, &block )
84
+ tag = Tag.new( tag, Tag.WILDCARD_NS ) unless tag.nil? || tag.is_a?( Tag )
85
+ _find_r( tag, block || TRUTH )
86
+ end
87
+
71
88
  # Serialize self to String of XML, with options.
72
89
  def to_xml( opts = {} )
73
90
  XMLHelper.write_element( self,
@@ -75,6 +92,33 @@ module Gravitext::XMLProd
75
92
  opts[ :qmark ] || QuoteMark::DOUBLE,
76
93
  opts[ :implied_ns ] || [] )
77
94
  end
95
+
96
+ def _find_r( tag, pred )
97
+ children.each do |c|
98
+ if c.element?
99
+ found = c if ( tag.nil? || c.tag == tag ) && pred.call( c )
100
+ found ||= c._find_r( tag, pred )
101
+ return found if found
102
+ end
103
+ end
104
+ nil
105
+ end
106
+
107
+ def _select_r( matches, tag, pred )
108
+ children.each do |c|
109
+ if c.element?
110
+ if ( tag.nil? || c.tag == tag ) && pred.call( c )
111
+ matches << c
112
+ else
113
+ c._select_r( matches, tag, pred )
114
+ end
115
+ end
116
+ end
117
+ matches
118
+ end
119
+
120
+ TRUTH = lambda { |e| true }
121
+
78
122
  end
79
123
 
80
124
  end
@@ -16,7 +16,7 @@
16
16
 
17
17
  module Gravitext
18
18
  module XMLProd
19
- VERSION = '1.5.1'
19
+ VERSION = '1.6.0'
20
20
 
21
21
  LIB_DIR = File.dirname(__FILE__) # :nodoc:
22
22
  end
data/pom.xml CHANGED
@@ -4,7 +4,7 @@
4
4
  <groupId>com.gravitext</groupId>
5
5
  <artifactId>gravitext-xmlprod</artifactId>
6
6
  <packaging>jar</packaging>
7
- <version>1.5.1</version>
7
+ <version>1.6.0</version>
8
8
  <name>Gravitext XML Producer</name>
9
9
  <url>http://gravitext.com/oss/gravitext-xmlprod</url>
10
10
 
data/test/test_tree.rb CHANGED
@@ -160,6 +160,33 @@ XML
160
160
  assert_equal( 1, root.select { |e| e[ att ] == 'a2value' }.length )
161
161
  end
162
162
 
163
+ def test_recurse
164
+ xml = <<XML
165
+ <doc>
166
+ <o1 a='1'>
167
+ <i1>text</i1>
168
+ <i2>next</i2>
169
+ </o1>
170
+ <o1 a='2'/>
171
+ <o1>
172
+ <o2>
173
+ <i1 a='3'>other</i1>
174
+ <i3/>
175
+ </o2>
176
+ </o1>
177
+ </doc>
178
+ XML
179
+ root = parse_tree( xml )
180
+
181
+ assert_equal( 'text', root.find_r( 'i1' ).characters )
182
+ assert_equal( 'next', root.find_r( 'i2' ).characters )
183
+ assert_equal( 'other',
184
+ root.find_r( 'i1' ) { |e| e['a'] == '3' }.characters )
185
+
186
+ assert_equal( %w[ 1 2 3 ],
187
+ root.select_r { |e| e['a'] }.map { |e| e['a'] } )
188
+ end
189
+
163
190
  def test_invalid_xml_error
164
191
  assert_raises( XMLStreamException ) do
165
192
  parse_tree( "<doc><open></doc>" )
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gravitext-xmlprod
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.5.1
5
+ version: 1.6.0
6
6
  platform: java
7
7
  authors:
8
8
  - David Kellum
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-04-06 00:00:00 Z
13
+ date: 2012-06-23 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gravitext-util
@@ -81,7 +81,7 @@ files:
81
81
  - test/test_dom.rb
82
82
  - test/test_tree.rb
83
83
  - test/xml/huffingtonpost.full.atom.xml
84
- - lib/gravitext-xmlprod/gravitext-xmlprod-1.5.1.jar
84
+ - lib/gravitext-xmlprod/gravitext-xmlprod-1.6.0.jar
85
85
  homepage: http://gravitext.rubyforge.org
86
86
  licenses: []
87
87