leaderbrag 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +19 -8
- data/.travis.yml +2 -0
- data/lib/leaderbrag/cli.rb +70 -16
- data/lib/leaderbrag/leader.rb +25 -0
- data/lib/leaderbrag/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: a290db98c22b0314fc48551b7d319ea8b3a59817
|
4
|
+
data.tar.gz: e8209617515bc0e5d8341149e2ad9c2e1e5044c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cae3372bfd3175481c84b7c900e950cfd194985b6a3266d9f208cc0d2c3814a3db0c1d76fc4218e16e584d55f7357bfe0bfe4b44a9f89a3b811bc2f3e850b69c
|
7
|
+
data.tar.gz: 4cc9b47a6969af72376c5126728bb6f5944e892a8bfc6068008467df75aa144fb667290fa8538216977bbee4f3d22186c1f089b957e9f42b18f442eda79d0dc1
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2019-06-
|
3
|
+
# on 2019-06-22 22:54:35 -0500 using RuboCop version 0.71.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -12,19 +12,30 @@ Lint/HandleExceptions:
|
|
12
12
|
Exclude:
|
13
13
|
- 'Rakefile'
|
14
14
|
|
15
|
-
# Offense count:
|
15
|
+
# Offense count: 6
|
16
16
|
Metrics/AbcSize:
|
17
|
-
Max:
|
17
|
+
Max: 43
|
18
18
|
|
19
19
|
# Offense count: 1
|
20
|
+
# Configuration parameters: CountComments.
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Max: 139
|
23
|
+
|
24
|
+
# Offense count: 3
|
20
25
|
Metrics/CyclomaticComplexity:
|
21
|
-
Max:
|
26
|
+
Max: 10
|
22
27
|
|
23
|
-
# Offense count:
|
28
|
+
# Offense count: 5
|
24
29
|
# Configuration parameters: CountComments, ExcludedMethods.
|
25
30
|
Metrics/MethodLength:
|
26
|
-
Max:
|
31
|
+
Max: 33
|
27
32
|
|
28
|
-
# Offense count:
|
33
|
+
# Offense count: 3
|
29
34
|
Metrics/PerceivedComplexity:
|
30
|
-
Max:
|
35
|
+
Max: 10
|
36
|
+
|
37
|
+
# Offense count: 1
|
38
|
+
# Configuration parameters: MinBodyLength.
|
39
|
+
Style/GuardClause:
|
40
|
+
Exclude:
|
41
|
+
- 'lib/leaderbrag/cli.rb'
|
data/.travis.yml
CHANGED
data/lib/leaderbrag/cli.rb
CHANGED
@@ -13,39 +13,91 @@ module Leaderbrag
|
|
13
13
|
@leader = nil
|
14
14
|
def initialize(args = [], local_options = {}, config = {})
|
15
15
|
super
|
16
|
+
if ENV['XMLSTATS_CONTACT_INFO'].nil?
|
17
|
+
warn 'Please set XMLSTATS_CONTACT_INFO environment variable.'
|
18
|
+
exit 60
|
19
|
+
elsif ENV['XMLSTATS_API_KEY'].nil?
|
20
|
+
warn 'Please set XMLSTATS_API_KEY environment variable'
|
21
|
+
exit 70
|
22
|
+
end
|
16
23
|
@leader = Leaderbrag::Leader.new
|
17
24
|
end
|
18
25
|
|
19
26
|
desc 'board', 'Lists all baseball teams with their standings'
|
27
|
+
method_option(:sort_by_league, aliases: '-l',
|
28
|
+
desc: 'Sort by league.', default: false,
|
29
|
+
type: :boolean)
|
30
|
+
method_option(:only_league, aliases: '-L', type: :string,
|
31
|
+
desc:
|
32
|
+
'Only show results for this league.',
|
33
|
+
enum: %w[AL NL])
|
34
|
+
method_option(:sort_by_division, aliases: '-d',
|
35
|
+
desc: 'Sort by league and division.'\
|
36
|
+
' Supercedes -l.',
|
37
|
+
type: :boolean)
|
38
|
+
method_option(:only_division, aliases: '-D', type: :string,
|
39
|
+
desc:
|
40
|
+
'Only show results for this division.',
|
41
|
+
enum: %w[E C W])
|
20
42
|
def board
|
21
43
|
puts 'Team Name'.ljust(23) +
|
22
|
-
'Team ID
|
23
|
-
puts '-'.ljust(
|
24
|
-
@leader.
|
44
|
+
'Team ID Win% Rank League Rank Div Rank'
|
45
|
+
puts '-'.ljust(78, '-')
|
46
|
+
teams = @leader.filter(options[:sort_by_league],
|
47
|
+
options[:sort_by_division],
|
48
|
+
options[:only_league],
|
49
|
+
options[:only_division])
|
50
|
+
teams.each do |team|
|
25
51
|
puts "#{team.first_name} #{team.last_name}:".ljust(23) +
|
26
|
-
team.team_id.ljust(22) +
|
27
|
-
team.
|
28
|
-
team.conference.ljust(
|
52
|
+
team.team_id.ljust(22) + team.win_percentage.ljust(7) +
|
53
|
+
@leader.overall_rank(team).to_s.ljust(7) +
|
54
|
+
team.conference.ljust(6) +
|
55
|
+
@leader.league_rank(team).to_s.ljust(6) +
|
56
|
+
team.division.ljust(4) + team.rank.to_s
|
29
57
|
end
|
30
58
|
end
|
31
59
|
|
32
60
|
desc 'find', 'Finds the best team in baseball'
|
33
61
|
method_option(:quiet, aliases: '-q',
|
34
|
-
desc: 'Do not print results', default: false)
|
62
|
+
desc: 'Do not print results.', default: false)
|
35
63
|
method_option(:stats, aliases: '-s',
|
36
|
-
desc: 'Include team stats in output',
|
64
|
+
desc: 'Include team stats in output.',
|
37
65
|
default: false)
|
66
|
+
method_option(:league, aliases: '-l', type: :string,
|
67
|
+
desc: 'Find the league leader rather than overall'\
|
68
|
+
' best team.',
|
69
|
+
enum: %w[AL NL])
|
70
|
+
method_option(:division, aliases: '-d', type: :string,
|
71
|
+
desc: 'Find the division leader rather than '\
|
72
|
+
'overall best team. Requires use of --league.',
|
73
|
+
enum: %w[E C W])
|
38
74
|
def find
|
39
|
-
|
75
|
+
if !options[:division].nil? && options[:league].nil?
|
76
|
+
warn 'League must be specified.'
|
77
|
+
exit 80
|
78
|
+
end
|
79
|
+
s_league = (options[:league].nil? ? nil : options[:league])
|
80
|
+
s_division = (options[:division].nil? ? nil : options[:division])
|
81
|
+
teams = @leader.filter(!options[:league].nil?, !options[:division].nil?,
|
82
|
+
s_league, s_division)
|
83
|
+
myteam = teams[0]
|
40
84
|
brag(myteam, options[:quiet], options[:stats])
|
41
85
|
end
|
42
86
|
|
43
87
|
desc 'is TEAM', 'asserts that TEAM is the best team in baseball'
|
44
|
-
method_option(:quiet, aliases: '-q',
|
88
|
+
method_option(:quiet, aliases: '-q', type: :boolean,
|
45
89
|
desc: 'Do not print results', default: false)
|
46
|
-
method_option(:stats, aliases: '-s',
|
90
|
+
method_option(:stats, aliases: '-s', type: :boolean,
|
47
91
|
desc: 'Include team stats in output',
|
48
92
|
default: false)
|
93
|
+
method_option(:league, aliases: '-l', type: :boolean,
|
94
|
+
desc: 'Check leadership of team\'s league. '\
|
95
|
+
'Only affects exit code.',
|
96
|
+
default: false)
|
97
|
+
method_option(:division, aliases: '-d', type: :boolean,
|
98
|
+
desc: 'Check leadership of team\'s division.'\
|
99
|
+
'Only affects the exit code.',
|
100
|
+
default: false)
|
49
101
|
def is?(team_id)
|
50
102
|
myteam = @leader.team(team_id)
|
51
103
|
if myteam.nil?
|
@@ -53,6 +105,13 @@ module Leaderbrag
|
|
53
105
|
exit 50
|
54
106
|
end
|
55
107
|
brag(myteam, options[:quiet], options[:stats])
|
108
|
+
if @leader.overall_leader?(myteam) ||
|
109
|
+
(options[:league] && @leader.league_leader?(myteam)) ||
|
110
|
+
(options[:division] && @leader.division_leader?(myteam))
|
111
|
+
exit 0
|
112
|
+
else
|
113
|
+
exit myteam.rank
|
114
|
+
end
|
56
115
|
end
|
57
116
|
|
58
117
|
private
|
@@ -93,11 +152,6 @@ module Leaderbrag
|
|
93
152
|
puts label.ljust(30) + myteam.send(field).to_s
|
94
153
|
end
|
95
154
|
end
|
96
|
-
if @leader.overall_leader?(myteam)
|
97
|
-
exit 0
|
98
|
-
else
|
99
|
-
exit myteam.rank
|
100
|
-
end
|
101
155
|
end
|
102
156
|
end
|
103
157
|
end
|
data/lib/leaderbrag/leader.rb
CHANGED
@@ -66,5 +66,30 @@ module Leaderbrag
|
|
66
66
|
def overall_rank(team)
|
67
67
|
@standings.find_index(team) + 1
|
68
68
|
end
|
69
|
+
|
70
|
+
def filter(sb_league = false, sb_division = false,
|
71
|
+
s_conference = nil, s_division = nil)
|
72
|
+
view = standings.sort_by do |team|
|
73
|
+
sort_items = []
|
74
|
+
sort_items << team.conference if sb_league
|
75
|
+
sort_items << team.conference if sb_division
|
76
|
+
sort_items << team.division if sb_division
|
77
|
+
sort_items << league_rank(team) if sb_league
|
78
|
+
sort_items << team.rank if sb_division
|
79
|
+
sort_items << overall_rank(team) if !sb_league && !sb_division
|
80
|
+
sort_items
|
81
|
+
end
|
82
|
+
unless s_conference.nil?
|
83
|
+
view.select! do |team|
|
84
|
+
team.conference == s_conference
|
85
|
+
end
|
86
|
+
end
|
87
|
+
unless s_division.nil?
|
88
|
+
view.select! do |team|
|
89
|
+
team.division == s_division
|
90
|
+
end
|
91
|
+
end
|
92
|
+
view
|
93
|
+
end
|
69
94
|
end
|
70
95
|
end
|
data/lib/leaderbrag/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaderbrag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Schlenk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|