gry 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gry/cli.rb +3 -2
- data/lib/gry/congress.rb +6 -2
- data/lib/gry/formatter.rb +23 -8
- data/lib/gry/option.rb +3 -1
- data/lib/gry/version.rb +1 -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: 2c1bd8a42dbd705ae82a96c17fd3a91333ee52c5
|
4
|
+
data.tar.gz: 6b6b7bfbb3be43b5861a4e3dc99856e394c7348e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf28029f72d0bf2706218ea7acd46f9a57626823513b57c25b58caf5485bbb6985a0cda2be5708c44be22068e2a2483336a7f14819ea36461f911ad1eed51a94
|
7
|
+
data.tar.gz: b7e0925469a617efcc20ed4c455d9f8edbee75256aed64eb3b99c012de555dbe8f20789606d5a7f9a7b8284889bc8413bdfabb3bc4354919b2adddefd8d5aebd
|
data/lib/gry/cli.rb
CHANGED
@@ -26,9 +26,10 @@ module Gry
|
|
26
26
|
)
|
27
27
|
laws = bills.map do |cop_name, bill|
|
28
28
|
congress.discuss(cop_name, bill)
|
29
|
-
end
|
29
|
+
end
|
30
30
|
|
31
|
-
|
31
|
+
fmt = Formatter.new(display_disabled_cops: opt.display_disabled_cops)
|
32
|
+
writer.puts fmt.format(laws)
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
data/lib/gry/congress.rb
CHANGED
@@ -14,6 +14,11 @@ module Gry
|
|
14
14
|
# }
|
15
15
|
# @return [Law]
|
16
16
|
def discuss(name, bill)
|
17
|
+
letter = letter(bill)
|
18
|
+
Law.new(name, bill, letter)
|
19
|
+
end
|
20
|
+
|
21
|
+
def letter(bill)
|
17
22
|
# [[conf, count], ...]
|
18
23
|
sorted = bill.sort_by{|_conf, count| count}
|
19
24
|
min_count = sorted.first.last
|
@@ -22,8 +27,7 @@ module Gry
|
|
22
27
|
second_count = sorted[1].last
|
23
28
|
return nil if second_count - min_count < @min_difference
|
24
29
|
|
25
|
-
|
26
|
-
Law.new(name, bill, letter)
|
30
|
+
sorted.first.first
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
data/lib/gry/formatter.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
module Gry
|
2
|
-
|
2
|
+
class Formatter
|
3
|
+
def initialize(display_disabled_cops:)
|
4
|
+
@display_disabled_cops = display_disabled_cops
|
5
|
+
end
|
6
|
+
|
3
7
|
# @param gry_result [Array<Law>]
|
4
8
|
# @return [String] a yaml string
|
5
|
-
def
|
9
|
+
def format(laws)
|
6
10
|
confs = laws.map do |law|
|
7
|
-
|
8
|
-
|
11
|
+
if law.letter
|
12
|
+
letter = {law.name => law.letter}
|
13
|
+
else
|
14
|
+
if @display_disabled_cops
|
15
|
+
letter = {law.name => {'Enabled' => false}}
|
16
|
+
else
|
17
|
+
next
|
18
|
+
end
|
19
|
+
end
|
20
|
+
comment = to_comment(law.bill)
|
21
|
+
yaml = to_yaml(letter)
|
22
|
+
comment + yaml
|
9
23
|
end.compact
|
10
24
|
|
11
25
|
to_yaml(RubocopAdapter.config_base) +
|
@@ -13,13 +27,14 @@ module Gry
|
|
13
27
|
confs.join("\n")
|
14
28
|
end
|
15
29
|
|
16
|
-
private_class_method
|
17
30
|
|
18
|
-
|
31
|
+
private
|
32
|
+
|
33
|
+
def to_yaml(hash)
|
19
34
|
YAML.dump(hash)[4..-1]
|
20
35
|
end
|
21
36
|
|
22
|
-
def
|
37
|
+
def to_comment(set_count)
|
23
38
|
set_count.map do |setting, count|
|
24
39
|
x = setting
|
25
40
|
.reject{|key, _| key == 'Enabled'}
|
@@ -29,7 +44,7 @@ module Gry
|
|
29
44
|
end.join
|
30
45
|
end
|
31
46
|
|
32
|
-
def
|
47
|
+
def offenses(count)
|
33
48
|
if count > 1
|
34
49
|
'offenses'
|
35
50
|
else
|
data/lib/gry/option.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Gry
|
2
2
|
class Option
|
3
|
-
attr_reader :args, :process, :version, :fast, :max_count, :min_difference
|
3
|
+
attr_reader :args, :process, :version, :fast, :max_count, :min_difference, :display_disabled_cops
|
4
4
|
|
5
5
|
def initialize(argv)
|
6
6
|
opt = OptionParser.new
|
@@ -9,6 +9,7 @@ module Gry
|
|
9
9
|
@fast = true
|
10
10
|
@max_count = 10
|
11
11
|
@min_difference = 10
|
12
|
+
@display_disabled_cops = false
|
12
13
|
|
13
14
|
opt.banner = 'Usage: gry [options] [Cop1, Cop2, ...]'
|
14
15
|
|
@@ -18,6 +19,7 @@ module Gry
|
|
18
19
|
opt.on('--[no-]fast', 'Run only fast cops. Default: true') {|v| @fast = v}
|
19
20
|
opt.on('--max-count=10', 'Upper limit of issues.') {|v| @max_count = v.to_i}
|
20
21
|
opt.on('--min-difference=10', 'Lower limit of issues number difference') {|v| @min_difference = v.to_i}
|
22
|
+
opt.on('--display-disabled-cops', 'Display disabled cops') {|v| @display_disabled_cops = v}
|
21
23
|
|
22
24
|
@args = opt.parse(argv)
|
23
25
|
end
|
data/lib/gry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|