equivalent-xml 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/equivalent-xml.rb +18 -4
  2. metadata +3 -3
@@ -1,16 +1,25 @@
1
- module EquivalentXml
2
-
3
1
  require 'nokogiri'
4
2
 
3
+ module EquivalentXml
4
+
5
5
  class << self
6
6
 
7
7
  DEFAULT_OPTS = { :element_order => false, :normalize_whitespace => true }
8
8
 
9
+ # Determine if two XML documents or nodes are equivalent
10
+ #
11
+ # @param [Nokogiri::XML::Node] node_1 The first top-level XML node to compare
12
+ # @param [Nokogiri::XML::Node] node_2 The secton top-level XML node to compare
13
+ # @param [Hash] opts Options that determine how certain comparisons are evaluated
14
+ # @option opts [Boolean] :element_order (false) Child elements must occur in the same order to be considered equivalent
15
+ # @option opts [Boolean] :normalize_whitespace (true) Collapse whitespace within Text nodes before comparing
16
+ # @yield [n1,n2,result] The two nodes currently being evaluated, and whether they are considered equivalent. The block can return true or false to override the default evaluation
17
+ # @return [Boolean] true or false
9
18
  def equivalent?(node_1, node_2, opts = {}, &block)
10
19
  opts = DEFAULT_OPTS.merge(opts)
11
- self.compare_nodes(self.as_node(node_1), self.as_node(node_2), opts, &block)
20
+ self.compare_nodes(as_node(node_1), as_node(node_2), opts, &block)
12
21
  end
13
-
22
+
14
23
  def compare_nodes(node_1, node_2, opts, &block)
15
24
  result = nil
16
25
  if [node_1, node_2].any? { |node| not node.respond_to?(:node_type) }
@@ -109,6 +118,10 @@ require 'nokogiri'
109
118
  return local_set_2.length == 0
110
119
  end
111
120
 
121
+ # Determine if two nodes are in the same effective Namespace
122
+ #
123
+ # @param [Nokogiri::XML::Node OR String] node_1 The first node to test
124
+ # @param [Nokogiri::XML::Node OR String] node_2 The second node to test
112
125
  def same_namespace?(node_1, node_2)
113
126
  args = [node_1,node_2]
114
127
 
@@ -126,6 +139,7 @@ require 'nokogiri'
126
139
  return href1 == href2
127
140
  end
128
141
 
142
+ private
129
143
  def as_node(data)
130
144
  if data.respond_to?(:node_type)
131
145
  return data
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: equivalent-xml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 4
10
- version: 0.2.4
9
+ - 5
10
+ version: 0.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael B. Klein