tdiff 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ### 0.3.0 / 2010-11-15
2
+
3
+ * Changed {TDiff#tdiff_equal} to compare `self` with another node.
4
+
1
5
  ### 0.2.0 / 2010-11-14
2
6
 
3
7
  * Added {TDiff::Unordered}.
data/README.md CHANGED
@@ -29,22 +29,22 @@ Diff two HTML documents:
29
29
 
30
30
  include TDiff
31
31
 
32
- def tdiff_each_child(node,&block)
33
- node.children.each(&block)
34
- end
35
-
36
- def tdiff_equal(node1,node2)
37
- if (node1.text? && node2.text?)
38
- node1.text == node2.text
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
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- gem 'ore-tasks', '~> 0.2.0'
5
+ gem 'ore-tasks', '~> 0.3.0'
6
6
  require 'ore/tasks'
7
7
 
8
8
  Ore::Tasks.new
@@ -1,5 +1,5 @@
1
1
  name: tdiff
2
- version: 0.2.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.2.0
15
+ ore-tasks: ~> 0.3.0
16
16
  rspec: ~> 2.1.0
17
17
  yard: ~> 0.6.0
@@ -18,19 +18,16 @@ module TDiff
18
18
  end
19
19
 
20
20
  #
21
- # Default method which compares two nodes.
21
+ # Default method which compares nodes.
22
22
  #
23
- # @param [Object] original_node
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 two nodes are equal.
27
+ # Specifies whether the nodes are equal.
31
28
  #
32
- def tdiff_equal(original_node,new_node)
33
- original_node == new_node
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(self,tree)
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(xi,yj)
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(xi,yj))
98
+ if (i != -1 && j != -1 && xi.tdiff_equal(yj))
102
99
  changes.unshift [' ', xi]
103
100
  unchanged.unshift [xi, yj]
104
101
 
@@ -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(self,tree)
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(xi,yj))
55
+ if (!unchanged.has_value?(yj) && xi.tdiff_equal(yj))
56
56
  unchanged[xi] = yj
57
57
  changes << [i, ' ', xi]
58
58
  break
@@ -9,8 +9,8 @@ class Node < Struct.new(:name, :children)
9
9
  node.children.each(&block)
10
10
  end
11
11
 
12
- def tdiff_equal(node1,node2)
13
- node1.name == node2.name
12
+ def tdiff_equal(node)
13
+ self.name == node.name
14
14
  end
15
15
 
16
16
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.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-14 00:00:00 -08:00
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
- - 2
30
+ - 3
31
31
  - 0
32
- version: 0.2.0
32
+ version: 0.3.0
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency