mlb-scores-standings 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb49cda32a34852775480fa8526ccb35353edc4a
4
- data.tar.gz: a0f0f68598821661e2b989582905261fe4212115
3
+ metadata.gz: 38ef833da21a9a840264384c8933b12c67608e19
4
+ data.tar.gz: e2f80b28b8b5086d87dc4684ee41ead1474cbf90
5
5
  SHA512:
6
- metadata.gz: 359e78e08a66407c3e865494586ccb9b63f251051a6f31e02e5d8e634335eebde14eed20e76177c175ac6b8b5ba9973faf23e6d76933d4e6da67e30b0f93d407
7
- data.tar.gz: 7286721e6d8bf1dee067ecf1dffd016529da4d9907f77afb77cdbc450ed4df2a5e5f59915de4070e85ba1709fd89f68af3373d27bb50924b179ca07cf57913ab
6
+ metadata.gz: 150f145110777d29320a4cc8edc1589c1646fe71472d9992cf99518e523d57a8c073e7553828879fac81403528c2fe12d15546435c47f1252ab431d2696f7b99
7
+ data.tar.gz: 1dbcdda85c41785519a0e47d37ebfbf507b8fcd39bca7bc9e3ecaeceac6c9d0ff8df86bb19cc4042d2003caa67794c375318756bed5e77b6b52ce015d20bae99
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "mlb"
4
+ require_relative "../lib/mlb"
5
+
5
6
  #require './lib/mlb'
6
7
 
7
- Mlb::CLI.new.call
8
+ Mlb::CLI.new.call
data/lib/mlb.rb CHANGED
@@ -2,9 +2,11 @@ require 'nokogiri'
2
2
  require 'pry'
3
3
  require 'open-uri'
4
4
  require 'openssl'
5
+ require 'colorize'
5
6
 
6
7
 
7
8
 
8
9
  require_relative "./mlb/version"
9
10
  require_relative './mlb/game'
10
11
  require_relative './mlb/cli'
12
+ require_relative './mlb/scraper'
@@ -4,13 +4,13 @@ class Mlb::CLI
4
4
 
5
5
  def call
6
6
  puts "Today's final scores."
7
+ Mlb::Scraper.scrape_games
7
8
  list_games
8
9
  menu
9
10
  end
10
11
 
11
12
  def list_games
12
- @games = Mlb::Game.scrape_games
13
- @games.each.with_index(1) do |game, i|
13
+ Mlb::Game.all.each.with_index(1) do |game, i|
14
14
  puts "#{i}) #{game.winner}:#{game.score_w} #{game.loser}:#{game.score_l}"
15
15
  end
16
16
 
@@ -21,26 +21,36 @@ class Mlb::CLI
21
21
  puts "\n 1 - show more info on games"
22
22
  puts "\n 2 - show standings"
23
23
  puts "\n 3 - show biggest run differential"
24
+ games = Mlb::Game.all
24
25
  input = gets.strip
25
26
  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
27
+ puts "enter a game number 1 - #{games.count} to see more info"
28
+ input = gets.strip.to_i
29
+ if input.between?(1,games.count)
30
+ input -= 1
31
+ print_more_info(input)
32
+ puts "\nWould you like to continue Y or N ? \n"
33
+ input = gets.strip.downcase
34
+ if input == "y"
35
+ menu
36
+ elsif input == 'n'
37
+ goodbye
38
+ else
39
+ puts "\nPlease enter Y or N only"
40
+ menu
41
+ end
42
+ else
43
+ puts "please enter a number between 1 and #{games.count}"
44
+ menu
45
+ end
39
46
  elsif input.to_i == 2
40
- Mlb::Game.scrape_standings
47
+ Mlb::Scraper.scrape_standings
41
48
  menu
42
49
  elsif input.to_i == 3
43
- Mlb::Game.find_lopside_score
50
+ #Mlb::Game.find_lopside_score
51
+ game_object = Mlb::Game.find_big_win
52
+ puts "the biggest margin of victory today was #{game_object.score_w.to_i - game_object.score_l.to_i} runs !".yellow + "\nfrom the game #{game_object.winner}: #{game_object.score_w} #{game_object.loser}: #{game_object.score_l}"
53
+
44
54
  menu
45
55
  elsif input.downcase == "exit"
46
56
  goodbye
@@ -50,7 +60,8 @@ class Mlb::CLI
50
60
  end
51
61
 
52
62
  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}"
63
+ games = Mlb::Game.all
64
+ puts "winning pitcher".green + ": #{games[input].pitcher_w}".cyan + " losing pitcher".red + ": #{games[input].pitcher_l}".cyan + " #{games[input].save}"
54
65
  end
55
66
 
56
67
  def goodbye
@@ -4,34 +4,18 @@ class Mlb::Game
4
4
 
5
5
  attr_accessor :winner, :loser, :score_w, :score_l, :pitcher_w, :pitcher_l, :save
6
6
 
7
- @doc = Nokogiri::HTML(open("http://www.baseball-reference.com/boxes/"))
7
+ @@doc = Nokogiri::HTML(open("http://www.baseball-reference.com/boxes/"))
8
8
 
9
- def self.scrape_games
10
- games = []
9
+ @@games = []
11
10
 
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
11
+ def self.all
12
+ @@games
29
13
  end
30
14
 
31
15
  def self.scrape_standings
32
16
  puts "\n AL STANDINGS"
33
17
  puts "\n TM W L WIN% GB"
34
- @doc.css("#standings-upto-AL-overall tr").each do |row|
18
+ @@doc.css("#standings-upto-AL-overall tr").each do |row|
35
19
  title = row.css("tr:nth-child(1)").text
36
20
  team = row.css("th a").text
37
21
  wins = row.css("td:nth-child(2)").text.green
@@ -43,7 +27,7 @@ class Mlb::Game
43
27
 
44
28
  puts "\n NL STANDINGS"
45
29
  puts "\n TM W L WIN% GB"
46
- @doc.css("#standings-upto-NL-overall tr").each do |row|
30
+ @@doc.css("#standings-upto-NL-overall tr").each do |row|
47
31
  team = row.css("th a").text
48
32
  wins = row.css("td:nth-child(2)").text.green
49
33
  losses = row.css("td:nth-child(3)").text.red
@@ -53,15 +37,12 @@ class Mlb::Game
53
37
  end
54
38
  end
55
39
 
40
+ def difference
41
+ self.score_w.to_i - self.score_l.to_i
42
+ end
56
43
 
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
44
+ def self.find_big_win
45
+ self.all.sort { |a, b| b.difference <=> a.difference}.first
64
46
  end
65
47
 
66
-
67
- end
48
+ end
@@ -0,0 +1,57 @@
1
+
2
+
3
+ class Mlb::Scraper
4
+
5
+ @@doc = Nokogiri::HTML(open("http://www.baseball-reference.com/boxes/"))
6
+
7
+
8
+ def self.scrape_games
9
+ #games = []
10
+
11
+ the_game = nil
12
+
13
+ @@doc.css(".game_summary").each do |game|
14
+ the_game = Mlb::Game.new
15
+ the_game.winner = game.css(".winner td[1]").text.green
16
+ the_game.loser = game.css(".loser td[1]").text.red
17
+ the_game.score_w = game.css(".winner td[2]").text
18
+ the_game.score_l = game.css(".loser td[2]").text
19
+ the_game.pitcher_w = game.css("table:nth-child(2) tr:nth-child(1) td:nth-child(2)").text.light_green
20
+ the_game.pitcher_l = game.css("table:nth-child(2) tr:nth-child(2) td:nth-child(2)").text.light_red
21
+ the_game.save = game.css("table:nth-child(2) tr:nth-child(3) td:nth-child(2)").text.yellow
22
+ if the_game.save != ""
23
+ the_game.save = the_game.save + (" S").yellow
24
+ end
25
+ Mlb::Game.all << the_game
26
+ end
27
+ end
28
+
29
+ def self.scrape_standings
30
+ puts "\n AL STANDINGS"
31
+ puts "\n TM W L WIN% GB"
32
+ @@doc.css("#standings-upto-AL-overall tr").each do |row|
33
+ title = row.css("tr:nth-child(1)").text
34
+ team = row.css("th a").text
35
+ wins = row.css("td:nth-child(2)").text.green
36
+ losses = row.css("td:nth-child(3)").text.red
37
+ win_percentage = row.css("td:nth-child(4)").text.cyan
38
+ games_back = row.css("td:nth-child(5)").text.yellow
39
+ puts " #{team} #{wins} #{losses} #{win_percentage} #{games_back}"
40
+ end
41
+
42
+ puts "\n NL STANDINGS"
43
+ puts "\n TM W L WIN% GB"
44
+ @@doc.css("#standings-upto-NL-overall tr").each do |row|
45
+ team = row.css("th a").text
46
+ wins = row.css("td:nth-child(2)").text.green
47
+ losses = row.css("td:nth-child(3)").text.red
48
+ win_percentage = row.css("td:nth-child(4)").text.cyan
49
+ games_back = row.css("td:nth-child(5)").text.yellow
50
+ puts " #{team} #{wins} #{losses} #{win_percentage} #{games_back}"
51
+ end
52
+ end
53
+
54
+
55
+
56
+
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Mlb
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlb-scores-standings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Drumitar
7
+ - Derek Pelt
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-16 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '1.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: pry
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: colorize
70
+ name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -80,27 +80,36 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Write a longer description or delete this line.
84
- email:
85
- - derekpelt@gmail.com
86
- executables: []
83
+ - !ruby/object:Gem::Dependency
84
+ name: colorize
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: mlb scores and standings
98
+ email: derekpelt@gmail.com
99
+ executables:
100
+ - mlb-scores-standings
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
- - ".gitignore"
91
- - Gemfile
92
- - README.md
93
- - Rakefile
94
- - bin/console
95
- - bin/mlb
96
- - bin/setup
104
+ - bin/mlb-scores-standings
97
105
  - lib/mlb.rb
98
106
  - lib/mlb/cli.rb
99
107
  - lib/mlb/game.rb
108
+ - lib/mlb/scraper.rb
100
109
  - lib/mlb/version.rb
101
- - mlb.gemspec
102
- homepage: ''
103
- licenses: []
110
+ homepage: http://rubygems.org/gems/mlb-scores-standings
111
+ licenses:
112
+ - MIT
104
113
  metadata: {}
105
114
  post_install_message:
106
115
  rdoc_options: []
@@ -121,5 +130,5 @@ rubyforge_project:
121
130
  rubygems_version: 2.6.11
122
131
  signing_key:
123
132
  specification_version: 4
124
- summary: Write a longer description or delete this line.
133
+ summary: mlb scores and standings
125
134
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in mlb.gemspec
4
- gemspec
data/README.md DELETED
@@ -1,38 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
@@ -1,14 +0,0 @@
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/setup DELETED
@@ -1,8 +0,0 @@
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
@@ -1,38 +0,0 @@
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