Sha256: 87d2f6f306c9c40b5a862851861945fc66ec7aafc0a65735dd4de5ec0af4611f
Contents?: true
Size: 1.91 KB
Versions: 1
Compression:
Stored size: 1.91 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true require "code_clone_detector" require 'ripper' code = [] Dir.glob('**/*') do |file_name| if file_name.include?('.rb') File.open(file_name, 'r') do |file| file_content = file.read code.push([file_name.to_s, Ripper.lex(file_content)]) end end end max = 0 sx = 0 ex = 0 sy = 0 ey = 0 index1 = 0 index2 = 0 (0..code.size - 2).each do |a| (a + 1..code.size - 1).each do |b| array = [] x = 0 code[a][1].each do |i| array.push([]) code[b][1].each do |j| if i[2] == j[2] array[x].push(1) else array[x].push(0) end end x += 1 end tmp_max = 0 tmp_sx = 0 tmp_ex = 0 tmp_sy = 0 tmp_ey = 0 array.size.times do |i| array[i].size.times do |j| next unless array[i - 1][j - 1].nil? || array[i - 1][j - 1].zero? next unless array[i][j] == 1 maxv = 1 x = j y = i while !array[y + 1].nil? && !array[y + 1][x + 1].nil? && array[y + 1][x + 1] == 1 maxv += 1 x += 1 y += 1 end next unless maxv > tmp_max tmp_max = maxv tmp_sx = j tmp_ex = x tmp_sy = i tmp_ey = y end end next unless tmp_max > max max = tmp_max sx = tmp_sx ex = tmp_ex sy = tmp_sy ey = tmp_ey index1 = a index2 = b end end file_1_name = code[index1][0] file1 = code[index1][1] file_2_name = code[index2][0] file2 = code[index2][1] print "#{file_1_name}:" print "#{file1[sy][0][0]},#{file1[sy][0][1]} ~ #{file1[ey][0][0]},#{file1[ey][0][1]}\n" code[index1][1][sy..ey].transpose[2].each do |i| print i end puts '===============================\n\n' print "#{file_2_name}:" print "#{file2[sx][0][0]},#{file2[sx][0][1]} ~ #{file2[ex][0][0]},#{file2[ex][0][1]}\n" code[index2][1][sx..ex].transpose[2].each do |i| print i end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
code_clone_detector-1.0.2 | exe/code_clone_detector |