mlb-scores-standings 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb49cda32a34852775480fa8526ccb35353edc4a
4
+ data.tar.gz: a0f0f68598821661e2b989582905261fe4212115
5
+ SHA512:
6
+ metadata.gz: 359e78e08a66407c3e865494586ccb9b63f251051a6f31e02e5d8e634335eebde14eed20e76177c175ac6b8b5ba9973faf23e6d76933d4e6da67e30b0f93d407
7
+ data.tar.gz: 7286721e6d8bf1dee067ecf1dffd016529da4d9907f77afb77cdbc450ed4df2a5e5f59915de4070e85ba1709fd89f68af3373d27bb50924b179ca07cf57913ab
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mlb.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Mlb
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mlb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mlb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mlb
22
+
23
+ ## Usage
24
+
25
+ select a menu option by entering in 1,2 or 3
26
+ if 1 is selected, enter in a game number to see winning and loser pitchers and if their was a save
27
+ if 2 is selected, the standings will print out and return you to menu
28
+ if 3 is selected the program will print out the biggest run differential from the game.
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/drumitar/mlb.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mlb"
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/mlb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mlb"
5
+ #require './lib/mlb'
6
+
7
+ Mlb::CLI.new.call
data/bin/setup ADDED
@@ -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
data/lib/mlb.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'nokogiri'
2
+ require 'pry'
3
+ require 'open-uri'
4
+ require 'openssl'
5
+
6
+
7
+
8
+ require_relative "./mlb/version"
9
+ require_relative './mlb/game'
10
+ require_relative './mlb/cli'
data/lib/mlb/cli.rb ADDED
@@ -0,0 +1,61 @@
1
+
2
+ #our Cli Controller
3
+ class Mlb::CLI
4
+
5
+ def call
6
+ puts "Today's final scores."
7
+ list_games
8
+ menu
9
+ end
10
+
11
+ def list_games
12
+ @games = Mlb::Game.scrape_games
13
+ @games.each.with_index(1) do |game, i|
14
+ puts "#{i}) #{game.winner}:#{game.score_w} #{game.loser}:#{game.score_l}"
15
+ end
16
+
17
+ end
18
+
19
+ def menu
20
+ puts "\nSelect 1 2 3 or exit to leave\n"
21
+ puts "\n 1 - show more info on games"
22
+ puts "\n 2 - show standings"
23
+ puts "\n 3 - show biggest run differential"
24
+ input = gets.strip
25
+ if input.to_i == 1
26
+ puts "enter a game number 1 - #{@games.count} to see more info"
27
+ input = gets.strip.to_i-1
28
+ print_more_info(input)
29
+ puts "\nWould you like to continue Y or N ? \n"
30
+ input = gets.strip.downcase
31
+ if input == "y"
32
+ menu
33
+ elsif input == 'n'
34
+ goodbye
35
+ else
36
+ puts "\nPlease enter Y or N only"
37
+ menu
38
+ end
39
+ elsif input.to_i == 2
40
+ Mlb::Game.scrape_standings
41
+ menu
42
+ elsif input.to_i == 3
43
+ Mlb::Game.find_lopside_score
44
+ menu
45
+ elsif input.downcase == "exit"
46
+ goodbye
47
+ else
48
+ menu
49
+ end
50
+ end
51
+
52
+ def print_more_info(input)
53
+ puts "winning pitcher".green + ": #{@games[input].pitcher_w}".cyan + " losing pitcher".red + ": #{@games[input].pitcher_l}".cyan + " #{@games[input].save}"
54
+ end
55
+
56
+ def goodbye
57
+ puts "Thankyou! Have a great day!".yellow
58
+ exit
59
+ end
60
+
61
+ end
data/lib/mlb/game.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'colorize'
2
+
3
+ class Mlb::Game
4
+
5
+ attr_accessor :winner, :loser, :score_w, :score_l, :pitcher_w, :pitcher_l, :save
6
+
7
+ @doc = Nokogiri::HTML(open("http://www.baseball-reference.com/boxes/"))
8
+
9
+ def self.scrape_games
10
+ games = []
11
+
12
+ the_game = nil
13
+
14
+ @doc.css(".game_summary").each do |game|
15
+ the_game = self.new
16
+ the_game.winner = game.css(".winner td[1]").text.green
17
+ the_game.loser = game.css(".loser td[1]").text.red
18
+ the_game.score_w = game.css(".winner td[2]").text
19
+ the_game.score_l = game.css(".loser td[2]").text
20
+ the_game.pitcher_w = game.css("table:nth-child(2) tr:nth-child(1) td:nth-child(2)").text.light_green
21
+ the_game.pitcher_l = game.css("table:nth-child(2) tr:nth-child(2) td:nth-child(2)").text.light_red
22
+ the_game.save = game.css("table:nth-child(2) tr:nth-child(3) td:nth-child(2)").text.yellow
23
+ if the_game.save != ""
24
+ the_game.save = the_game.save + (" S").yellow
25
+ end
26
+ games << the_game
27
+ end
28
+ games
29
+ end
30
+
31
+ def self.scrape_standings
32
+ puts "\n AL STANDINGS"
33
+ puts "\n TM W L WIN% GB"
34
+ @doc.css("#standings-upto-AL-overall tr").each do |row|
35
+ title = row.css("tr:nth-child(1)").text
36
+ team = row.css("th a").text
37
+ wins = row.css("td:nth-child(2)").text.green
38
+ losses = row.css("td:nth-child(3)").text.red
39
+ win_percentage = row.css("td:nth-child(4)").text.cyan
40
+ games_back = row.css("td:nth-child(5)").text.yellow
41
+ puts " #{team} #{wins} #{losses} #{win_percentage} #{games_back}"
42
+ end
43
+
44
+ puts "\n NL STANDINGS"
45
+ puts "\n TM W L WIN% GB"
46
+ @doc.css("#standings-upto-NL-overall tr").each do |row|
47
+ team = row.css("th a").text
48
+ wins = row.css("td:nth-child(2)").text.green
49
+ losses = row.css("td:nth-child(3)").text.red
50
+ win_percentage = row.css("td:nth-child(4)").text.cyan
51
+ games_back = row.css("td:nth-child(5)").text.yellow
52
+ puts " #{team} #{wins} #{losses} #{win_percentage} #{games_back}"
53
+ end
54
+ end
55
+
56
+
57
+ def self.find_lopside_score
58
+ scores = []
59
+ games = self.scrape_games
60
+ games.each do | game |
61
+ scores << (game.score_w.to_i - game.score_l.to_i)
62
+ end
63
+ puts "the biggest margin of victory today was #{scores.max} runs!".green
64
+ end
65
+
66
+
67
+ end
@@ -0,0 +1,3 @@
1
+ module Mlb
2
+ VERSION = "0.1.0"
3
+ end
data/mlb.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mlb/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mlb-scores-standings"
8
+ spec.version = Mlb::VERSION
9
+ spec.authors = ["Drumitar"]
10
+ spec.email = ["derekpelt@gmail.com"]
11
+
12
+ spec.description = %q{Write a longer description or delete this line.}
13
+ spec.summary = spec.description
14
+ spec.homepage = ""
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ #else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.15"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "pry", ">= 0"
35
+ spec.add_development_dependency "nokogiri", ">= 0"
36
+ spec.add_development_dependency "colorize", ">=0"
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mlb-scores-standings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Drumitar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-16 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: pry
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: colorize
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: Write a longer description or delete this line.
84
+ email:
85
+ - derekpelt@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/mlb
96
+ - bin/setup
97
+ - lib/mlb.rb
98
+ - lib/mlb/cli.rb
99
+ - lib/mlb/game.rb
100
+ - lib/mlb/version.rb
101
+ - mlb.gemspec
102
+ homepage: ''
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.6.11
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Write a longer description or delete this line.
125
+ test_files: []