rasantiago-tiny_xpath_helper 0.1.1 → 0.1.2

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/README.rdoc CHANGED
@@ -40,6 +40,11 @@ The output from :format => :xml is suitable for passing to another TinyXPathHelp
40
40
  >> deeper_xpath = TinyXPathHelper.new( node_tree )
41
41
  >> deeper_xpath[ 'b/@beta' ]
42
42
  => ["true"]
43
+
44
+ If you want empty documents to not raise an error
45
+ >> empty_xpath = TinyXPathHelper.new( String.new, :allow_empty_document => true )
46
+ >> empty_xpath[ 'b/@beta' ]
47
+ => []
43
48
 
44
49
  --
45
50
  doctest_require: 'lib/tiny_xpath_helper.rb'
@@ -3,9 +3,9 @@ require 'rexml/document'
3
3
  class TinyXPathHelper
4
4
  attr :node
5
5
 
6
- def initialize(xml)
6
+ def initialize(xml, options = {})
7
7
  @xml = xml
8
- @node = self.class.xml_node_for_xmlish(xml)
8
+ @node = self.class.xml_node_for_xmlish(xml, options)
9
9
  end
10
10
 
11
11
  def find_xpath(xpath_expr, options = {})
@@ -31,7 +31,7 @@ class TinyXPathHelper
31
31
  io_stream_classes + [ String, REXML::Document ]
32
32
  end
33
33
 
34
- def self.xml_node_for_xmlish( xml )
34
+ def self.xml_node_for_xmlish( xml, options = {} )
35
35
  if io_stream_classes.any?{|k| k === xml }
36
36
  xml = xml.read
37
37
  end
@@ -39,7 +39,11 @@ class TinyXPathHelper
39
39
  xml = REXML::Document.new(xml)
40
40
  end
41
41
  if REXML::Document === xml
42
- xml = xml.root
42
+ if options[:allow_empty_document] and ! xml.root
43
+ xml = xml
44
+ else
45
+ xml = xml.root
46
+ end
43
47
  end
44
48
  if not REXML::Element === xml
45
49
  raise TypeError.new("Expected REXML::Element, got #{xml.class}")
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tiny_xpath_helper}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.authors = ["Jesse Wolfe"]
8
8
  s.date = %q{2009-06-01}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rasantiago-tiny_xpath_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Wolfe