compare-xml 0.5.1 → 0.5.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: eb7ad2fa6ba45154479d1129ad6ce84337b331fa
4
- data.tar.gz: eb3a5b0f7caedccb403c1a5504baa80b4e5ff7a8
3
+ metadata.gz: 33a222cacf011fd953938812fd99be01832a61ca
4
+ data.tar.gz: fd30d6713bddf059806814e28faf431132697c60
5
5
  SHA512:
6
- metadata.gz: d46798f576e812ad39b3604c8b41f01d531f6490ba1690facb1cd978c200139d8b1e58a17b98a2d47fbbd76cc011487f9850bb68f5a5e28f5d3156d41a7c9f7c
7
- data.tar.gz: 91993f87fca6eb40ec302bb598a88b85fa36e1876e1c9ef88396b2f52360e8bed89597400d9803ceaa7a455e8d5930750a9239d4610f607efe46f01d03c5dc31
6
+ metadata.gz: cc7042aa3c3ff8b69a6ebcbf76d8a443d5fc7f4d38379f12cbd91d6fe8b908d6d096f70dd22945231e0403ff742cd04f9c0423237fcb3b0715a89baf92d3a93c
7
+ data.tar.gz: 54d723bfb1c797083b103328bfee70ad40ad302c15355106755da9d22d9e58a854f56a859032a3af771a1a042b16727b4082b119832f3f1b5ea0c770b1bd849d
data/README.md CHANGED
@@ -60,19 +60,39 @@ require 'compare-xml'
60
60
  ```
61
61
 
62
62
 
63
- ## Options
63
+ ## Options at a Glance
64
64
 
65
65
  CompareXML has a variety of options that can be invoked as an optional argument, e.g.:
66
66
 
67
67
  ```ruby
68
- CompareXML.equivalent?(doc1, doc2, {squeeze_whitespace: true, verbose: true})
68
+ CompareXML.equivalent?(doc1, doc2, {ignore_comments: false, verbose: true, ...})
69
69
  ```
70
70
 
71
+ - `ignore_attr_order: {true|false}` default: **`true`**
72
+ - when `true`, ignores attribute order within tags
71
73
 
72
- ----------
74
+ - `ignore_attrs: {css}` default: **`{}`**
75
+ - when provided, ignores specific *attributes* using [CSS selectors](http://www.w3schools.com/cssref/css_selectors.asp)
73
76
 
77
+ - `ignore_comments: {true|false}` default: **`true`**
78
+ - when `true`, ignores comments, such as `<!-- comment -->`
74
79
 
75
- - ####`ignore_attr_order: {true|false}` default: **`true`**
80
+ - `ignore_nodes: {css}` default: **`{}`**
81
+ - when provided, ignores specific *nodes* using [CSS selectors](http://www.w3schools.com/cssref/css_selectors.asp)
82
+
83
+ - `ignore_text_nodes: {true|false}` default: **`false`**
84
+ - when `true`, ignores all text content within a document
85
+
86
+ - `collapse_whitespace: {true|false}` default: **`true`**
87
+ - when `true`, trims and collapses whitespace
88
+
89
+ - `verbose: {true|false}` default: **`false`**
90
+ - when `true`, instead of a boolean, `CompareXML.equivalent?` returns an array of discrepancies.
91
+
92
+
93
+ ## Options in Depth
94
+
95
+ - `ignore_attr_order: {true|false}` default: **`true`**
76
96
 
77
97
  When `true`, all attributes are sorted before comparison and only attributes of the same type are compared.
78
98
 
@@ -100,10 +120,8 @@ CompareXML.equivalent?(doc1, doc2, {squeeze_whitespace: true, verbose: true})
100
120
  target="_blank" == target="_blank"
101
121
 
102
122
 
103
- ----------
104
123
 
105
-
106
- - ####`ignore_attrs: {css}` default: **`{}`**
124
+ - `ignore_attrs: {css}` default: **`{}`**
107
125
 
108
126
  When provided, ignores all **attributes** that satisfy a particular rule using [CSS selectors](http://www.w3schools.com/cssref/css_selectors.asp).
109
127
 
@@ -120,10 +138,8 @@ CompareXML.equivalent?(doc1, doc2, {squeeze_whitespace: true, verbose: true})
120
138
  <a href="https://google.com" class="primary button rounded">Link</a>
121
139
 
122
140
 
123
- ----------
124
-
125
141
 
126
- - ####`ignore_comments: {true|false}` default: **`true`**
142
+ - `ignore_comments: {true|false}` default: **`true`**
127
143
 
128
144
  When `true`, ignores comments, such as `<!-- This is a comment -->`.
129
145
 
@@ -140,10 +156,8 @@ CompareXML.equivalent?(doc1, doc2, {squeeze_whitespace: true, verbose: true})
140
156
  <a href="/admin">Link</a>
141
157
 
142
158
 
143
- ----------
144
-
145
159
 
146
- - ####`ignore_nodes: {css}` default: **`{}`**
160
+ - `ignore_nodes: {css}` default: **`{}`**
147
161
 
148
162
  When provided, ignores all **nodes** that satisfy a particular rule using [CSS selectors](http://www.w3schools.com/cssref/css_selectors.asp).
149
163
 
@@ -160,10 +174,8 @@ CompareXML.equivalent?(doc1, doc2, {squeeze_whitespace: true, verbose: true})
160
174
  <a href="/admin"><i class"icon info"></i><b>Message:</b> Link</a>
161
175
 
162
176
 
163
- ----------
164
177
 
165
-
166
- - ####`ignore_text_nodes: {true|false}` default: **`false`**
178
+ - `ignore_text_nodes: {true|false}` default: **`false`**
167
179
 
168
180
  When `true`, ignores all text content. Text content is anything that is included between an opening and a closing tag, e.g. `<tag>THIS IS TEXT CONTENT</tag>`.
169
181
 
@@ -180,14 +192,12 @@ CompareXML.equivalent?(doc1, doc2, {squeeze_whitespace: true, verbose: true})
180
192
  <i class="icon> </i> <b>Message:</b>
181
193
 
182
194
 
183
- ----------
184
-
185
195
 
186
- - ####`squeeze_whitespace: {true|false}` default: **`true`**
196
+ - `collapse_whitespace: {true|false}` default: **`true`**
187
197
 
188
- When `true`, all text content within the document is trimmed (i.e. space removed from left and right) and whitespace is squeezed (i.e. tabs, new lines, multiple whitespaces are all replaced by a single whitespace).
198
+ When `true`, all text content within the document is trimmed (i.e. space removed from left and right) and whitespace is collapsed (i.e. tabs, new lines, multiple whitespace characters are replaced by a single whitespace).
189
199
 
190
- **Usage Example:** `CompareXML.equivalent?(doc1, doc2, {squeeze_whitespace: true})`
200
+ **Usage Example:** `CompareXML.equivalent?(doc1, doc2, {collapse_whitespace: true})`
191
201
 
192
202
  **Example:** When `true` the following HTML strings are considered equal:
193
203
 
@@ -205,10 +215,8 @@ CompareXML.equivalent?(doc1, doc2, {squeeze_whitespace: true, verbose: true})
205
215
  <html><title>This is my title</title></html>
206
216
 
207
217
 
208
- ----------
209
-
210
218
 
211
- - ####`verbose: {true|false}` default: **`false`**
219
+ - `verbose: {true|false}` default: **`false`**
212
220
 
213
221
  When `true`, instead of returning a boolean value `CompareXML.equivalent?` returns an array of all errors encountered when performing a comparison.
214
222
 
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{A customizable tool that compares two instances of Nokogiri::XML::Node for equality or equivalency.}
13
13
  spec.description = %q{CompareXML is a fast, lightweight and feature-rich tool that will solve your XML/HTML comparison or diffing needs. its purpose is to compare two instances of Nokogiri::XML::Node or Nokogiri::XML::NodeSet for equality or equivalency.}
14
- spec.homepage = 'https://github.com/vkononov/compare-xml-xml'
14
+ spec.homepage = 'https://github.com/vkononov/compare-xml'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -25,9 +25,9 @@ module CompareXML
25
25
  # when false, all text nodes are compared to their counterparts (except the empty ones)
26
26
  ignore_text_nodes: false,
27
27
 
28
- # when true, trims and squeezes whitespace in text nodes and comments to a single space
28
+ # when true, trims and collapses whitespace in text nodes and comments to a single space
29
29
  # when false, all whitespace is preserved as it is without any changes
30
- squeeze_whitespace: true,
30
+ collapse_whitespace: true,
31
31
 
32
32
  # when true, provides a list of all error messages encountered in comparisons
33
33
  # when false, execution stops when the first error is encountered with no error messages
@@ -123,7 +123,7 @@ module CompareXML
123
123
  def compareCommentNodes(n1, n2, opts, errors, status = EQUIVALENT)
124
124
  return true if opts[:ignore_comments]
125
125
  t1, t2 = n1.content, n2.content
126
- t1, t2 = squeeze(t1), squeeze(t2) if opts[:squeeze_whitespace]
126
+ t1, t2 = collapse(t1), collapse(t2) if opts[:collapse_whitespace]
127
127
  unless t1 == t2
128
128
  status = UNEQUAL_COMMENTS
129
129
  errors << [nodePath(n1.parent), t1, status, t2, nodePath(n2.parent)] if opts[:verbose]
@@ -228,7 +228,7 @@ module CompareXML
228
228
  def compareTextNodes(n1, n2, opts, errors, status = EQUIVALENT)
229
229
  return true if opts[:ignore_text_nodes]
230
230
  t1, t2 = n1.content, n2.content
231
- t1, t2 = squeeze(t1), squeeze(t2) if opts[:squeeze_whitespace]
231
+ t1, t2 = collapse(t1), collapse(t2) if opts[:collapse_whitespace]
232
232
  unless t1 == t2
233
233
  status = UNEQUAL_TEXT_CONTENTS
234
234
  errors << [nodePath(n1.parent), t1, status, t2, nodePath(n2.parent)] if opts[:verbose]
@@ -362,7 +362,7 @@ module CompareXML
362
362
  #
363
363
  def nodeExcluded?(n, opts)
364
364
  return true if n.is_a?(Nokogiri::XML::Comment) && opts[:ignore_comments]
365
- return true if n.is_a?(Nokogiri::XML::Text) && (opts[:ignore_text_nodes] || squeeze(n.content).empty?)
365
+ return true if n.is_a?(Nokogiri::XML::Text) && (opts[:ignore_text_nodes] || collapse(n.content).empty?)
366
366
  opts[:ignore_nodes].each do |css|
367
367
  return true if n.xpath('../*').css(css).include?(n)
368
368
  end
@@ -435,14 +435,14 @@ module CompareXML
435
435
 
436
436
 
437
437
  ##
438
- # Strips the whitespace (from beginning and end) and squeezes it,
439
- # i.e. multiple spaces, new lines and tabs are all squeezed to a single space.
438
+ # Strips the whitespace (from beginning and end) and collapses it,
439
+ # i.e. multiple spaces, new lines and tabs are all collapsed to a single space.
440
440
  #
441
- # @param [String] text string to squeeze
441
+ # @param [String] text string to collapse
442
442
  #
443
- # @return squeezed string
443
+ # @return collapsed string
444
444
  #
445
- def squeeze(text)
445
+ def collapse(text)
446
446
  text = text.to_s unless text.is_a? String
447
447
  text.strip.gsub(/\s+/, ' ')
448
448
  end
@@ -1,3 +1,3 @@
1
1
  module CompareXML
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compare-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Kononov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.11'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '11.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '11.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.6'
55
55
  description: CompareXML is a fast, lightweight and feature-rich tool that will solve
@@ -61,7 +61,7 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - ".gitignore"
64
+ - .gitignore
65
65
  - Gemfile
66
66
  - LICENSE.txt
67
67
  - README.md
@@ -71,7 +71,7 @@ files:
71
71
  - compare-xml.gemspec
72
72
  - lib/compare-xml.rb
73
73
  - lib/compare-xml/version.rb
74
- homepage: https://github.com/vkononov/compare-xml-xml
74
+ homepage: https://github.com/vkononov/compare-xml
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}
@@ -81,17 +81,17 @@ require_paths:
81
81
  - lib
82
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ">="
84
+ - - '>='
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ">="
89
+ - - '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.5.2
94
+ rubygems_version: 2.6.2
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: A customizable tool that compares two instances of Nokogiri::XML::Node for