hof_stats 0.1.1
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/hof_stats +5 -0
- data/bin/setup +8 -0
- data/hof_stats.gemspec +39 -0
- data/lib/hof_stats/cli.rb +61 -0
- data/lib/hof_stats/player.rb +70 -0
- data/lib/hof_stats/scraper.rb +17 -0
- data/lib/hof_stats/version.rb +3 -0
- data/lib/hof_stats.rb +7 -0
- data/spec.md +7 -0
- metadata +133 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 365fc2f581ee930f1f66d6f7f3223a1fe0c8f165
|
|
4
|
+
data.tar.gz: 3c9b94f183a8869f0f9bc64b44e7ed98b0a822fb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 895d32466a73a898da1ba486be88d4a1c3f043d62371c300d2c2bd8f39e808468b0e787dea08ccd86f7d4d9c453310077cebab2f8b689c9bc0016de9d73985d5
|
|
7
|
+
data.tar.gz: b3d7528e526026687135f269742e8b794b3dab73e990a5cdb26b66d496322255c191e2c1f23671e42d8be811d504ffeaff06feae3212a1655cded637a0503732
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 TODO: Write your name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# HofStats
|
|
2
|
+
|
|
3
|
+
This Ruby Gem provies a CLI to view all the members of the MLB Hall of Fame as well as their career statistics. Data is pulled from baseball-reference.com.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'hof_stats'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install hof_stats
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Type the text below in your terminal and then follow the on screen prompts.
|
|
24
|
+
|
|
25
|
+
## Development
|
|
26
|
+
|
|
27
|
+
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.
|
|
28
|
+
|
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
30
|
+
|
|
31
|
+
## Contributing
|
|
32
|
+
|
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/<github username>/hof_stats.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "hof_stats"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/hof_stats
ADDED
data/bin/setup
ADDED
data/hof_stats.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "hof_stats/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "hof_stats"
|
|
8
|
+
spec.version = HofStats::VERSION
|
|
9
|
+
spec.authors = ["Tony Mastrorio"]
|
|
10
|
+
spec.email = ["tony.mastrorio@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "MLB Hall of Famers"
|
|
13
|
+
spec.description = "Provides statistics on all MLB Hall of Famers"
|
|
14
|
+
spec.homepage = "https://github.com/tonymastrorio/hof_stats"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
21
|
+
else
|
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
23
|
+
"public gem pushes."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
|
28
|
+
end
|
|
29
|
+
spec.bindir = "bin"
|
|
30
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
31
|
+
spec.require_paths = ["lib"]
|
|
32
|
+
|
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
35
|
+
spec.add_development_dependency "rspec", '~> 0'
|
|
36
|
+
spec.add_development_dependency "nokogiri", '~> 0'
|
|
37
|
+
spec.add_development_dependency "pry", '~> 0'
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
class HofStats::CLI
|
|
2
|
+
|
|
3
|
+
def call
|
|
4
|
+
list_players
|
|
5
|
+
menu
|
|
6
|
+
goodbye
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def list_players
|
|
10
|
+
HofStats::Scraper.new.make_player
|
|
11
|
+
puts "MLB Hall of Famers"
|
|
12
|
+
@players = HofStats::Player.all
|
|
13
|
+
@players.each_with_index do |player, i|
|
|
14
|
+
puts "#{i+1}. #{player.name} - #{player.year} - #{player.votes} votes - #{player.percent}%"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def list_individual_player(player)
|
|
19
|
+
puts "Player Name: #{player.name}"
|
|
20
|
+
if player.position == "" || player.position == "Manager"
|
|
21
|
+
puts "No stats available for #{player.name}."
|
|
22
|
+
else
|
|
23
|
+
puts "Position: #{player.position}"
|
|
24
|
+
if player.position != "Pitcher"
|
|
25
|
+
puts "Games: #{player.games}"
|
|
26
|
+
puts "Hits: #{player.hits}"
|
|
27
|
+
puts "Runs: #{player.runs}"
|
|
28
|
+
puts "Homers: #{player.homers}"
|
|
29
|
+
puts "Batting Average: #{player.batting_avg}"
|
|
30
|
+
else
|
|
31
|
+
puts "ERA: #{player.era}"
|
|
32
|
+
puts "W/L %: #{player.wlpercent}"
|
|
33
|
+
puts "Strikeouts: #{player.strikeouts}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def menu
|
|
39
|
+
input = nil
|
|
40
|
+
puts ""
|
|
41
|
+
puts "Enter the line number of a player to see more info."
|
|
42
|
+
puts "Type 'exit' to exit."
|
|
43
|
+
|
|
44
|
+
input = gets.strip.downcase
|
|
45
|
+
player = HofStats::Player.all[input.to_i - 1]
|
|
46
|
+
|
|
47
|
+
puts "***************************"
|
|
48
|
+
list_individual_player(player)
|
|
49
|
+
puts "***************************"
|
|
50
|
+
|
|
51
|
+
puts "Would you like to see another player? (Y or N)"
|
|
52
|
+
input = gets.strip.downcase
|
|
53
|
+
if input == "y"
|
|
54
|
+
menu
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def goodbye
|
|
59
|
+
puts "Goodbye!"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
class HofStats::Player
|
|
2
|
+
|
|
3
|
+
attr_accessor :name, :year, :votes, :percent, :url, :games, :runs, :hits, :homers, :batting_avg, :era, :wlpercent, :strikeouts, :position
|
|
4
|
+
|
|
5
|
+
@@all = []
|
|
6
|
+
|
|
7
|
+
def self.new_from_index(p)
|
|
8
|
+
self.new(
|
|
9
|
+
p.css("td[data-stat='player']").text,
|
|
10
|
+
p.css("th[data-stat='year_ID']").text,
|
|
11
|
+
p.css("td[data-stat='votes']").text,
|
|
12
|
+
p.css("td[data-stat='votes_pct']").text,
|
|
13
|
+
"https://baseball-reference.com#{p.css("td a").attribute("href").text}"
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize(name=nil, year=nil, votes=nil, percent=nil, url=nil)
|
|
18
|
+
@name = name
|
|
19
|
+
@year = year
|
|
20
|
+
@votes = votes
|
|
21
|
+
@percent = percent
|
|
22
|
+
@url = url
|
|
23
|
+
@@all << self
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.all
|
|
27
|
+
@@all
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def games
|
|
31
|
+
@games = doc.css("tfoot td[data-stat='G']").first.text
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def runs
|
|
35
|
+
@runs = doc.css("tfoot td[data-stat='R']").first.text
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def hits
|
|
39
|
+
@hits = doc.css("tfoot td[data-stat='H']").first.text
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def homers
|
|
43
|
+
@homers = doc.css("tfoot td[data-stat='HR']").first.text
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def batting_avg
|
|
47
|
+
@batting_avg = doc.css("tfoot td[data-stat='batting_avg']").first.text
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def era
|
|
51
|
+
@era = doc.css("tfoot td[data-stat='earned_run_avg']").first.text
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def wlpercent
|
|
55
|
+
@wlpercent = doc.css("tfoot td[data-stat='win_loss_perc']").first.text
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def strikeouts
|
|
59
|
+
@strikeouts = doc.css("tfoot td[data-stat='SO']").first.text
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def position
|
|
63
|
+
@position = doc.xpath("//*[@id='meta']/div[2]/p[1]/text()").text.strip
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def doc
|
|
67
|
+
@doc = Nokogiri::HTML(open(self.url))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class HofStats::Scraper
|
|
2
|
+
|
|
3
|
+
def get_page
|
|
4
|
+
Nokogiri::HTML(open("https://www.baseball-reference.com/awards/hof.shtml"))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def scrape_baseball_index
|
|
8
|
+
self.get_page.css("tbody tr")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def make_player
|
|
12
|
+
scrape_baseball_index.each do |p|
|
|
13
|
+
HofStats::Player.new_from_index(p)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
data/lib/hof_stats.rb
ADDED
data/spec.md
ADDED
metadata
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hof_stats
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tony Mastrorio
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-08-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.15'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.15'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: nokogiri
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: pry
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: Provides statistics on all MLB Hall of Famers
|
|
84
|
+
email:
|
|
85
|
+
- tony.mastrorio@gmail.com
|
|
86
|
+
executables:
|
|
87
|
+
- console
|
|
88
|
+
- hof_stats
|
|
89
|
+
- setup
|
|
90
|
+
extensions: []
|
|
91
|
+
extra_rdoc_files: []
|
|
92
|
+
files:
|
|
93
|
+
- ".gitignore"
|
|
94
|
+
- Gemfile
|
|
95
|
+
- LICENSE.txt
|
|
96
|
+
- README.md
|
|
97
|
+
- Rakefile
|
|
98
|
+
- bin/console
|
|
99
|
+
- bin/hof_stats
|
|
100
|
+
- bin/setup
|
|
101
|
+
- hof_stats.gemspec
|
|
102
|
+
- lib/hof_stats.rb
|
|
103
|
+
- lib/hof_stats/cli.rb
|
|
104
|
+
- lib/hof_stats/player.rb
|
|
105
|
+
- lib/hof_stats/scraper.rb
|
|
106
|
+
- lib/hof_stats/version.rb
|
|
107
|
+
- spec.md
|
|
108
|
+
homepage: https://github.com/tonymastrorio/hof_stats
|
|
109
|
+
licenses:
|
|
110
|
+
- MIT
|
|
111
|
+
metadata:
|
|
112
|
+
allowed_push_host: https://rubygems.org
|
|
113
|
+
post_install_message:
|
|
114
|
+
rdoc_options: []
|
|
115
|
+
require_paths:
|
|
116
|
+
- lib
|
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
|
+
requirements:
|
|
119
|
+
- - ">="
|
|
120
|
+
- !ruby/object:Gem::Version
|
|
121
|
+
version: '0'
|
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
|
+
requirements:
|
|
124
|
+
- - ">="
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: '0'
|
|
127
|
+
requirements: []
|
|
128
|
+
rubyforge_project:
|
|
129
|
+
rubygems_version: 2.4.8
|
|
130
|
+
signing_key:
|
|
131
|
+
specification_version: 4
|
|
132
|
+
summary: MLB Hall of Famers
|
|
133
|
+
test_files: []
|