leaderbrag 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +3 -3
- data/.travis.yml +4 -0
- data/README.md +87 -72
- data/Rakefile +0 -3
- data/leaderbrag.gemspec +3 -1
- data/lib/leaderbrag/cli.rb +51 -39
- data/lib/leaderbrag/leader.rb +70 -0
- data/lib/leaderbrag/version.rb +1 -1
- metadata +33 -5
- data/lib/leaderbrag/standings.rb +0 -26
- data/lib/leaderbrag/team.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7579c259982dedf4121354fd0cdcdd697e2c76ff
|
4
|
+
data.tar.gz: 6c98eebdb490302afcde4ef45289516ad51421e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d7b685b826f17d073c2c923e3790ef1f1ab66c552f50ee928ae1c4c43feec0377ea734063c80395b9b594b2a163d774c50ca7b8711b1f1cf4d7bcda0909daa9
|
7
|
+
data.tar.gz: b30eacd0ffd35c3540d24dd41e7702055405ab06c4c88c1e2ea83cecb860bee89445c5ebdaca81baba3d41a7adf7bdf377e65fb1d02f7c413f1db90e9c7a74dc
|
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-21 22:32:50 -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,7 +14,7 @@ Lint/HandleExceptions:
|
|
14
14
|
|
15
15
|
# Offense count: 2
|
16
16
|
Metrics/AbcSize:
|
17
|
-
Max:
|
17
|
+
Max: 44
|
18
18
|
|
19
19
|
# Offense count: 1
|
20
20
|
Metrics/CyclomaticComplexity:
|
@@ -23,7 +23,7 @@ Metrics/CyclomaticComplexity:
|
|
23
23
|
# Offense count: 1
|
24
24
|
# Configuration parameters: CountComments, ExcludedMethods.
|
25
25
|
Metrics/MethodLength:
|
26
|
-
Max:
|
26
|
+
Max: 38
|
27
27
|
|
28
28
|
# Offense count: 1
|
29
29
|
Metrics/PerceivedComplexity:
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# Leaderbrag
|
1
|
+
# Leaderbrag [![Build Status](https://travis-ci.org/schlazor/leaderbrag.svg?branch=master)](https://travis-ci.org/schlazor/leaderbrag)
|
2
2
|
|
3
|
-
Leaderbrag is a small gem that uses [xmlstats](https://erikberg.com/api) to find the leading team in baseball or determine if a given team is the best in baseball.
|
3
|
+
Leaderbrag is a small gem that uses [xmlstats](https://erikberg.com/api) via [xmlstats-ruby](https://github.com/alexmchale/xmlstats-ruby) to find the leading team in baseball or determine if a given team is the best in baseball.
|
4
4
|
|
5
|
-
It includes the CLI executable `leader` which should be suitable for most scripting desires
|
5
|
+
It includes the CLI executable `leader` which should be suitable for most scripting desires.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -23,6 +23,17 @@ Or install it yourself as:
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
First, ensure you have $GEM_HOME/bin in your path.
|
26
|
+
You'll need to set some environment variables to match your [xmlstats API key](https://erikberg.com/api#):
|
27
|
+
```
|
28
|
+
$ export XMLSTATS_API_KEY="xxxxx-xxxx-xxxx"
|
29
|
+
$ export XMLSTATS_CONTACT_INFO="you@example.com"
|
30
|
+
```
|
31
|
+
To cut down on API calls, you can turn on caching by setting these environment variables:
|
32
|
+
```
|
33
|
+
export XMLSTATS_CACHER='redis'
|
34
|
+
export XMLSTATS_REDIS_HOST='127.0.0.1'
|
35
|
+
```
|
36
|
+
where XMLSTATS_REDIS_HOST is the IP of a server running [redis](https://redis.io/) that you have access to. Most probably this is `127.0.0.1` and in fact if you don't specify this environment variable that value will be used.
|
26
37
|
|
27
38
|
Using the CLI is pretty straightforward.
|
28
39
|
|
@@ -35,41 +46,43 @@ The Minnesota Twins are the leaders of the AL.
|
|
35
46
|
The Minnesota Twins are the best team in baseball.
|
36
47
|
```
|
37
48
|
|
38
|
-
To query about a specific team, you'll need that team's ID. Get the
|
49
|
+
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:
|
39
50
|
```
|
40
|
-
$ leader
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
Texas Rangers: texas-rangers
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
51
|
+
$ 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
|
71
84
|
```
|
72
|
-
When asking about a team, the exit code
|
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
86
|
```
|
74
87
|
$ leader is minnesota-twins
|
75
88
|
The Minnesota Twins are the leaders of the AL C division.
|
@@ -77,51 +90,53 @@ The Minnesota Twins are the leaders of the AL.
|
|
77
90
|
The Minnesota Twins are the best team in baseball.
|
78
91
|
$ echo $?
|
79
92
|
0
|
80
|
-
|
81
93
|
$ leader is new-york-yankees
|
82
94
|
The New York Yankees are the leaders of the AL E division.
|
83
|
-
The New York Yankees are not the leaders of the AL.
|
84
|
-
The New York Yankees are not the best team in baseball.
|
95
|
+
The New York Yankees are not the leaders of the AL. They are #2.
|
96
|
+
The New York Yankees are not the best team in baseball. They are #3.
|
85
97
|
$ echo $?
|
86
98
|
1
|
87
|
-
|
88
99
|
$ leader is seattle-mariners
|
89
|
-
The Seattle Mariners are not the leaders of the AL W division.
|
90
|
-
The Seattle Mariners are not the leaders of the AL.
|
91
|
-
The Seattle Mariners are not the best team in baseball.
|
100
|
+
The Seattle Mariners are not the leaders of the AL W division. They are 5th.
|
101
|
+
The Seattle Mariners are not the leaders of the AL. They are #11.
|
102
|
+
The Seattle Mariners are not the best team in baseball. They are #25.
|
92
103
|
$ echo $?
|
93
104
|
5
|
94
105
|
```
|
95
|
-
You can also get some extra stats about the team in the `is` and `find` tasks:
|
106
|
+
You can also get some extra stats about the team in the `is` and `find` tasks with the `-s` option:
|
96
107
|
```
|
97
|
-
$ leader is
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
108
|
+
$ leader is chicago-cubs -s
|
109
|
+
The Chicago Cubs are the leaders of the NL C division.
|
110
|
+
The Chicago Cubs are not the leaders of the NL. They are #3.
|
111
|
+
The Chicago Cubs are not the best team in baseball. They are #7.
|
112
|
+
Rank: 1
|
113
|
+
Won: 41
|
114
|
+
Lost: 34
|
115
|
+
Streak: L1
|
116
|
+
Games back: 0.0
|
117
|
+
Points for: 382
|
118
|
+
Points against: 317
|
119
|
+
Home won: 26
|
120
|
+
Home lost: 13
|
121
|
+
Away won: 15
|
122
|
+
Away lost: 21
|
123
|
+
Conference won: 34
|
124
|
+
Conference lost: 28
|
125
|
+
Division won: 13
|
126
|
+
Division lost: 11
|
127
|
+
Last five: 2-3
|
128
|
+
Last ten: 4-6
|
129
|
+
Conference: NL
|
130
|
+
Division: C
|
131
|
+
Points scored per game: 5.1
|
132
|
+
Points allowed per game: 4.2
|
133
|
+
Win percentage: .547
|
134
|
+
Point differential: 65
|
135
|
+
Point differential per game: 0.9
|
136
|
+
Streak type: loss
|
137
|
+
Streak total: 1
|
138
|
+
Games played: 75
|
139
|
+
Date: 2019-06-21
|
125
140
|
```
|
126
141
|
|
127
142
|
## Development
|
data/Rakefile
CHANGED
@@ -2,11 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
begin
|
5
|
-
require 'rspec/core/rake_task'
|
6
5
|
require 'rubocop/rake_task'
|
7
6
|
require 'cucumber'
|
8
7
|
require 'cucumber/rake/task'
|
9
|
-
RSpec::Core::RakeTask.new(:spec)
|
10
8
|
RuboCop::RakeTask.new(:style)
|
11
9
|
Cucumber::Rake::Task.new(:features) do |t|
|
12
10
|
t.cucumber_opts = '--format pretty'
|
@@ -14,7 +12,6 @@ begin
|
|
14
12
|
desc 'run all checks'
|
15
13
|
task :all do
|
16
14
|
Rake::Task['style'].invoke
|
17
|
-
Rake::Task['spec'].invoke
|
18
15
|
Rake::Task['features'].invoke
|
19
16
|
end
|
20
17
|
rescue LoadError
|
data/leaderbrag.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = 'Find out if your baseball team is best baseball team.'
|
13
13
|
spec.description = 'Tools to determine whether a baseball team is leading'\
|
14
|
-
'its division/league/all of baseball.'
|
14
|
+
' its division/league/all of baseball.'
|
15
15
|
spec.homepage = 'https://github.com/schlazor/leaderbrag'
|
16
16
|
|
17
17
|
if spec.respond_to?(:metadata)
|
@@ -33,7 +33,9 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.bindir = 'exe'
|
34
34
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
35
|
spec.require_paths = ['lib']
|
36
|
+
spec.add_dependency 'redis', '~> 4.1'
|
36
37
|
spec.add_dependency 'thor', '~> 0.20'
|
38
|
+
spec.add_dependency 'xmlstats', '~> 1.7'
|
37
39
|
spec.add_development_dependency 'aruba', '~> 0.14'
|
38
40
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
39
41
|
spec.add_development_dependency 'cucumber', '~> 3.1'
|
data/lib/leaderbrag/cli.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'thor'
|
4
|
-
require 'leaderbrag/
|
4
|
+
require 'leaderbrag/leader'
|
5
|
+
require 'redis'
|
5
6
|
module Leaderbrag
|
6
7
|
# A CLI for Leaderbrag
|
7
8
|
class CLI < Thor
|
@@ -9,13 +10,22 @@ module Leaderbrag
|
|
9
10
|
true
|
10
11
|
end
|
11
12
|
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
@leader = nil
|
14
|
+
def initialize(args = [], local_options = {}, config = {})
|
15
|
+
super
|
16
|
+
@leader = Leaderbrag::Leader.new
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'board', 'Lists all baseball teams with their standings'
|
20
|
+
def board
|
21
|
+
puts 'Team Name'.ljust(23) +
|
22
|
+
'Team ID Rank Win% League Div'
|
23
|
+
puts '-'.ljust(68, '-')
|
24
|
+
@leader.standings.each_with_index do |team, i|
|
25
|
+
puts "#{team.first_name} #{team.last_name}:".ljust(23) +
|
26
|
+
team.team_id.ljust(22) + (i + 1).to_s.ljust(6) +
|
27
|
+
team.win_percentage.ljust(6) +
|
28
|
+
team.conference.ljust(8) + team.division
|
19
29
|
end
|
20
30
|
end
|
21
31
|
|
@@ -26,13 +36,7 @@ module Leaderbrag
|
|
26
36
|
desc: 'Include team stats in output',
|
27
37
|
default: false)
|
28
38
|
def find
|
29
|
-
|
30
|
-
@standings['standing'].sort_by! do |team|
|
31
|
-
team['win_percentage'].to_f
|
32
|
-
end
|
33
|
-
i = @standings['standing'].length - 1
|
34
|
-
myteam = Leaderbrag::Team.new(@standings['standing'][i]['team_id'],
|
35
|
-
@standings)
|
39
|
+
myteam = @leader.standings[0]
|
36
40
|
brag(myteam, options[:quiet], options[:stats])
|
37
41
|
end
|
38
42
|
|
@@ -42,9 +46,9 @@ module Leaderbrag
|
|
42
46
|
method_option(:stats, aliases: '-s',
|
43
47
|
desc: 'Include team stats in output',
|
44
48
|
default: false)
|
45
|
-
def is?(
|
46
|
-
myteam =
|
47
|
-
if myteam.
|
49
|
+
def is?(team_id)
|
50
|
+
myteam = @leader.team(team_id)
|
51
|
+
if myteam.nil?
|
48
52
|
warn "No such team with ID #{options['team']}"
|
49
53
|
exit 50
|
50
54
|
end
|
@@ -54,37 +58,45 @@ module Leaderbrag
|
|
54
58
|
private
|
55
59
|
|
56
60
|
def brag(myteam, quiet, stats)
|
57
|
-
name = "#{myteam.
|
58
|
-
" #{myteam.
|
59
|
-
league = myteam.
|
60
|
-
division = myteam.
|
61
|
+
name = "#{myteam.first_name}"\
|
62
|
+
" #{myteam.last_name}"
|
63
|
+
league = myteam.conference
|
64
|
+
division = myteam.division
|
61
65
|
unless quiet
|
62
66
|
print "The #{name} are "
|
63
|
-
print 'not ' unless
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
print "
|
69
|
-
print 'not ' unless
|
70
|
-
|
67
|
+
print 'not ' unless @leader.division_leader?(myteam)
|
68
|
+
print "the leaders of the #{league} #{division} division."
|
69
|
+
unless @leader.division_leader?(myteam)
|
70
|
+
print " They are #{myteam.ordinal_rank}."
|
71
|
+
end
|
72
|
+
print "\nThe #{name} are "
|
73
|
+
print 'not ' unless @leader.league_leader?(myteam)
|
74
|
+
print "the leaders of the #{league}."
|
75
|
+
unless @leader.league_leader?(myteam)
|
76
|
+
print " They are ##{@leader.league_rank(myteam)}."
|
77
|
+
end
|
78
|
+
print "\nThe #{name} are "
|
79
|
+
print 'not ' unless @leader.overall_leader?(myteam)
|
80
|
+
print 'the best team in baseball.'
|
81
|
+
unless @leader.overall_leader?(myteam)
|
82
|
+
print " They are ##{@leader.overall_rank(myteam)}."
|
83
|
+
end
|
84
|
+
puts
|
71
85
|
end
|
72
86
|
|
73
87
|
if stats
|
74
|
-
myteam.
|
75
|
-
|
76
|
-
next if
|
77
|
-
next if k == 'last_name'
|
78
|
-
next if k == 'ordinal_rank'
|
88
|
+
myteam.fields.each do |field|
|
89
|
+
k = field.to_s
|
90
|
+
next if %w[team_id first_name last_name ordinal_rank].include?(k)
|
79
91
|
|
80
|
-
label = k.gsub(/_/, ' ').capitalize + ':'
|
81
|
-
puts
|
92
|
+
label = k.gsub(/_/, ' ').capitalize + ': '
|
93
|
+
puts label.ljust(30) + myteam.send(field).to_s
|
82
94
|
end
|
83
95
|
end
|
84
|
-
if
|
96
|
+
if @leader.overall_leader?(myteam)
|
85
97
|
exit 0
|
86
98
|
else
|
87
|
-
exit myteam.
|
99
|
+
exit myteam.rank
|
88
100
|
end
|
89
101
|
end
|
90
102
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'xmlstats'
|
4
|
+
module Leaderbrag
|
5
|
+
# Mostly wraps MLB standings adding some additional leadership checks
|
6
|
+
class Leader
|
7
|
+
attr_reader :standings
|
8
|
+
def initialize
|
9
|
+
Xmlstats.cacher = if ENV['XMLSTATS_CACHER'] == 'redis'
|
10
|
+
host = '127.0.0.1'
|
11
|
+
if ENV.key? 'XMLSTATS_REDIS_HOST'
|
12
|
+
host = ENV['XMLSTATS_REDIS_HOST']
|
13
|
+
end
|
14
|
+
Xmlstats::Cachers::Redis.new(host: host)
|
15
|
+
else
|
16
|
+
Xmlstats::Cachers::Memory.new
|
17
|
+
end
|
18
|
+
begin
|
19
|
+
@standings = Xmlstats.mlb_standing
|
20
|
+
rescue Redis::CannotConnectError
|
21
|
+
warn "WARN: Redis host #{ENV['XMLSTATS_REDIS_HOST']} "\
|
22
|
+
'not available. Falling back to memory cacher.'
|
23
|
+
Xmlstats.cacher = Xmlstats::Cachers::Memory.new
|
24
|
+
@standings = Xmlstats.mlb_standing
|
25
|
+
end
|
26
|
+
@standings.sort_by! do |team|
|
27
|
+
team.win_percentage.to_f
|
28
|
+
end
|
29
|
+
@standings.reverse!
|
30
|
+
end
|
31
|
+
|
32
|
+
def team(team_id)
|
33
|
+
@standings.detect do |team|
|
34
|
+
team.team_id == team_id
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def division_leader?(team)
|
39
|
+
return true if team.rank == 1
|
40
|
+
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
def league_members(team)
|
45
|
+
@standings.select do |t|
|
46
|
+
team.conference == t.conference
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def league_leader?(team)
|
51
|
+
return true if team.team_id == league_members(team)[0].team_id
|
52
|
+
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def league_rank(team)
|
57
|
+
league_members(team).find_index(team) + 1
|
58
|
+
end
|
59
|
+
|
60
|
+
def overall_leader?(team)
|
61
|
+
return true if team.team_id == @standings[0].team_id
|
62
|
+
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
def overall_rank(team)
|
67
|
+
@standings.find_index(team) + 1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/leaderbrag/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaderbrag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: thor
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +38,20 @@ dependencies:
|
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0.20'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: xmlstats
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: aruba
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +150,7 @@ dependencies:
|
|
122
150
|
- - "~>"
|
123
151
|
- !ruby/object:Gem::Version
|
124
152
|
version: '0.20'
|
125
|
-
description: Tools to determine whether a baseball team is
|
153
|
+
description: Tools to determine whether a baseball team is leading its division/league/all
|
126
154
|
of baseball.
|
127
155
|
email:
|
128
156
|
- david@schdav.org
|
@@ -135,6 +163,7 @@ files:
|
|
135
163
|
- ".rubocop.yml"
|
136
164
|
- ".rubocop_todo.yml"
|
137
165
|
- ".ruby-version"
|
166
|
+
- ".travis.yml"
|
138
167
|
- CHANGELOG.md
|
139
168
|
- CODE_OF_CONDUCT.md
|
140
169
|
- Gemfile
|
@@ -147,8 +176,7 @@ files:
|
|
147
176
|
- leaderbrag.gemspec
|
148
177
|
- lib/leaderbrag.rb
|
149
178
|
- lib/leaderbrag/cli.rb
|
150
|
-
- lib/leaderbrag/
|
151
|
-
- lib/leaderbrag/team.rb
|
179
|
+
- lib/leaderbrag/leader.rb
|
152
180
|
- lib/leaderbrag/version.rb
|
153
181
|
homepage: https://github.com/schlazor/leaderbrag
|
154
182
|
licenses: []
|
data/lib/leaderbrag/standings.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
require 'net/http'
|
5
|
-
|
6
|
-
module Leaderbrag
|
7
|
-
# holds the current baseball standings
|
8
|
-
class Standings
|
9
|
-
attr_reader :standings
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
update
|
13
|
-
end
|
14
|
-
|
15
|
-
def update
|
16
|
-
url = 'https://erikberg.com/mlb/standings.json'
|
17
|
-
uri = URI(url)
|
18
|
-
user_agent = 'Leaderbrag/0.1.0 (david@schdav.org)'
|
19
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
20
|
-
request = Net::HTTP::Get.new(uri, 'User-Agent' => user_agent)
|
21
|
-
response = http.request(request)
|
22
|
-
@standings = JSON.parse(response.body)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/leaderbrag/team.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'leaderbrag/standings'
|
4
|
-
module Leaderbrag
|
5
|
-
# a baseball team
|
6
|
-
class Team
|
7
|
-
attr_reader :name, :team_standings, :division_leader, :league_leader
|
8
|
-
attr_reader :overall_leader, :baseball_standings
|
9
|
-
alias division_leader? division_leader
|
10
|
-
alias league_leader? league_leader
|
11
|
-
alias overall_leader? overall_leader
|
12
|
-
def initialize(name, standings = nil)
|
13
|
-
@name = name
|
14
|
-
if standings.nil?
|
15
|
-
@baseball_standings = Leaderbrag::Standings.new.standings
|
16
|
-
end
|
17
|
-
@baseball_standings = standings unless standings.nil?
|
18
|
-
@team_standings = find_team
|
19
|
-
return if @team_standings.nil?
|
20
|
-
|
21
|
-
find_division_leader
|
22
|
-
find_league_leader
|
23
|
-
find_overall_leader
|
24
|
-
end
|
25
|
-
|
26
|
-
def find_team
|
27
|
-
myteams = @baseball_standings['standing'].select do |team|
|
28
|
-
team['team_id'] == name
|
29
|
-
end
|
30
|
-
myteams.length == 1 ? myteams[0] : nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def find_division_leader
|
34
|
-
@division_leader = @team_standings['games_back'] == 0.0
|
35
|
-
end
|
36
|
-
|
37
|
-
def find_division_leaders
|
38
|
-
@baseball_standings['standing'].select do |team|
|
39
|
-
team['rank'] == 1
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def find_overall_leader
|
44
|
-
division_leaders = find_division_leaders
|
45
|
-
division_leaders.sort_by! do |team|
|
46
|
-
team['win_percentage'].to_f
|
47
|
-
end
|
48
|
-
dl_id = division_leaders[division_leaders.length - 1]['team_id']
|
49
|
-
@overall_leader = false
|
50
|
-
@overall_leader = true if dl_id == @name
|
51
|
-
end
|
52
|
-
|
53
|
-
def find_league_leader
|
54
|
-
division_leaders = find_division_leaders
|
55
|
-
league_leaders = division_leaders.select do |team|
|
56
|
-
@team_standings['conference'] == team['conference']
|
57
|
-
end
|
58
|
-
league_leaders.sort_by! do |team|
|
59
|
-
team['win_percentage'].to_f
|
60
|
-
end
|
61
|
-
ll_id = league_leaders[league_leaders.length - 1]['team_id']
|
62
|
-
@league_leader = false
|
63
|
-
@league_leader = true if ll_id == name
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|