baseball 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e3e3d203d1782695568c886cc314c8c6c5bd841f279ce1cc5f7d4c7ec4bdbe0
4
+ data.tar.gz: a3292aa684e4d25baa4ff1cba87f8e555902669efc87e9a46aa04fb5a5a3db97
5
+ SHA512:
6
+ metadata.gz: 63254e1298c152eb7d22ed2f77272cea9a4611a8157ac8ed9dc9b76e54760612c17134b432fd96bff7dd7d8b35dd553f348f8979321e0ff780819365bb406353
7
+ data.tar.gz: f08a391e31bdf6872101f2d95a963460a75d0f007cfdef0b915d629b83ead1d7bf4226367c93a5a7d9dd3d5b03dc9c926250a74b78e06738f4d40ca62386f01f
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .DS_store
10
+ *.gem
@@ -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 brent.busby@yahoo.com. 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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in baseball.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Brent Busby
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.
@@ -0,0 +1,87 @@
1
+ # Baseball
2
+
3
+ This Ruby gem contains a pre-created library for factoring baseball statistics.
4
+
5
+ * Gem is still in development and not yet available via rubygems.org
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'baseball'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install baseball
22
+
23
+ ## Usage
24
+
25
+ All methods in `Baseball` take a hash as an argument. The hash should contain all the
26
+ key-value pairs needed for the specific method called.
27
+
28
+ Example hash:
29
+
30
+ ```ruby
31
+ your_player_hash = {
32
+ at_bats: 420,
33
+ hits: 134,
34
+ walks: 68,
35
+ hbp: 1,
36
+ sac_flies: 3,
37
+ singles: 77,
38
+ doubles: 27,
39
+ triples: 1,
40
+ hr: 29
41
+ }
42
+ ```
43
+
44
+ Example uses:
45
+
46
+ ##### Figuring Batting Average
47
+
48
+ ```ruby
49
+ Baseball.batting_average(your_player_hash)
50
+ # will return value of ".319"
51
+ ```
52
+
53
+ #### Figure On Base Percentage
54
+ ```ruby
55
+ Baseball.obp(your_player_hash)
56
+ # will return value of ".413"
57
+ ```
58
+
59
+ #### Figure Slugging Percentage
60
+ ```ruby
61
+ Baseball.slg(your_player_hash)
62
+ # will return a value of ".595"
63
+ ```
64
+
65
+ #### Figure On Base Plus Slugging
66
+ ```ruby
67
+ Baseball.ops(your_player_hash)
68
+ # will return a value of "1.008"
69
+ ```
70
+
71
+ All values are returned as a string
72
+
73
+ ## Development
74
+
75
+ 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.
76
+
77
+ 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).
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/buzzamus/baseball.
82
+
83
+ Ruby programmers that are also very familiar with baseball statistics especially welcome.
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,24 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "baseball/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "baseball"
8
+ spec.version = Baseball::VERSION
9
+ spec.authors = ["Brent Busby"]
10
+ spec.email = ["brentbusby86@gmail.com"]
11
+ spec.summary = "a Ruby Gem library for calculating baseball statistics"
12
+ spec.homepage = "https://github.com/buzzamus/baseball-gem"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "baseball"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,64 @@
1
+ require 'baseball/version'
2
+ require 'baseball/batting'
3
+ require 'baseball/pitching'
4
+ require 'baseball/fielding'
5
+ require 'baseball/running'
6
+
7
+ module Baseball
8
+
9
+ #table of contents
10
+ #batter stats
11
+ #pitcher stats
12
+ # fielder stats
13
+
14
+ def self.version_number
15
+ Baseball::VERSION
16
+ end
17
+
18
+ #batting stats
19
+
20
+ def self.batting_average(player_hash)
21
+ include Batting
22
+ player = Batter.new(player_hash)
23
+ player.batting_average
24
+ end
25
+
26
+ def self.obp(player_hash)
27
+ include Batting
28
+ player = Batter.new(player_hash)
29
+ player.obp
30
+ end
31
+
32
+ def self.slg(player_hash)
33
+ include Batting
34
+ player = Batter.new(player_hash)
35
+ player.slugging_percentage
36
+ end
37
+
38
+ def self.ops(player_hash)
39
+ include Batting
40
+ player = Batter.new(player_hash)
41
+ player.ops
42
+ end
43
+
44
+ #pitcher stats
45
+ def self.era(pitcher_hash)
46
+ include Pitching
47
+ pitcher = Pitcher.new(pitcher_hash)
48
+ pitcher.era
49
+ end
50
+
51
+ def self.whip(pitcher_hash)
52
+ include Pitching
53
+ pitcher = Pitcher.new(pitcher_hash)
54
+ pitcher.whip
55
+ end
56
+
57
+ #fielder stats
58
+ def self.fielding_percentage(fielder_hash)
59
+ include Fielding
60
+ fielder = Fielder.new(fielder_hash)
61
+ fielder.fielding_percentage
62
+ end
63
+
64
+ end
@@ -0,0 +1,68 @@
1
+ module Batting
2
+
3
+ # add all required statistics as separate arguments required, will then be individual attributes to parse
4
+ # from object
5
+
6
+ #need to remove attr_accessors, no need to initialize. Each method will have their own individual
7
+ #arguments when called
8
+
9
+ class Batter
10
+ attr_accessor :player_hash
11
+ def initialize(player_hash)
12
+ @player = player_hash
13
+ end
14
+
15
+ def batting_average
16
+ avg = @player[:hits].to_f / @player[:at_bats].to_f
17
+ player_average = avg.round(3)
18
+ batting_average_string = player_average.to_s.sub!("0", "")
19
+ if batting_average_string.length === 3
20
+ batting_average_string = "#{batting_average_string}0"
21
+ elsif batting_average_string.length === 2
22
+ batting_average_string = "#{batting_average_string}00"
23
+ else
24
+ return batting_average_string
25
+ end
26
+ end
27
+
28
+ def obp
29
+ times_on_base = @player[:hits].to_f + @player[:walks].to_f + @player[:hbp].to_f
30
+ times_at_plate = @player[:at_bats].to_f + @player[:walks].to_f + @player[:hbp].to_f + @player[:sac_flies]
31
+ obp = times_on_base.to_f / times_at_plate.to_f
32
+ player_obp = obp.round(3)
33
+ player_obp_string = player_obp.to_s.sub!("0", "")
34
+ if player_obp_string.length === 3
35
+ player_obp_string = "#{player_obp_string}0"
36
+ elsif player_obp_string === 2
37
+ player_obp_string = "#{player_obp_string}00"
38
+ else
39
+ return player_obp_string
40
+ end
41
+ end
42
+
43
+ def slugging_percentage
44
+ player_doubles = @player[:doubles] * 2
45
+ player_triples = @player[:triples] * 3
46
+ player_hr = @player[:hr] * 4
47
+ total_bases = @player[:singles] + player_doubles + player_triples + player_hr
48
+ slg = total_bases.to_f / @player[:at_bats].to_f
49
+ slg = slg.round(3)
50
+ slg_string = slg.to_s.sub!("0", "")
51
+ if slg_string.length === 3
52
+ slg_string = "#{slg_string}0"
53
+ elsif slg_string.length === 2
54
+ slg_string = "#{slg_string}00"
55
+ else
56
+ return slg_string
57
+ end
58
+ end
59
+
60
+ def ops
61
+ player_ops = self.obp.to_f + self.slugging_percentage.to_f
62
+ player_ops_string = player_ops.round(3)
63
+ player_ops_string.to_s
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,27 @@
1
+ module Fielding
2
+
3
+ class Fielder
4
+ attr_accessor :player_hash
5
+ def initialize(player_hash)
6
+ @player = player_hash
7
+ end
8
+
9
+ def fielding_percentage
10
+ plays = @player[:put_outs] + @player[:assists]
11
+ plays_plus_errors = plays + @player[:errors]
12
+ player_avg = plays.to_f / plays_plus_errors.to_f
13
+ avg = player_avg.round(3)
14
+ # code smell - make this a several function called somewhere since this is used over multiple stats
15
+ fielding_percentage = avg.to_s.sub!("0", "")
16
+ if fielding_percentage.length === 3
17
+ fielding_percentage = "#{fielding_percentage}0"
18
+ elsif fielding_percentage.length === 2
19
+ fielding_percentage = "#{fielding_percentage}00"
20
+ else
21
+ return fielding_percentage.round
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,23 @@
1
+ module Pitching
2
+
3
+ class Pitcher
4
+ attr_accessor :pitcher_hash
5
+ def initialize(pitcher_hash)
6
+ @pitcher = pitcher_hash
7
+ end
8
+
9
+ def era
10
+ earned_runs = @pitcher[:er] * 9
11
+ avg = earned_runs / @pitcher[:ip].to_f
12
+ earned_run_average = avg.round(2)
13
+ end
14
+
15
+ def whip
16
+ walks_plus_hits = @pitcher[:walks] + @pitcher[:hits]
17
+ whip = walks_plus_hits / @pitcher[:ip].to_f
18
+ whip = whip.round(3)
19
+ end
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,4 @@
1
+ module Running
2
+
3
+
4
+ end
@@ -0,0 +1,3 @@
1
+ module Baseball
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: baseball
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brent Busby
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-14 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ description:
42
+ email:
43
+ - brentbusby86@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - baseball.gemspec
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/baseball.rb
58
+ - lib/baseball/batting.rb
59
+ - lib/baseball/fielding.rb
60
+ - lib/baseball/pitching.rb
61
+ - lib/baseball/running.rb
62
+ - lib/baseball/version.rb
63
+ homepage: https://github.com/buzzamus/baseball-gem
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.7.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: a Ruby Gem library for calculating baseball statistics
87
+ test_files: []