leaderbrag 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +30 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +13 -0
- data/README.md +141 -0
- data/Rakefile +23 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/leader +6 -0
- data/leaderbrag.gemspec +44 -0
- data/lib/leaderbrag/cli.rb +91 -0
- data/lib/leaderbrag/standings.rb +26 -0
- data/lib/leaderbrag/team.rb +66 -0
- data/lib/leaderbrag/version.rb +5 -0
- data/lib/leaderbrag.rb +8 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1f08cd9b911549a210572d128a7468a81ffc96e
|
4
|
+
data.tar.gz: 45530a9599ccdf9fb6254eba5aad905582e984fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35747ec43c7fd29058e812f22f8774f5239f9e952ab9b89b07503800c7cc88e29347a8762b3c72a0b2c50a445f2099dbbc6c1291b1a0d96f6722ae9a2c52bada
|
7
|
+
data.tar.gz: d203f5e93b3f093ce69958097f70d431157c4603c12824bf3e06e45407581df0c0034ef0342c95c455751af59da3b4f54bd1ef73247b72dc87060d71e6e4caae
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2019-06-18 21:39:23 -0500 using RuboCop version 0.71.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: AllowComments.
|
11
|
+
Lint/HandleExceptions:
|
12
|
+
Exclude:
|
13
|
+
- 'Rakefile'
|
14
|
+
|
15
|
+
# Offense count: 2
|
16
|
+
Metrics/AbcSize:
|
17
|
+
Max: 36
|
18
|
+
|
19
|
+
# Offense count: 1
|
20
|
+
Metrics/CyclomaticComplexity:
|
21
|
+
Max: 11
|
22
|
+
|
23
|
+
# Offense count: 1
|
24
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
25
|
+
Metrics/MethodLength:
|
26
|
+
Max: 30
|
27
|
+
|
28
|
+
# Offense count: 1
|
29
|
+
Metrics/PerceivedComplexity:
|
30
|
+
Max: 12
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at david@schdav.org. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2019 David Schlenk
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# Leaderbrag
|
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.
|
4
|
+
|
5
|
+
It includes the CLI executable `leader` which should be suitable for most scripting desires and also serves as a useful example for using the underlying library.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'leaderbrag'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install leaderbrag
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
First, ensure you have $GEM_HOME/bin in your path.
|
26
|
+
|
27
|
+
Using the CLI is pretty straightforward.
|
28
|
+
|
29
|
+
Use the `find` task to find the best team in baseball:
|
30
|
+
|
31
|
+
```
|
32
|
+
$ leader find
|
33
|
+
The Minnesota Twins are the leaders of the AL C division.
|
34
|
+
The Minnesota Twins are the leaders of the AL.
|
35
|
+
The Minnesota Twins are the best team in baseball.
|
36
|
+
```
|
37
|
+
|
38
|
+
To query about a specific team, you'll need that team's ID. Get the list with the `list` task:
|
39
|
+
```
|
40
|
+
$ leader list
|
41
|
+
Minnesota Twins: minnesota-twins
|
42
|
+
Cleveland Indians: cleveland-indians
|
43
|
+
Chicago White Sox: chicago-white-sox
|
44
|
+
Detroit Tigers: detroit-tigers
|
45
|
+
Kansas City Royals: kansas-city-royals
|
46
|
+
New York Yankees: new-york-yankees
|
47
|
+
Tampa Bay Rays: tampa-bay-rays
|
48
|
+
Boston Red Sox: boston-red-sox
|
49
|
+
Toronto Blue Jays: toronto-blue-jays
|
50
|
+
Baltimore Orioles: baltimore-orioles
|
51
|
+
Houston Astros: houston-astros
|
52
|
+
Texas Rangers: texas-rangers
|
53
|
+
Oakland Athletics: oakland-athletics
|
54
|
+
Los Angeles Angels: los-angeles-angels
|
55
|
+
Seattle Mariners: seattle-mariners
|
56
|
+
Milwaukee Brewers: milwaukee-brewers
|
57
|
+
Chicago Cubs: chicago-cubs
|
58
|
+
St. Louis Cardinals: st-louis-cardinals
|
59
|
+
Cincinnati Reds: cincinnati-reds
|
60
|
+
Pittsburgh Pirates: pittsburgh-pirates
|
61
|
+
Atlanta Braves: atlanta-braves
|
62
|
+
Philadelphia Phillies: philadelphia-phillies
|
63
|
+
New York Mets: new-york-mets
|
64
|
+
Washington Nationals: washington-nationals
|
65
|
+
Miami Marlins: miami-marlins
|
66
|
+
Los Angeles Dodgers: los-angeles-dodgers
|
67
|
+
Colorado Rockies: colorado-rockies
|
68
|
+
Arizona Diamondbacks: arizona-diamondbacks
|
69
|
+
San Diego Padres: san-diego-padres
|
70
|
+
San Francisco Giants: san-francisco-giants
|
71
|
+
```
|
72
|
+
When asking about a team, the exit code indicates whether the requested team is the best team in baseball - 0 of so, otherwise it is the rank of that team in their division.
|
73
|
+
```
|
74
|
+
$ leader is minnesota-twins
|
75
|
+
The Minnesota Twins are the leaders of the AL C division.
|
76
|
+
The Minnesota Twins are the leaders of the AL.
|
77
|
+
The Minnesota Twins are the best team in baseball.
|
78
|
+
$ echo $?
|
79
|
+
0
|
80
|
+
|
81
|
+
$ leader is new-york-yankees
|
82
|
+
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.
|
85
|
+
$ echo $?
|
86
|
+
1
|
87
|
+
|
88
|
+
$ 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.
|
92
|
+
$ echo $?
|
93
|
+
5
|
94
|
+
```
|
95
|
+
You can also get some extra stats about the team in the `is` and `find` tasks:
|
96
|
+
```
|
97
|
+
$ leader is new-york-yankees -s
|
98
|
+
Rank: 1
|
99
|
+
Won: 44
|
100
|
+
Lost: 27
|
101
|
+
Streak: W3
|
102
|
+
Games back: 0.0
|
103
|
+
Points for: 382
|
104
|
+
Points against: 307
|
105
|
+
Home won: 23
|
106
|
+
Home lost: 13
|
107
|
+
Away won: 21
|
108
|
+
Away lost: 14
|
109
|
+
Conference won: 38
|
110
|
+
Conference lost: 23
|
111
|
+
Division won: 20
|
112
|
+
Division lost: 7
|
113
|
+
Last five: 3-2
|
114
|
+
Last ten: 5-5
|
115
|
+
Conference: AL
|
116
|
+
Division: E
|
117
|
+
Points scored per game: 5.4
|
118
|
+
Points allowed per game: 4.3
|
119
|
+
Win percentage: .620
|
120
|
+
Point differential: 75
|
121
|
+
Point differential per game: 1.1
|
122
|
+
Streak type: win
|
123
|
+
Streak total: 3
|
124
|
+
Games played: 71
|
125
|
+
```
|
126
|
+
|
127
|
+
## Development
|
128
|
+
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
130
|
+
|
131
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
132
|
+
|
133
|
+
There are a few rake tasks defined for linting and testing. The default rake task runs them all. Before submitting a pull request, please ensure tests and style checks pass.
|
134
|
+
|
135
|
+
## Contributing
|
136
|
+
|
137
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/schlazor/leaderbrag. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
138
|
+
|
139
|
+
## Code of Conduct
|
140
|
+
|
141
|
+
Everyone interacting in the Leaderbrag project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/schlazor/leaderbrag/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
begin
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'rubocop/rake_task'
|
7
|
+
require 'cucumber'
|
8
|
+
require 'cucumber/rake/task'
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
RuboCop::RakeTask.new(:style)
|
11
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
12
|
+
t.cucumber_opts = '--format pretty'
|
13
|
+
end
|
14
|
+
desc 'run all checks'
|
15
|
+
task :all do
|
16
|
+
Rake::Task['style'].invoke
|
17
|
+
Rake::Task['spec'].invoke
|
18
|
+
Rake::Task['features'].invoke
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
end
|
22
|
+
|
23
|
+
task default: :all
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'leaderbrag'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/leader
ADDED
data/leaderbrag.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'leaderbrag/version'
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'leaderbrag'
|
8
|
+
spec.version = Leaderbrag::VERSION
|
9
|
+
spec.authors = ['David Schlenk']
|
10
|
+
spec.email = ['david@schdav.org']
|
11
|
+
|
12
|
+
spec.summary = 'Find out if your baseball team is best baseball team.'
|
13
|
+
spec.description = 'Tools to determine whether a baseball team is leading'\
|
14
|
+
'its division/league/all of baseball.'
|
15
|
+
spec.homepage = 'https://github.com/schlazor/leaderbrag'
|
16
|
+
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
+
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/schlazor/leaderbrag/tree/master/CHANGELOG.md'
|
23
|
+
else
|
24
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
25
|
+
'public gem pushes.'
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
30
|
+
f.match(%r{^(test|spec|features)/})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
spec.bindir = 'exe'
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ['lib']
|
36
|
+
spec.add_dependency 'thor', '~> 0.20'
|
37
|
+
spec.add_development_dependency 'aruba', '~> 0.14'
|
38
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
39
|
+
spec.add_development_dependency 'cucumber', '~> 3.1'
|
40
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
41
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 0.71'
|
43
|
+
spec.add_development_dependency 'thor', '~> 0.20'
|
44
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'leaderbrag/team'
|
5
|
+
module Leaderbrag
|
6
|
+
# A CLI for Leaderbrag
|
7
|
+
class CLI < Thor
|
8
|
+
def self.exit_on_failure?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
@standings = nil
|
13
|
+
desc 'list', 'Lists all baseball team IDs'
|
14
|
+
def list
|
15
|
+
standings = Leaderbrag::Standings.new.standings
|
16
|
+
standings['standing'].each do |team|
|
17
|
+
puts "#{team['first_name']} #{team['last_name']}:".ljust(23) +
|
18
|
+
team['team_id']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'find', 'Finds the best team in baseball'
|
23
|
+
method_option(:quiet, aliases: '-q',
|
24
|
+
desc: 'Do not print results', default: false)
|
25
|
+
method_option(:stats, aliases: '-s',
|
26
|
+
desc: 'Include team stats in output',
|
27
|
+
default: false)
|
28
|
+
def find
|
29
|
+
@standings = Leaderbrag::Standings.new.standings
|
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)
|
36
|
+
brag(myteam, options[:quiet], options[:stats])
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'is TEAM', 'asserts that TEAM is the best team in baseball'
|
40
|
+
method_option(:quiet, aliases: '-q',
|
41
|
+
desc: 'Do not print results', default: false)
|
42
|
+
method_option(:stats, aliases: '-s',
|
43
|
+
desc: 'Include team stats in output',
|
44
|
+
default: false)
|
45
|
+
def is?(team)
|
46
|
+
myteam = Leaderbrag::Team.new(team)
|
47
|
+
if myteam.team_standings.nil?
|
48
|
+
warn "No such team with ID #{options['team']}"
|
49
|
+
exit 50
|
50
|
+
end
|
51
|
+
brag(myteam, options[:quiet], options[:stats])
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def brag(myteam, quiet, stats)
|
57
|
+
name = "#{myteam.team_standings['first_name']}"\
|
58
|
+
" #{myteam.team_standings['last_name']}"
|
59
|
+
league = myteam.team_standings['conference']
|
60
|
+
division = myteam.team_standings['division']
|
61
|
+
unless quiet
|
62
|
+
print "The #{name} are "
|
63
|
+
print 'not ' unless myteam.division_leader?
|
64
|
+
puts "the leaders of the #{league} #{division} division."
|
65
|
+
print "The #{name} are "
|
66
|
+
print 'not ' unless myteam.league_leader?
|
67
|
+
puts "the leaders of the #{league}."
|
68
|
+
print "The #{name} are "
|
69
|
+
print 'not ' unless myteam.overall_leader?
|
70
|
+
puts 'the best team in baseball.'
|
71
|
+
end
|
72
|
+
|
73
|
+
if stats
|
74
|
+
myteam.team_standings.each do |k, v|
|
75
|
+
next if k == 'team_id'
|
76
|
+
next if k == 'first_name'
|
77
|
+
next if k == 'last_name'
|
78
|
+
next if k == 'ordinal_rank'
|
79
|
+
|
80
|
+
label = k.gsub(/_/, ' ').capitalize + ':'
|
81
|
+
puts "#{label.ljust(30)} #{v}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
if myteam.overall_leader?
|
85
|
+
exit 0
|
86
|
+
else
|
87
|
+
exit myteam.team_standings['rank']
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,66 @@
|
|
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
|
data/lib/leaderbrag.rb
ADDED
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leaderbrag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Schlenk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.20'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.20'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aruba
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cucumber
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.71'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.71'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: thor
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.20'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.20'
|
125
|
+
description: Tools to determine whether a baseball team is leadingits division/league/all
|
126
|
+
of baseball.
|
127
|
+
email:
|
128
|
+
- david@schdav.org
|
129
|
+
executables:
|
130
|
+
- leader
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".gitignore"
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- ".rubocop_todo.yml"
|
137
|
+
- ".ruby-version"
|
138
|
+
- CHANGELOG.md
|
139
|
+
- CODE_OF_CONDUCT.md
|
140
|
+
- Gemfile
|
141
|
+
- LICENSE.txt
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- bin/console
|
145
|
+
- bin/setup
|
146
|
+
- exe/leader
|
147
|
+
- leaderbrag.gemspec
|
148
|
+
- lib/leaderbrag.rb
|
149
|
+
- lib/leaderbrag/cli.rb
|
150
|
+
- lib/leaderbrag/standings.rb
|
151
|
+
- lib/leaderbrag/team.rb
|
152
|
+
- lib/leaderbrag/version.rb
|
153
|
+
homepage: https://github.com/schlazor/leaderbrag
|
154
|
+
licenses: []
|
155
|
+
metadata:
|
156
|
+
allowed_push_host: https://rubygems.org
|
157
|
+
homepage_uri: https://github.com/schlazor/leaderbrag
|
158
|
+
source_code_uri: https://github.com/schlazor/leaderbrag
|
159
|
+
changelog_uri: https://github.com/schlazor/leaderbrag/tree/master/CHANGELOG.md
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.5.2.3
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: Find out if your baseball team is best baseball team.
|
180
|
+
test_files: []
|