xrt 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xrt/command/lcs.rb +28 -8
- data/lib/xrt/version.rb +1 -1
- data/test/test-command-lcs.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16821e98381373b1d22d09101636a83bb04ab394
|
4
|
+
data.tar.gz: 8e7fd66dcc9fd8ab7a18b53bc94b567aa6bfe30c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6be31df8e00727bffb709e563a61ffd806d7cc0d1c26f1217f2c2fa56fbe46b325a4d5cbc79420f09d135a36f1464bcfefcd9fbd8f8d7667e56ca74535d775ab
|
7
|
+
data.tar.gz: 95c192151307f20bb24e3daae234050a5efda6d86475565cc65972bb06af94f837631ad77775c820068f5022e8f32a08b12ec0ae15e0c55c9cfba8fe7d863c26
|
data/lib/xrt/command/lcs.rb
CHANGED
@@ -6,7 +6,13 @@ module XRT
|
|
6
6
|
def execute(*files)
|
7
7
|
lcs = collect(*files)
|
8
8
|
if lcs.length > 0
|
9
|
-
|
9
|
+
report = lcs.map{|statement|
|
10
|
+
header = "### Seen #{statement[:count]} times, size: #{statement[:code].length}, mass: #{statement[:mass]}"
|
11
|
+
list = statement[:locations].map{|location| "- #{location}" }.join("\n")
|
12
|
+
quoted_code = ['```html', statement[:code], '```'].join("\n")
|
13
|
+
[header, quoted_code, list].join("\n\n")
|
14
|
+
}
|
15
|
+
puts report.join("\n\n")
|
10
16
|
true
|
11
17
|
else
|
12
18
|
false
|
@@ -14,14 +20,28 @@ module XRT
|
|
14
20
|
end
|
15
21
|
|
16
22
|
def collect(*files)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
statements_hash = {}
|
24
|
+
|
25
|
+
files.each{|file|
|
26
|
+
next unless File.file? file
|
27
|
+
statements(file).each{|statement|
|
28
|
+
statements_hash[statement] ||= []
|
29
|
+
statements_hash[statement] << file
|
30
|
+
}
|
31
|
+
}
|
21
32
|
|
22
|
-
|
23
|
-
|
24
|
-
|
33
|
+
statements_hash.each_pair.map{|k, v|
|
34
|
+
{
|
35
|
+
code: k,
|
36
|
+
locations: v.sort,
|
37
|
+
count: v.length,
|
38
|
+
mass: k.length * v.length,
|
39
|
+
}
|
40
|
+
}.delete_if{|statement|
|
41
|
+
statement[:count] == 1
|
42
|
+
}.sort_by{|statement|
|
43
|
+
statement[:mass]
|
44
|
+
}.reverse
|
25
45
|
end
|
26
46
|
|
27
47
|
def statements(file)
|
data/lib/xrt/version.rb
CHANGED
data/test/test-command-lcs.rb
CHANGED
@@ -10,7 +10,14 @@ class TestCommandLCS < Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
command = XRT::Command::LCS.new
|
12
12
|
lcs = command.collect(Pathname(dir).join('if1.pm').to_s, Pathname(dir).join('if2.pm').to_s)
|
13
|
-
assert_equal [
|
13
|
+
assert_equal [
|
14
|
+
{
|
15
|
+
code: %q{[% IF 1 %]nested[% END %]},
|
16
|
+
count: 2,
|
17
|
+
locations: [ Pathname(dir).join('if1.pm').to_s, Pathname(dir).join('if2.pm').to_s ],
|
18
|
+
mass: 50,
|
19
|
+
}
|
20
|
+
], lcs
|
14
21
|
}
|
15
22
|
end
|
16
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xrt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hitode909
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|