leaderbrag 1.1.0 → 1.2.0

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: a290db98c22b0314fc48551b7d319ea8b3a59817
4
- data.tar.gz: e8209617515bc0e5d8341149e2ad9c2e1e5044c9
3
+ metadata.gz: 8d200b5b405a670ded0a492989e99952c21585a7
4
+ data.tar.gz: e033586e5a5770f5a6873914930b9cc26f455b0f
5
5
  SHA512:
6
- metadata.gz: cae3372bfd3175481c84b7c900e950cfd194985b6a3266d9f208cc0d2c3814a3db0c1d76fc4218e16e584d55f7357bfe0bfe4b44a9f89a3b811bc2f3e850b69c
7
- data.tar.gz: 4cc9b47a6969af72376c5126728bb6f5944e892a8bfc6068008467df75aa144fb667290fa8538216977bbee4f3d22186c1f089b957e9f42b18f442eda79d0dc1
6
+ metadata.gz: 4a35ee2a953a2a859bb4ec2430821cbb7f9fe02a3de7f8cc25832653d1a9af0419818e590ffbf153076da8943cd4c8ebae943c028b40250a5e8f1f68fb80fde4
7
+ data.tar.gz: aec9c4c76a634dad861686a7efbfbe5e4b3edf04568ba4e6dad6dae418726a33945c420b3bca618b916a327dec63a1eb1492074535dd4e8fe6134b7967e90845
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-06-22 22:54:35 -0500 using RuboCop version 0.71.0.
3
+ # on 2019-06-24 22:37:19 -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
@@ -14,28 +14,49 @@ Lint/HandleExceptions:
14
14
 
15
15
  # Offense count: 6
16
16
  Metrics/AbcSize:
17
- Max: 43
17
+ Max: 61
18
18
 
19
19
  # Offense count: 1
20
20
  # Configuration parameters: CountComments.
21
21
  Metrics/ClassLength:
22
- Max: 139
22
+ Max: 170
23
23
 
24
- # Offense count: 3
24
+ # Offense count: 4
25
25
  Metrics/CyclomaticComplexity:
26
- Max: 10
26
+ Max: 12
27
27
 
28
- # Offense count: 5
28
+ # Offense count: 6
29
29
  # Configuration parameters: CountComments, ExcludedMethods.
30
30
  Metrics/MethodLength:
31
- Max: 33
31
+ Max: 38
32
32
 
33
33
  # Offense count: 3
34
34
  Metrics/PerceivedComplexity:
35
- Max: 10
35
+ Max: 12
36
+
37
+ # Offense count: 1
38
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
39
+ # AllowedNames: io, id, to, by, on, in, at, ip, db
40
+ Naming/UncommunicativeMethodParamName:
41
+ Exclude:
42
+ - 'lib/leaderbrag/cli.rb'
36
43
 
37
44
  # Offense count: 1
38
45
  # Configuration parameters: MinBodyLength.
39
46
  Style/GuardClause:
40
47
  Exclude:
41
48
  - 'lib/leaderbrag/cli.rb'
49
+
50
+ # Offense count: 2
51
+ # Cop supports --auto-correct.
52
+ Style/IfUnlessModifier:
53
+ Exclude:
54
+ - 'lib/leaderbrag/cli.rb'
55
+ - 'lib/leaderbrag/leader.rb'
56
+
57
+ # Offense count: 3
58
+ # Cop supports --auto-correct.
59
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
60
+ # URISchemes: http, https
61
+ Metrics/LineLength:
62
+ Max: 93
data/README.md CHANGED
@@ -37,75 +37,119 @@ where XMLSTATS_REDIS_HOST is the IP of a server running [redis](https://redis.io
37
37
 
38
38
  Using the CLI is pretty straightforward.
39
39
 
40
+ All tasks accept the `--date` option which expects a date in `yyyyMMdd` format and will cause the results to reflect the given date.
41
+
42
+ ### leader find
40
43
  Use the `find` task to find the best team in baseball:
41
44
 
42
45
  ```
43
- $ leader find
46
+ $ leader find --date 20190618
47
+ On the 18th day of June, 2019:
44
48
  The Minnesota Twins are the leaders of the AL C division.
45
49
  The Minnesota Twins are the leaders of the AL.
46
50
  The Minnesota Twins are the best team in baseball.
47
51
  ```
52
+ You can also get some extra team stats with the `-s` option, and find the best team in a league or division. `leader -h find` provides the details:
53
+ ```
54
+ $ leader -h find
55
+ Usage:
56
+ leader find
57
+
58
+ Options:
59
+ -s, [--stats=STATS] # Include team stats in output.
60
+ -l, [--league=LEAGUE] # Find the league leader rather than overall best team.
61
+ # Possible values: AL, NL
62
+ -d, [--division=DIVISION] # Find the division leader rather than overall best team. Requires use of --league.
63
+ # Possible values: E, C, W
64
+ [--date=DATE] # The date for which to retrieve statistics. 'yyyyMMdd' format; default is current date. Statistics exist starting with the 2008 season.
65
+
66
+ Finds the best team in all of baseball, a league or a division.
67
+ ```
48
68
 
69
+ ### leader board
49
70
  To query about a specific team, you'll need that team's ID. Get the full leaderboard with the `board` task, which includes each team's ID:
50
71
  ```
51
72
  $ leader board
52
- Team Name Team ID Rank Win% League Div
53
- --------------------------------------------------------------------
54
- Los Angeles Dodgers: los-angeles-dodgers 1 .671 NL W
55
- Minnesota Twins: minnesota-twins 2 .649 AL C
56
- New York Yankees: new-york-yankees 3 .635 AL E
57
- Houston Astros: houston-astros 4 .632 AL W
58
- Atlanta Braves: atlanta-braves 5 .587 NL E
59
- Tampa Bay Rays: tampa-bay-rays 6 .573 AL E
60
- Chicago Cubs: chicago-cubs 7 .547 NL C
61
- Colorado Rockies: colorado-rockies 8 .541 NL W
62
- Boston Red Sox: boston-red-sox 9 .539 AL E
63
- Texas Rangers: texas-rangers 10 .533 AL W
64
- Milwaukee Brewers: milwaukee-brewers 11 .533 NL C
65
- Cleveland Indians: cleveland-indians 12 .527 AL C
66
- Philadelphia Phillies: philadelphia-phillies 13 .527 NL E
67
- Oakland Athletics: oakland-athletics 14 .526 AL W
68
- St. Louis Cardinals: st-louis-cardinals 15 .514 NL C
69
- San Diego Padres: san-diego-padres 16 .507 NL W
70
- Arizona Diamondbacks: arizona-diamondbacks 17 .500 NL W
71
- Los Angeles Angels: los-angeles-angels 18 .500 AL W
72
- Chicago White Sox: chicago-white-sox 19 .486 AL C
73
- Washington Nationals: washington-nationals 20 .486 NL E
74
- Cincinnati Reds: cincinnati-reds 21 .479 NL C
75
- New York Mets: new-york-mets 22 .474 NL E
76
- Pittsburgh Pirates: pittsburgh-pirates 23 .452 NL C
77
- San Francisco Giants: san-francisco-giants 24 .425 NL W
78
- Seattle Mariners: seattle-mariners 25 .418 AL W
79
- Detroit Tigers: detroit-tigers 26 .371 AL C
80
- Miami Marlins: miami-marlins 27 .370 NL E
81
- Toronto Blue Jays: toronto-blue-jays 28 .360 AL E
82
- Kansas City Royals: kansas-city-royals 29 .347 AL C
83
- Baltimore Orioles: baltimore-orioles 30 .280 AL E
84
- ```
85
- When asking about a team, the exit code is 0 when the requested team is the best team in baseball, otherwise it is the rank of that team in their division.
73
+ Team ID Win% W L Rank League Rank Div Rank GB Streak
74
+ -----------------------------------------------------------------------------
75
+ los-angeles-dodgers .684 54 25 1 NL 1 W 1 0.0 W6
76
+ minnesota-twins .649 50 27 2 AL 1 C 1 0.0 L1
77
+ new-york-yankees .636 49 28 3 AL 2 E 1 0.0 L1
78
+ houston-astros .620 49 30 4 AL 3 W 1 0.0 W1
79
+ atlanta-braves .590 46 32 5 NL 2 E 1 0.0 W2
80
+ tampa-bay-rays .577 45 33 6 AL 4 E 2 4.5 W1
81
+ cleveland-indians .545 42 35 7 AL 5 C 2 8.0 W3
82
+ chicago-cubs .545 42 35 8 NL 3 C 1 0.0 W1
83
+ texas-rangers .538 42 36 9 AL 6 W 2 6.5 W2
84
+ milwaukee-brewers .538 42 36 10 NL 4 C 2 0.5 W2
85
+ boston-red-sox .532 42 37 11 AL 7 E 3 8.0 L2
86
+ oakland-athletics .519 41 38 12 AL 8 W 3 8.0 L1
87
+ colorado-rockies .519 40 37 13 NL 5 W 2 13.0 L3
88
+ st-louis-cardinals .519 40 37 14 NL 6 C 3 2.0 L1
89
+ philadelphia-phillies .506 39 38 15 NL 7 E 2 6.5 L7
90
+ los-angeles-angels .494 39 40 16 AL 9 W 4 10.0 W1
91
+ arizona-diamondbacks .494 39 40 17 NL 8 W 3 15.0 W1
92
+ san-diego-padres .487 38 40 18 NL 9 W 4 15.5 L3
93
+ washington-nationals .481 37 40 19 NL 10 E 3 8.5 L2
94
+ chicago-white-sox .480 36 39 20 AL 10 C 3 13.0 L2
95
+ cincinnati-reds .474 36 40 21 NL 11 C 4 5.5 L2
96
+ new-york-mets .474 37 41 22 NL 12 E 4 9.0 L1
97
+ pittsburgh-pirates .474 36 40 23 NL 13 C 4 5.5 W4
98
+ san-francisco-giants .434 33 43 24 NL 14 W 5 19.5 L1
99
+ seattle-mariners .427 35 47 25 AL 11 W 5 15.5 W1
100
+ miami-marlins .395 30 46 26 NL 15 E 5 15.0 W4
101
+ toronto-blue-jays .372 29 49 27 AL 12 E 4 20.5 W2
102
+ detroit-tigers .356 26 47 28 AL 13 C 4 22.0 L4
103
+ kansas-city-royals .346 27 51 29 AL 14 C 5 23.5 W1
104
+ baltimore-orioles .282 22 56 30 AL 15 E 5 27.5 L1
105
+ ```
106
+ You can also sort and filter by league and division. Use `leader -h board` for details:
107
+ ```
108
+ $ leader -h board
109
+ Usage:
110
+ leader board
111
+
112
+ Options:
113
+ -l, [--sort-by-league], [--no-sort-by-league] # Sort by league.
114
+ -L, [--only-league=ONLY_LEAGUE] # Only show results for this league.
115
+ # Possible values: AL, NL
116
+ -d, [--sort-by-division], [--no-sort-by-division] # Sort by league and division. Supercedes -l.
117
+ -D, [--only-division=ONLY_DIVISION] # Only show results for this division.
118
+ # Possible values: E, C, W
119
+ [--date=DATE] # The date for which to retrieve statistics. 'yyyyMMdd' format; default is current date. Statistics exist starting with the 2008 season.
120
+
121
+ Lists baseball teams with their standings.
122
+ ```
123
+ ### leader is
124
+
125
+ Use the `is` task to determine if your favorite team is leading baseball. If it is, the exit code is 0. If not, the exit code is that team's current rank in their division.
86
126
  ```
87
127
  $ leader is minnesota-twins
128
+ Today, the 18th day of June, 2019:
88
129
  The Minnesota Twins are the leaders of the AL C division.
89
130
  The Minnesota Twins are the leaders of the AL.
90
131
  The Minnesota Twins are the best team in baseball.
91
132
  $ echo $?
92
133
  0
93
134
  $ leader is new-york-yankees
135
+ Today, the 18th day of June, 2019:
94
136
  The New York Yankees are the leaders of the AL E division.
95
137
  The New York Yankees are not the leaders of the AL. They are #2.
96
138
  The New York Yankees are not the best team in baseball. They are #3.
97
139
  $ echo $?
98
140
  1
99
141
  $ leader is seattle-mariners
142
+ Today, the 18th day of June, 2019:
100
143
  The Seattle Mariners are not the leaders of the AL W division. They are 5th.
101
144
  The Seattle Mariners are not the leaders of the AL. They are #11.
102
145
  The Seattle Mariners are not the best team in baseball. They are #25.
103
146
  $ echo $?
104
147
  5
105
148
  ```
106
- You can also get some extra stats about the team in the `is` and `find` tasks with the `-s` option:
149
+ You can also get some extra team stats with the `-s` option:
107
150
  ```
108
151
  $ leader is chicago-cubs -s
152
+ Today, the 18th day of June, 2019:
109
153
  The Chicago Cubs are the leaders of the NL C division.
110
154
  The Chicago Cubs are not the leaders of the NL. They are #3.
111
155
  The Chicago Cubs are not the best team in baseball. They are #7.
@@ -138,6 +182,21 @@ Streak total: 1
138
182
  Games played: 75
139
183
  Date: 2019-06-21
140
184
  ```
185
+ You can also limit your query to their league or division with the `-l` and `-d` options. Full help:
186
+ ```
187
+ $ leader -h is minnesota-twins
188
+ Usage:
189
+ leader is TEAM
190
+
191
+ Options:
192
+ -q, [--quiet], [--no-quiet] # Do not print results
193
+ -s, [--stats], [--no-stats] # Include team stats in output
194
+ -l, [--league], [--no-league] # Check leadership of team's league. Only affects exit code.
195
+ -d, [--division], [--no-division] # Check leadership of team's division.Only affects the exit code.
196
+ [--date=DATE] # The date for which to retrieve statistics. 'yyyyMMdd' format; default is current date. Statistics exist starting with the 2008 season.
197
+
198
+ Asserts that TEAM is the best team in baseball.
199
+ ```
141
200
 
142
201
  ## Development
143
202
 
@@ -6,7 +6,11 @@ require 'redis'
6
6
  module Leaderbrag
7
7
  # A CLI for Leaderbrag
8
8
  class CLI < Thor
9
- def self.exit_on_failure?
9
+ class_option :date, type: :string, desc: 'The date for which to retrieve '\
10
+ 'statistics. \'yyyyMMdd\' format; default is current '\
11
+ 'date. Statistics exist starting with the 2008 season.'
12
+
13
+ def self.exit_on_failure
10
14
  true
11
15
  end
12
16
 
@@ -20,10 +24,9 @@ module Leaderbrag
20
24
  warn 'Please set XMLSTATS_API_KEY environment variable'
21
25
  exit 70
22
26
  end
23
- @leader = Leaderbrag::Leader.new
24
27
  end
25
28
 
26
- desc 'board', 'Lists all baseball teams with their standings'
29
+ desc 'board', 'Lists baseball teams with their standings.'
27
30
  method_option(:sort_by_league, aliases: '-l',
28
31
  desc: 'Sort by league.', default: false,
29
32
  type: :boolean)
@@ -40,26 +43,29 @@ module Leaderbrag
40
43
  'Only show results for this division.',
41
44
  enum: %w[E C W])
42
45
  def board
43
- puts 'Team Name'.ljust(23) +
44
- 'Team ID Win% Rank League Rank Div Rank'
45
- puts '-'.ljust(78, '-')
46
+ populate
47
+ puts 'Team ID Win% W L Rank League Rank Div Rank GB Streak'
48
+ puts '-'.ljust(77, '-')
46
49
  teams = @leader.filter(options[:sort_by_league],
47
50
  options[:sort_by_division],
48
51
  options[:only_league],
49
52
  options[:only_division])
50
53
  teams.each do |team|
51
- puts "#{team.first_name} #{team.last_name}:".ljust(23) +
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
54
+ puts team.team_id.ljust(22) + team.win_percentage.ljust(6) +
55
+ team.won.to_s.ljust(4) +
56
+ team.lost.to_s.ljust(@leader.overall_rank(team) < 10 ? 5 : 4) +
57
+ @leader.overall_rank(team).to_s.ljust(@leader.overall_rank(team) < 10 ? 7 : 8) +
58
+ team.conference.ljust(@leader.league_rank(team) < 10 ? 7 : 6) +
59
+ @leader.league_rank(team).to_s.ljust(@leader.league_rank(team) < 10 ? 5 : 6) +
60
+ team.division.ljust(5) +
61
+ team.rank.to_s.ljust(team.games_back < 10 ? 5 : 4) +
62
+ team.games_back.to_s.ljust(team.games_back < 10 ? 7 : 8) +
63
+ team.streak.to_s
57
64
  end
58
65
  end
59
66
 
60
- desc 'find', 'Finds the best team in baseball'
61
- method_option(:quiet, aliases: '-q',
62
- desc: 'Do not print results.', default: false)
67
+ desc 'find', 'Finds the best team in all of baseball, a league or a '\
68
+ 'division.'
63
69
  method_option(:stats, aliases: '-s',
64
70
  desc: 'Include team stats in output.',
65
71
  default: false)
@@ -76,15 +82,16 @@ module Leaderbrag
76
82
  warn 'League must be specified.'
77
83
  exit 80
78
84
  end
85
+ populate
79
86
  s_league = (options[:league].nil? ? nil : options[:league])
80
87
  s_division = (options[:division].nil? ? nil : options[:division])
81
88
  teams = @leader.filter(!options[:league].nil?, !options[:division].nil?,
82
89
  s_league, s_division)
83
90
  myteam = teams[0]
84
- brag(myteam, options[:quiet], options[:stats])
91
+ brag(myteam, false, options[:stats])
85
92
  end
86
93
 
87
- desc 'is TEAM', 'asserts that TEAM is the best team in baseball'
94
+ desc 'is TEAM', 'Asserts that TEAM is the best team in baseball.'
88
95
  method_option(:quiet, aliases: '-q', type: :boolean,
89
96
  desc: 'Do not print results', default: false)
90
97
  method_option(:stats, aliases: '-s', type: :boolean,
@@ -99,9 +106,10 @@ module Leaderbrag
99
106
  'Only affects the exit code.',
100
107
  default: false)
101
108
  def is?(team_id)
109
+ populate
102
110
  myteam = @leader.team(team_id)
103
111
  if myteam.nil?
104
- warn "No such team with ID #{options['team']}"
112
+ warn "No such team with ID '#{team_id}'"
105
113
  exit 50
106
114
  end
107
115
  brag(myteam, options[:quiet], options[:stats])
@@ -116,12 +124,39 @@ module Leaderbrag
116
124
 
117
125
  private
118
126
 
127
+ def populate
128
+ @leader = if options[:date].nil?
129
+ Leaderbrag::Leader.new
130
+ else
131
+ Leaderbrag::Leader.new(Date.parse(options[:date]))
132
+ end
133
+ end
134
+
135
+ def ordinal(n)
136
+ case n % 100
137
+ when 11, 12, 13 then 'th'
138
+ else
139
+ case n % 10
140
+ when 1 then 'st'
141
+ when 2 then 'nd'
142
+ when 3 then 'rd'
143
+ else 'th'
144
+ end
145
+ end
146
+ end
147
+
119
148
  def brag(myteam, quiet, stats)
120
149
  name = "#{myteam.first_name}"\
121
150
  " #{myteam.last_name}"
122
151
  league = myteam.conference
123
152
  division = myteam.division
124
153
  unless quiet
154
+ d = Date.today
155
+ d = Date.parse(options[:date]) unless options[:date].nil?
156
+ start = 'Today,'
157
+ start = 'On' if d != Date.today
158
+
159
+ puts "#{start} the #{d.strftime("%-d#{ordinal(d.day)} day of %B, %Y")}:"
125
160
  print "The #{name} are "
126
161
  print 'not ' unless @leader.division_leader?(myteam)
127
162
  print "the leaders of the #{league} #{division} division."
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'xmlstats'
4
+ require 'date'
4
5
  module Leaderbrag
5
6
  # Mostly wraps MLB standings adding some additional leadership checks
6
7
  class Leader
7
8
  attr_reader :standings
8
- def initialize
9
+ def initialize(date = Date.today)
9
10
  Xmlstats.cacher = if ENV['XMLSTATS_CACHER'] == 'redis'
10
11
  host = '127.0.0.1'
11
12
  if ENV.key? 'XMLSTATS_REDIS_HOST'
@@ -16,12 +17,12 @@ module Leaderbrag
16
17
  Xmlstats::Cachers::Memory.new
17
18
  end
18
19
  begin
19
- @standings = Xmlstats.mlb_standing
20
+ @standings = Xmlstats.mlb_standing(date)
20
21
  rescue Redis::CannotConnectError
21
22
  warn "WARN: Redis host #{ENV['XMLSTATS_REDIS_HOST']} "\
22
23
  'not available. Falling back to memory cacher.'
23
24
  Xmlstats.cacher = Xmlstats::Cachers::Memory.new
24
- @standings = Xmlstats.mlb_standing
25
+ @standings = Xmlstats.mlb_standing(date)
25
26
  end
26
27
  @standings.sort_by! do |team|
27
28
  team.win_percentage.to_f
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leaderbrag
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
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.1.0
4
+ version: 1.2.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-23 00:00:00.000000000 Z
11
+ date: 2019-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis