diffxml 0.2.0 → 0.2.1

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: 26d733a1a7c9f08ef8c081456aacb00972a54558
4
- data.tar.gz: a8d24b26f97175818bd199436c3df76b2dbc962a
3
+ metadata.gz: 71975698b2c8d3b61efb8c93560bf39dbb3cfd7b
4
+ data.tar.gz: 718b47df978f4567339ec45b8ba8c133e06eb359
5
5
  SHA512:
6
- metadata.gz: f5578ee34dd1776e2dcdc9ab9b1afacba42208702b6f858edd7d7de3be98f274627640289cb2e691f490a9d1cf46e1ed757aaca049b34a246ac136d2502b59fc
7
- data.tar.gz: 4ba3c68fba21b859e1985445b826cb093685926998eb32fc9da3fa0e0d18b5a146baa4a5da028001218d9e9d4e22078491e733672d3cda8a2ac603c0b4eb0d4f
6
+ metadata.gz: cbce23d4c5d51e50917d25342c42657302fe73b6b62df099ba710f639ca56a4051d08fe1dcfbc93a513aeb6035182cc7e96330b1be84f07c3cbb8503bdf4e130
7
+ data.tar.gz: 4d5de49aef324f97e1fcb7184f1c4e94ab977cf3bd9261740fe480304493d21fe849cbe26595f62d9a63f93c0206c3370ea51ce9f9b0753e5164ae126fe1b8cb
data/.DS_Store CHANGED
Binary file
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # diff-xml [![Gem Version](https://badge.fury.io/rb/diffxml.svg)](https://rubygems.org/gems/diffxml)
1
+ # diffxml [![Gem Version](https://badge.fury.io/rb/diffxml.svg)](https://rubygems.org/gems/diffxml)
2
2
 
3
3
  Inspired by the equivalent-xml gem, I wanted a way to get the differences between the two xmls, instead of just checking to see that there were differences, this is an alternative method I came up with, and I will add as I work on it, as it is still in its infancy.
4
4
 
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "diffxml"
7
- spec.version = '0.2.0'
7
+ spec.version = '0.2.1'
8
8
  spec.authors = ["Jake Bubnar"]
9
9
  spec.email = ["jake@pjbapps.com"]
10
10
  spec.licenses = ["MIT"]
11
11
  spec.summary = 'A simple xml comparison tool to get a list of diffs between two files passed to it'
12
- spec.description = 'Goes through each child to find the XPaths of each final child, and compares them to the path in the second file'
12
+ spec.description = 'Goes through each child to find the XPaths of each final child, and compares them to the path in the second file, returning the differences.'
13
13
  spec.homepage = 'https://github.com/pbubnar/diff-xml'
14
14
 
15
15
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -0,0 +1,27 @@
1
+ require 'DiffXML'
2
+ module DiffXML
3
+
4
+ class Utils
5
+ def self.collectXPaths(doc, xpArray)
6
+ doc.element_children.each do |child|
7
+ if child.element_children.empty?
8
+ xpArray.push(getPath(child,child.name)) unless child.content.empty?
9
+ else
10
+ collectXPaths(child, xpArray)
11
+ end
12
+ end
13
+ end
14
+
15
+ def self.getPath(node, path = nil)
16
+ if node.parent.name.eql? 'document'
17
+ return path
18
+ else
19
+ if path.nil?
20
+ getPath(node, node.name)
21
+ else
22
+ getPath(node.parent, "#{node.parent.name}/#{path}")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,46 +1,24 @@
1
1
  require 'Nokogiri'
2
+ require 'DiffXML/utils'
2
3
 
3
4
  module DiffXML
4
5
  @xpathArray = []
5
6
  def self.compareXML(doc1, doc2)
6
7
  @namespaces = doc1.collect_namespaces
7
8
  if doc1.class == Nokogiri::XML::Document
8
- collectXPaths(doc1.root)
9
+ DiffXML::Utils.collectXPaths(doc1.root, @xpathArray)
9
10
  else
10
- collectXPaths(doc1)
11
+ DiffXML::Utils.collectXPaths(doc1, @xpathArray)
11
12
  end
12
- @xpathArray.delete_if.with_index do |element, i|
13
- puts "iteration #{i} and #{element}"
13
+ @xpathArray.delete_if do |element|
14
14
  compareToPath(element, doc1, doc2)
15
15
  end
16
16
  end
17
17
 
18
- def self.getPath(node, path = nil)
19
- if node.parent.name.eql? 'document'
20
- return path
21
- else
22
- if path.nil?
23
- getPath(node, node.name)
24
- else
25
- getPath(node.parent, "#{node.parent.name}/#{path}")
26
- end
27
- end
28
- end
29
-
30
18
  def self.compareToPath(path, doc1, doc2)
31
19
  doc2.search(path, @namespaces).to_s == doc1.search(path, @namespaces).to_s
32
20
  end
33
21
 
34
- def self.collectXPaths(doc)
35
- doc.element_children.each do |child|
36
- if child.element_children.empty?
37
- @xpathArray.push(getPath(child,child.name)) unless child.content.empty?
38
- else
39
- collectXPaths(child)
40
- end
41
- end
42
- end
43
-
44
22
  def self.getXPathArray
45
23
  @xpathArray
46
24
  end
@@ -14,22 +14,22 @@ describe DiffXML do
14
14
 
15
15
  it 'should return an XPath for a given node' do
16
16
  node = xml1.element_children[0].element_children[2].element_children[0].element_children[0]
17
- expect(DiffXML.getPath(node, node.name)).to eql 'doc/third/firstthird/finalChild'
17
+ expect(DiffXML::Utils.getPath(node, node.name)).to eql 'doc/third/firstthird/finalChild'
18
18
  end
19
19
 
20
20
  it 'should return an XPath for a given node when no name is passed in' do
21
21
  node = xml1.element_children[0].element_children[2].element_children[0].element_children[0]
22
- expect(DiffXML.getPath(node)).to eql 'doc/third/firstthird/finalChild'
22
+ expect(DiffXML::Utils.getPath(node)).to eql 'doc/third/firstthird/finalChild'
23
23
  end
24
24
 
25
25
  it 'should Collect all XPaths of the children into an array' do
26
- DiffXML.collectXPaths(xml1)
26
+ DiffXML::Utils.collectXPaths(xml1, DiffXML.getXPathArray)
27
27
  expect(DiffXML.getXPathArray.size).to be 3
28
28
  expect(DiffXML.getXPathArray).to eql %w[doc/first doc/second doc/third/firstthird/finalChild]
29
29
  end
30
30
 
31
31
  it 'should retrieve and compare a node from a second document using a Path' do
32
- expect(DiffXML.compareToPath('doc/first',xml1,xml2)).to eql true
32
+ expect(DiffXML::Utils.compareToPath('doc/first',xml1,xml2)).to eql true
33
33
  end
34
34
 
35
35
  it 'should go through 2 XMLs removing XPaths from the array as they are found' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diffxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Bubnar
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.6'
69
69
  description: Goes through each child to find the XPaths of each final child, and compares
70
- them to the path in the second file
70
+ them to the path in the second file, returning the differences.
71
71
  email:
72
72
  - jake@pjbapps.com
73
73
  executables: []