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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd3b9dd012073b47b0a1bf0109540273f16d8f5d
4
- data.tar.gz: caf93a2e9702add56ff30b94f8165acf399c0741
3
+ metadata.gz: 16821e98381373b1d22d09101636a83bb04ab394
4
+ data.tar.gz: 8e7fd66dcc9fd8ab7a18b53bc94b567aa6bfe30c
5
5
  SHA512:
6
- metadata.gz: 3b6276557387abf00c81765fdf85ccb81b7dfa983af136306190a9a603f6141845702e2f21ae3851b3628919466c692fe0be5dcf44fe751c9e4c483a3ced9862
7
- data.tar.gz: 18a297a71be188b03114e32e8e4f74e1ed3ad846e198758657b45cbf7b18e45c108a5661be83d2d922b7484262cdc06e02cc4d8d9eee26214ea38ba9497dc1ba
6
+ metadata.gz: 6be31df8e00727bffb709e563a61ffd806d7cc0d1c26f1217f2c2fa56fbe46b325a4d5cbc79420f09d135a36f1464bcfefcd9fbd8f8d7667e56ca74535d775ab
7
+ data.tar.gz: 95c192151307f20bb24e3daae234050a5efda6d86475565cc65972bb06af94f837631ad77775c820068f5022e8f32a08b12ec0ae15e0c55c9cfba8fe7d863c26
@@ -6,7 +6,13 @@ module XRT
6
6
  def execute(*files)
7
7
  lcs = collect(*files)
8
8
  if lcs.length > 0
9
- puts lcs.join("\n---\n")
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
- products = statements(files.shift)
18
- while files.length > 0
19
- products = products.product(statements(files.shift))
20
- end
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
- products.select{|pairs|
23
- pairs.flatten.uniq.length == 1
24
- }.map{|pairs| pairs.first }.sort_by{|s| s.length}
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
@@ -1,3 +1,3 @@
1
1
  module Xrt
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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 [%q{[% IF 1 %]nested[% END %]}], lcs
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.3
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-30 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler