tdiff 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +4 -0
- data/README.md +11 -11
- data/Rakefile +1 -1
- data/gemspec.yml +2 -2
- data/lib/tdiff/tdiff.rb +8 -11
- data/lib/tdiff/unordered.rb +2 -2
- data/spec/classes/node.rb +2 -2
- metadata +5 -5
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -29,22 +29,22 @@ Diff two HTML documents:
|
|
29
29
|
|
30
30
|
include TDiff
|
31
31
|
|
32
|
-
def
|
33
|
-
node.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
elsif (node1.respond_to?(:root) && node2.respond_to?(:root))
|
40
|
-
tdiff_equal(node1.root,node2.root)
|
41
|
-
elsif (node1.respond_to?(:name) && node2.respond_to?(:name))
|
42
|
-
node1.name == node2.name
|
32
|
+
def tdiff_equal(node)
|
33
|
+
if (self.text? && node.text?)
|
34
|
+
self.text == node.text
|
35
|
+
elsif (self.respond_to?(:root) && node.respond_to?(:root))
|
36
|
+
self.root.tdiff_equal(node.root)
|
37
|
+
elsif (self.respond_to?(:name) && node.respond_to?(:name))
|
38
|
+
self.name == node.name
|
43
39
|
else
|
44
40
|
false
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
44
|
+
def tdiff_each_child(node,&block)
|
45
|
+
node.children.each(&block)
|
46
|
+
end
|
47
|
+
|
48
48
|
end
|
49
49
|
|
50
50
|
doc1 = Nokogiri::HTML('<div><p>one</p> <p>three</p></div>')
|
data/Rakefile
CHANGED
data/gemspec.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
name: tdiff
|
2
|
-
version: 0.
|
2
|
+
version: 0.3.0
|
3
3
|
summary: Calculates the differences between two tree-like structures.
|
4
4
|
description:
|
5
5
|
Calculates the differences between two tree-like structures. Similar to
|
@@ -12,6 +12,6 @@ homepage: http://github.com/postmodern/tdiff
|
|
12
12
|
has_yard: true
|
13
13
|
|
14
14
|
development_dependencies:
|
15
|
-
ore-tasks: ~> 0.
|
15
|
+
ore-tasks: ~> 0.3.0
|
16
16
|
rspec: ~> 2.1.0
|
17
17
|
yard: ~> 0.6.0
|
data/lib/tdiff/tdiff.rb
CHANGED
@@ -18,19 +18,16 @@ module TDiff
|
|
18
18
|
end
|
19
19
|
|
20
20
|
#
|
21
|
-
# Default method which compares
|
21
|
+
# Default method which compares nodes.
|
22
22
|
#
|
23
|
-
# @param [Object]
|
24
|
-
# A node from the original tree.
|
25
|
-
#
|
26
|
-
# @param [Object] new_node
|
23
|
+
# @param [Object] node
|
27
24
|
# A node from the new tree.
|
28
25
|
#
|
29
26
|
# @return [Boolean]
|
30
|
-
# Specifies whether the
|
27
|
+
# Specifies whether the nodes are equal.
|
31
28
|
#
|
32
|
-
def tdiff_equal(
|
33
|
-
|
29
|
+
def tdiff_equal(node)
|
30
|
+
self == node
|
34
31
|
end
|
35
32
|
|
36
33
|
#
|
@@ -55,7 +52,7 @@ module TDiff
|
|
55
52
|
return enum_for(:tdiff,tree) unless block
|
56
53
|
|
57
54
|
# check if the nodes differ
|
58
|
-
unless tdiff_equal(
|
55
|
+
unless tdiff_equal(tree)
|
59
56
|
yield '-', self
|
60
57
|
yield '+', tree
|
61
58
|
return self
|
@@ -67,7 +64,7 @@ module TDiff
|
|
67
64
|
|
68
65
|
x.each_with_index do |xi,i|
|
69
66
|
y.each_with_index do |yj,j|
|
70
|
-
c[i][j] = if tdiff_equal(
|
67
|
+
c[i][j] = if xi.tdiff_equal(yj)
|
71
68
|
c[i-1][j-1] + 1
|
72
69
|
else
|
73
70
|
if c[i][j-1] > c[i-1][j]
|
@@ -98,7 +95,7 @@ module TDiff
|
|
98
95
|
yj, j = next_child[y_backtrack]
|
99
96
|
|
100
97
|
until (i == -1 && j == -1)
|
101
|
-
if (i != -1 && j != -1 && tdiff_equal(
|
98
|
+
if (i != -1 && j != -1 && xi.tdiff_equal(yj))
|
102
99
|
changes.unshift [' ', xi]
|
103
100
|
unchanged.unshift [xi, yj]
|
104
101
|
|
data/lib/tdiff/unordered.rb
CHANGED
@@ -38,7 +38,7 @@ module TDiff
|
|
38
38
|
return enum_for(:tdiff_unordered,tree) unless block
|
39
39
|
|
40
40
|
# check if the nodes differ
|
41
|
-
unless tdiff_equal(
|
41
|
+
unless tdiff_equal(tree)
|
42
42
|
yield '-', self
|
43
43
|
yield '+', tree
|
44
44
|
return self
|
@@ -52,7 +52,7 @@ module TDiff
|
|
52
52
|
|
53
53
|
x.each_with_index do |xi,i|
|
54
54
|
y.each_with_index do |yj,j|
|
55
|
-
if (!unchanged.has_value?(yj) && tdiff_equal(
|
55
|
+
if (!unchanged.has_value?(yj) && xi.tdiff_equal(yj))
|
56
56
|
unchanged[xi] = yj
|
57
57
|
changes << [i, ' ', xi]
|
58
58
|
break
|
data/spec/classes/node.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Postmodern
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-15 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,9 +27,9 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 0
|
30
|
-
-
|
30
|
+
- 3
|
31
31
|
- 0
|
32
|
-
version: 0.
|
32
|
+
version: 0.3.0
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|