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 +6 -0
- data/lib/tiny_xpath_helper.rb +13 -6
- data/tiny_xpath_helper.gemspec +1 -1
- metadata +1 -1
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'
|
data/lib/tiny_xpath_helper.rb
CHANGED
@@ -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
|
12
|
-
|
11
|
+
|
12
|
+
def default_options
|
13
|
+
@options.dup
|
13
14
|
end
|
14
15
|
|
15
|
-
|
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
|
data/tiny_xpath_helper.gemspec
CHANGED