File tree Expand file tree Collapse file tree 4 files changed +14
-16
lines changed Expand file tree Collapse file tree 4 files changed +14
-16
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ gem "octokit"
14
14
gem "puma"
15
15
gem "tilt"
16
16
17
- gem "diff-lcs "
17
+ gem "diffy "
18
18
gem "launchy"
19
19
gem "netrc"
20
20
gem "nokogiri"
Original file line number Diff line number Diff line change 80
80
database_cleaner (1.8.5 )
81
81
debug_inspector (0.0.3 )
82
82
diff-lcs (1.4.4 )
83
+ diffy (3.4.0 )
83
84
dotenv (2.7.6 )
84
85
dotenv-rails (2.7.6 )
85
86
dotenv (= 2.7.6 )
@@ -310,7 +311,7 @@ DEPENDENCIES
310
311
better_errors
311
312
binding_of_caller
312
313
database_cleaner
313
- diff-lcs
314
+ diffy
314
315
dotenv-rails
315
316
elasticsearch (= 2.0.2 )
316
317
fabrication
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
- require "diff/lcs"
4
3
require "pp"
5
4
require "searchable"
5
+ require "diffy"
6
6
7
7
# t.text :blob_sha
8
8
# t.text :plain
Original file line number Diff line number Diff line change @@ -24,21 +24,18 @@ class DocVersion < ApplicationRecord
24
24
# 2: 8 - (add + sub)
25
25
def diff ( doc_version )
26
26
begin
27
- to = self . doc . plain . split ( "\n " )
28
- from = doc_version . doc . plain . split ( "\n " )
29
- total = adds = mins = 0
30
- diff = Diff ::LCS . diff ( to , from )
31
- diff . first . each do |change |
32
- adds += 1 if change . action == "+"
33
- mins += 1 if change . action == "-"
34
- total += 1
35
- end
36
- if total > 8
27
+ diff_out = Diffy ::Diff . new ( self . doc . plain , doc_version . doc . plain )
28
+ first_chars = diff_out . to_s . gsub ( /(.)[^\n ]*\n / , '\1' )
29
+ adds = first_chars . count ( "+" )
30
+ mins = first_chars . count ( "-" )
31
+ total = mins + adds
32
+ if total > 8
37
33
min = ( 8.0 / total )
38
- adds = ( adds * min ) . floor
39
- mins = ( mins * min ) . floor
34
+ adds = ( adds * min ) . round
35
+ mins = ( mins * min ) . round
36
+ total = 8
40
37
end
41
- [ adds , mins , ( 8 - total ) ]
38
+ [ adds , mins , 8 - total ]
42
39
rescue
43
40
[ 0 , 0 , 8 ]
44
41
end
You can’t perform that action at this time.
0 commit comments