CodeDiff 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/codediff.rb +90 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0b85c1c1e888b0926a66acdda805864fa156ea74
|
4
|
+
data.tar.gz: b0e61548eb46fc83469ebf1bd7147b7e6601e1d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e8d26cccfc6c0587717ff3f3129a3bcded1c914600e961c3eb926cb84fa5ec08677ad52d7bdcdc5108fc3ae664e1f39410b8d494f03b534de6f4c2e90bea83b
|
7
|
+
data.tar.gz: 56348541ef900bf28c4d6f0c484750b68aa3f32bdaa08edb515bd711ae71815204a0a6877e7884116fb81701e8775074f0e584f3caa754aa8f495b6916fad619
|
data/lib/codediff.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'levenshtein'
|
3
|
+
require 'Diffy'
|
4
|
+
|
5
|
+
class CodeDiff
|
6
|
+
|
7
|
+
def initialize()
|
8
|
+
@res = Hash.new
|
9
|
+
@res["additions"] = 0
|
10
|
+
@res["subtractions"] = 0
|
11
|
+
@res["comment_additions"] = 0
|
12
|
+
@res["comment_subtraction"] = 0
|
13
|
+
@res["accumulated_distance"] = 0
|
14
|
+
@res["percent_change"] = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
# Execute the given file using the associate app
|
18
|
+
public
|
19
|
+
def run old_file, new_file
|
20
|
+
|
21
|
+
@res["old_file_lines"] = File.foreach(old_file).count
|
22
|
+
@res["new_file_lines"] = File.foreach(new_file).count
|
23
|
+
|
24
|
+
cmd = "diff -y --left-column " + new_file + " " + old_file
|
25
|
+
`#{cmd}`.each_line { |line|
|
26
|
+
line = line.chomp
|
27
|
+
if !line.end_with?("(")
|
28
|
+
lines = line.split("|")
|
29
|
+
if lines.size > 1
|
30
|
+
@res["accumulated_distance"] += Levenshtein.normalized_distance lines[0].chomp, lines[1].chomp
|
31
|
+
end
|
32
|
+
|
33
|
+
lines = line.split("<")
|
34
|
+
if lines.size > 1
|
35
|
+
@res["accumulated_distance"] += Levenshtein.normalized_distance lines[0].chomp, lines[1].chomp
|
36
|
+
end
|
37
|
+
|
38
|
+
lines = line.split(">")
|
39
|
+
if lines.size > 1
|
40
|
+
@res["accumulated_distance"] += Levenshtein.normalized_distance lines[0].chomp, lines[1].chomp
|
41
|
+
end
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
# count of different strings
|
46
|
+
Diffy::Diff.new(new_file, old_file, :source => 'files').each { |item|
|
47
|
+
# remove white spaces
|
48
|
+
item = item.gsub(/\s+/, "")
|
49
|
+
|
50
|
+
# ignore space lines
|
51
|
+
next if item.size == 1
|
52
|
+
|
53
|
+
# see if changed starts with comment
|
54
|
+
case item[0]
|
55
|
+
when "+"
|
56
|
+
case item[1]
|
57
|
+
when "#", "/", "*"
|
58
|
+
@res["comment_additions"] += 1
|
59
|
+
else
|
60
|
+
@res["additions"] += 1
|
61
|
+
end
|
62
|
+
when "-"
|
63
|
+
case item[1]
|
64
|
+
when "#"
|
65
|
+
@res["comment_subtraction"] += 1
|
66
|
+
else
|
67
|
+
@res["subtractions"] += 1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
diff = [@res["additions"], @res["subtractions"]].max
|
74
|
+
average = (@res["old_file_lines"] + @res["new_file_lines"]) / 2.0
|
75
|
+
@res["percent_change"] = diff / average * 100
|
76
|
+
|
77
|
+
return @res
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
public
|
82
|
+
def print_results
|
83
|
+
puts "accumulated normalized distance:", @res["accumulated_distance"] # chars
|
84
|
+
puts "+comments:", @res["comment_additions"]
|
85
|
+
puts "-comments:", @res["comment_subtraction"]
|
86
|
+
puts "+code:", @res["additions"]
|
87
|
+
puts "-code:", @res["subtractions"]
|
88
|
+
puts "Percent file change: ", @res["percent_change"]
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: CodeDiff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Gorbaty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Given two diles gives you a diff of comments, code, percentage change
|
14
|
+
and accumulative string distance
|
15
|
+
email: serg.gorbaty@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/codediff.rb
|
21
|
+
homepage: http://rubygems.org/gems/codediff
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.4.5
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Code files' differ
|
45
|
+
test_files: []
|