nokofuzzi 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.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/nokofuzzi.rb +7 -0
- data/spec/nokofuzzi_spec.rb +18 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74ffa4ece3b1f5f25ede6041d992ae7c7749dacb
|
4
|
+
data.tar.gz: dea2421e26e0a5b6b1a2f5557e77990fdec27c5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48cfbd829bab2a8450eab2110b8ae4b5300f08a88b559e91b6ca8b69349a76e49fdbe11a9aa727b85548aec57c243054b9f4514980a2ad00b4ea8d38f4f62f83
|
7
|
+
data.tar.gz: deb6e4bef5b1243706222cc91836cd8d9d4c535bee9fd5aac7a28d121a0837a53b0c076d3e23b90feae1212fe4629b402bd2390de8f98f3493c0a801c4cb449c
|
data/README.md
CHANGED
@@ -35,3 +35,13 @@ modified_xml = Nokogiri::XML('<a><b></b><c><b></b></c></a>').without_xpath('//b'
|
|
35
35
|
|
36
36
|
puts modified_xml.to_xml # <?xml version="1.0"?><a><c/></a>
|
37
37
|
```
|
38
|
+
|
39
|
+
## set_text_at_xpath(xpath, text)
|
40
|
+
`set_text_at_xpath` replaces the text for a node (as well as contents below that node)
|
41
|
+
|
42
|
+
``` ruby
|
43
|
+
modified_xml = Nokogiri::XML('<a><b></b><c><b></b></c></a>').set_text_at_xpath('//c', "HI")
|
44
|
+
|
45
|
+
puts modified_xml.to_xml # <?xml version="1.0"?><a><b/><c>HI</c></a>
|
46
|
+
```
|
47
|
+
|
data/lib/nokofuzzi.rb
CHANGED
data/spec/nokofuzzi_spec.rb
CHANGED
@@ -13,8 +13,25 @@ describe Nokogiri::XML::Document do
|
|
13
13
|
expect(source_xml.without_xpath('//c').to_xml).to eq(expected_c_xml.to_xml)
|
14
14
|
end
|
15
15
|
it "expects removing //b to remove everything <b> node and below" do
|
16
|
-
expect(source_xml.without_xpath('//
|
16
|
+
expect(source_xml.without_xpath('//b').to_xml).to eq(expected_b_xml.to_xml)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe "#set_text_at_xpath" do
|
20
|
+
let(:source_xml) { Nokogiri::XML('<node><a><c></c></a><b><c></c></b></node>')}
|
21
|
+
let(:expected_b_c_xml) { Nokogiri::XML('<node><a><c></c></a><b><c>HI</c></b></node>') }
|
22
|
+
let(:expected_c_xml) { Nokogiri::XML('<node><a><c>HI</c></a><b><c>HI</c></b></node>') }
|
23
|
+
let(:expected_b_xml) { Nokogiri::XML('<node><a><c></c></a><b>HI</b></node>') }
|
24
|
+
|
25
|
+
it "expects removing //b/c to replacing the <c> node text inside <b>" do
|
26
|
+
expect(source_xml.set_text_at_xpath('//b/c', "HI").to_xml).to eq(expected_b_c_xml.to_xml)
|
27
|
+
end
|
28
|
+
it "expects removing //c to replace text for all <c> nodes" do
|
29
|
+
expect(source_xml.set_text_at_xpath('//c', "HI").to_xml).to eq(expected_c_xml.to_xml)
|
17
30
|
end
|
31
|
+
it "expects removing //b to replace text for the <b> node and remove the <c> node" do
|
32
|
+
expect(source_xml.set_text_at_xpath('//b', "HI").to_xml).to eq(expected_b_xml.to_xml)
|
33
|
+
end
|
34
|
+
|
18
35
|
end
|
19
36
|
|
20
37
|
describe '#each_missing' do
|