baseball 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e3e3d203d1782695568c886cc314c8c6c5bd841f279ce1cc5f7d4c7ec4bdbe0
4
- data.tar.gz: a3292aa684e4d25baa4ff1cba87f8e555902669efc87e9a46aa04fb5a5a3db97
3
+ metadata.gz: 263bbb5e3eb706584740570cd142d6925dfd8c31200eafad661f9b29c879c68c
4
+ data.tar.gz: 6a91bc0f837b0f4b90b689775df87be4969f603cb0d7a21988ee3f53dbaf2244
5
5
  SHA512:
6
- metadata.gz: 63254e1298c152eb7d22ed2f77272cea9a4611a8157ac8ed9dc9b76e54760612c17134b432fd96bff7dd7d8b35dd553f348f8979321e0ff780819365bb406353
7
- data.tar.gz: f08a391e31bdf6872101f2d95a963460a75d0f007cfdef0b915d629b83ead1d7bf4226367c93a5a7d9dd3d5b03dc9c926250a74b78e06738f4d40ca62386f01f
6
+ metadata.gz: 54d13dd6dc62ea4e60ee25d3e4c366edc2bd9999fb6cb3d4885ec533dbfcdb59934a93813b6f0d99ddf13912bcbdc671ec993c739b032bcd95db43b305483948
7
+ data.tar.gz: 59d38c6cd8d7c5f7f38962bd699b527cefb33d0f1c1a6815054271546653838d3a730480bfdbcfedc074447f49f9b57616b1865d2329dfbb73f22f8ad77d4780
data/README.md CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  This Ruby gem contains a pre-created library for factoring baseball statistics.
4
4
 
5
- * Gem is still in development and not yet available via rubygems.org
5
+ * Gem is still in development with more stats to be added.
6
+
7
+ * Note: This project is in no way taking credit for creating any of the included baseball stats.
8
+ This is a library created strictly to be used in easily figuring the included statistics based on the data received by the user.
6
9
 
7
10
  ## Installation
8
11
 
@@ -61,4 +61,10 @@ module Baseball
61
61
  fielder.fielding_percentage
62
62
  end
63
63
 
64
+ def self.stolen_base_percentage(runner_hash)
65
+ include Running
66
+ runner = Runner.new(runner_hash)
67
+ runner.stolen_base_percentage
68
+ end
69
+
64
70
  end
@@ -1,12 +1,9 @@
1
- module Batting
2
-
3
- # add all required statistics as separate arguments required, will then be individual attributes to parse
4
- # from object
1
+ require 'baseball/helper'
5
2
 
6
- #need to remove attr_accessors, no need to initialize. Each method will have their own individual
7
- #arguments when called
3
+ module Batting
8
4
 
9
5
  class Batter
6
+ include Helper
10
7
  attr_accessor :player_hash
11
8
  def initialize(player_hash)
12
9
  @player = player_hash
@@ -16,13 +13,7 @@ module Batting
16
13
  avg = @player[:hits].to_f / @player[:at_bats].to_f
17
14
  player_average = avg.round(3)
18
15
  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
16
+ figure_trailing_zeroes(batting_average_string)
26
17
  end
27
18
 
28
19
  def obp
@@ -31,13 +22,7 @@ module Batting
31
22
  obp = times_on_base.to_f / times_at_plate.to_f
32
23
  player_obp = obp.round(3)
33
24
  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
25
+ figure_trailing_zeroes(player_obp_string)
41
26
  end
42
27
 
43
28
  def slugging_percentage
@@ -48,13 +33,7 @@ module Batting
48
33
  slg = total_bases.to_f / @player[:at_bats].to_f
49
34
  slg = slg.round(3)
50
35
  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
36
+ figure_trailing_zeroes(slg_string)
58
37
  end
59
38
 
60
39
  def ops
@@ -1,6 +1,9 @@
1
+ require 'baseball/helper'
2
+
1
3
  module Fielding
2
4
 
3
5
  class Fielder
6
+ include Helper
4
7
  attr_accessor :player_hash
5
8
  def initialize(player_hash)
6
9
  @player = player_hash
@@ -13,15 +16,8 @@ module Fielding
13
16
  avg = player_avg.round(3)
14
17
  # code smell - make this a several function called somewhere since this is used over multiple stats
15
18
  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
19
+ figure_trailing_zeroes(fielding_percentage)
23
20
  end
24
-
25
21
  end
26
22
 
27
23
  end
@@ -0,0 +1,14 @@
1
+ module Helper
2
+
3
+ def figure_trailing_zeroes(arg)
4
+ revised_number = arg
5
+ if revised_number.length === 3
6
+ revised_number = "#{revised_number}0"
7
+ elsif revised_number.length === 2
8
+ revised_number = "#{revised_number}00"
9
+ else
10
+ return revised_number
11
+ end
12
+ end
13
+
14
+ end
@@ -1,4 +1,25 @@
1
+ require 'baseball/helper'
2
+
1
3
  module Running
2
4
 
5
+ class Runner
6
+ include Helper
7
+ attr_accessor :runner_hash
8
+ def initialize(runner_hash)
9
+ @runner = runner_hash
10
+ end
11
+
12
+ def stolen_base_percentage
13
+ player_stolen_base_percentage = @runner[:stolen_bases].to_f / (@runner[:stolen_bases ].to_f + @runner[:caught_stealing].to_f)
14
+ stealing_average = player_stolen_base_percentage.round(3)
15
+ average_string = stealing_average.to_s.sub!("0", "")
16
+ figure_trailing_zeroes(average_string)
17
+ end
3
18
 
4
- end
19
+ def stolen_base_runs
20
+ #Created by Total baseball
21
+ # (.3 x stolen bases) - (.6 x caught stealing)
22
+ end
23
+ end
24
+
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Baseball
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baseball
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Busby
@@ -57,6 +57,7 @@ files:
57
57
  - lib/baseball.rb
58
58
  - lib/baseball/batting.rb
59
59
  - lib/baseball/fielding.rb
60
+ - lib/baseball/helper.rb
60
61
  - lib/baseball/pitching.rb
61
62
  - lib/baseball/running.rb
62
63
  - lib/baseball/version.rb