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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9056b793e5ae8f8aeb572116a36c28c3a62dd6a
4
- data.tar.gz: 78517b99ddc75a08b9a6a58e6a759c81ffa094dc
3
+ metadata.gz: 74ffa4ece3b1f5f25ede6041d992ae7c7749dacb
4
+ data.tar.gz: dea2421e26e0a5b6b1a2f5557e77990fdec27c5f
5
5
  SHA512:
6
- metadata.gz: 7c5bd3d0a35ac09fb6394dfa08f453d05756f538a5856db1b1e0a8cf01ef88715af6fdf33865018be4d8841b09c2a6553cea40925f579934939747c11357acbc
7
- data.tar.gz: dbe954673a6559956cbab8498dac4704416f804100738e5a716fd286de0d79d13111bc531905f4d798d1e15a33fbe159d68001005cf9b63d62db3aa1bfdef677
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
@@ -25,6 +25,13 @@ module Nokogiri
25
25
  end
26
26
  xml_dup
27
27
  end
28
+ def set_text_at_xpath(xpath, text)
29
+ xml_dup = self.dup
30
+ xml_dup.xpath(xpath).each do |xml_node|
31
+ xml_node.content = text
32
+ end
33
+ xml_dup
34
+ end
28
35
  end
29
36
  end
30
37
  end
@@ -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('//c').to_xml).to eq(expected_c_xml.to_xml)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokofuzzi
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
  - Thomas Powell