rasantiago-tiny_xpath_helper 0.1.2 → 0.1.3

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
@@ -45,6 +45,12 @@ If you want empty documents to not raise an error
45
45
  >> empty_xpath = TinyXPathHelper.new( String.new, :allow_empty_document => true )
46
46
  >> empty_xpath[ 'b/@beta' ]
47
47
  => []
48
+
49
+ If you want to call to_s on the xpath argument
50
+ >> xpath_with_indifferent_access = TinyXPathHelper.new( File.open( 'test/xml/sample.xml' ), :with_indifferent_access => true )
51
+ >> xpath_with_indifferent_access[ :node ]
52
+ => ["one", "two", "three\n "]
53
+
48
54
 
49
55
  --
50
56
  doctest_require: 'lib/tiny_xpath_helper.rb'
@@ -6,20 +6,24 @@ class TinyXPathHelper
6
6
  def initialize(xml, options = {})
7
7
  @xml = xml
8
8
  @node = self.class.xml_node_for_xmlish(xml, options)
9
+ @options = options.freeze
9
10
  end
10
-
11
- def find_xpath(xpath_expr, options = {})
12
- self.class.find_xpath_from( node, xpath_expr, options )
11
+
12
+ def default_options
13
+ @options.dup
13
14
  end
14
15
 
15
- alias at find_xpath
16
+ def find_xpath(xpath_expr, options = {})
17
+ self.class.find_xpath_from( node, xpath_expr, default_options.update(options) )
18
+ end
16
19
 
17
20
  def first(xpath_expr, options = {})
18
- self.find_xpath( xpath_expr, options.update(:find => :first) )
21
+ self.find_xpath( xpath_expr, default_options.update(options).update(:find => :first) )
19
22
  end
23
+ alias at first
20
24
 
21
25
  def all(xpath_expr, options = {})
22
- self.find_xpath( xpath_expr, options.update(:find => :all) )
26
+ self.find_xpath( xpath_expr, default_options.update(options).update(:find => :all) )
23
27
  end
24
28
  alias [] all
25
29
 
@@ -61,6 +65,9 @@ class TinyXPathHelper
61
65
  end
62
66
 
63
67
  def self.find_xpath_from(element, path, options = {}, &blk)
68
+ if options[:with_indifferent_access]
69
+ path = path.to_s
70
+ end
64
71
 
65
72
  format = options[:format] || :text
66
73
  if format == :array
@@ -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.2"
5
+ s.version = "0.1.3"
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Wolfe