mlb_scoreboard 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51af5401f47d1929a44a09003bd5d0589371633c
4
+ data.tar.gz: f8f3824f60d43b2019e86a63d6463a43d1c750a7
5
+ SHA512:
6
+ metadata.gz: a19d3e6a747d3cf1c85864c94386d8882ba80d2f77726a616bdb10996ceb2fc33930493ca75ca74d70fed9bfbbe3a7b49b33edd03d0ca471c9495cf434831b9a
7
+ data.tar.gz: 4c63b793c6bf5c4eae60e4622309f0305b4c3ae8701f93d0f1e8ec2cde0d69921e73e0df011b4d7094690bbf6d573fdbfe5749cff3d0d09935835e62dac4badd
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at ffrostt@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scoreboard.gemspec
4
+ gemspec
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mlb_scoreboard (0.1.0)
5
+ json (~> 1.8.3)
6
+ nokogiri (~> 1.6.8)
7
+ terminal-table (~> 1.6.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.2.5)
13
+ json (1.8.3)
14
+ mini_portile2 (2.1.0)
15
+ nokogiri (1.6.8)
16
+ mini_portile2 (~> 2.1.0)
17
+ pkg-config (~> 1.1.7)
18
+ pkg-config (1.1.7)
19
+ rake (10.4.2)
20
+ rspec (3.4.0)
21
+ rspec-core (~> 3.4.0)
22
+ rspec-expectations (~> 3.4.0)
23
+ rspec-mocks (~> 3.4.0)
24
+ rspec-core (3.4.4)
25
+ rspec-support (~> 3.4.0)
26
+ rspec-expectations (3.4.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-mocks (3.4.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-support (3.4.1)
33
+ terminal-table (1.6.0)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.12)
40
+ mlb_scoreboard!
41
+ rake (~> 10.0)
42
+ rspec (~> 3.0)
43
+
44
+ BUNDLED WITH
45
+ 1.12.5
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 steveafrost
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,31 @@
1
+ ## How to Setup the Gem ##
2
+
3
+ 1. Plan the gem. Imagine your interface.
4
+ 2. Start with a project structure - checkout bundler
5
+ 3. Start with an entry point - the file run
6
+ 4. force that to build the CLI interface
7
+ 5. stub out the interface
8
+ 6. start making things real
9
+ 7. discover objects
10
+ 8. program
11
+
12
+ ## Objective ##
13
+ To build a gem called Scoreboard which displays the scores from yesterday's MLB games.
14
+
15
+ ## Behavior ##
16
+ 2. All matches are listed from current day
17
+ 3. User selects a number and that game is displayed with runs, hits, errors
18
+ 3. User is able to type 'exit' to exit CLI
19
+
20
+ ## What is a score? ##
21
+ * A score has teams
22
+ * A score has a time
23
+ * A score has runs, hits, and errors
24
+
25
+ ## Extendability ##
26
+ * The gem will later be extended to include a way to get scores from one team for their last 7 games. If this is able to be programmed while building the primary objective, it will be incorporated.
27
+ * Several other sports to be included at a later date
28
+
29
+ ## Other Notes ##
30
+ * self.today interates through scoreboard and displays each score
31
+ * Does each score need to be an object?
@@ -0,0 +1,44 @@
1
+ # Scoreboard
2
+
3
+ This gem scrapes and displays yesterday's MLB matchups and their details including hits, runs, and errors from the official MLB API.
4
+
5
+ Future version plans
6
+ 1. Display scores from a day input by user.
7
+ 2. Display the last 7 games of a team input by user.
8
+ 3. Ability to show the league standings and drill down into division standings.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'mlb_scoreboard'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install mlb_scoreboard
25
+
26
+ ## Usage
27
+
28
+ Once installed, running bin/mlb_scoreboard will load all MLB matchups from the previous day. The user can then type a number that corresponds to a matchup and see more details about that matchup in a formatted table. The details include hits, runs, and errors. At any time the user can type 'exit' to exit the program.
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. 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/steveafrost/scoreboard-cli-gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mlb_scoreboard"
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
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require './lib/mlb_scoreboard.rb'
3
+
4
+ MLBScoreboard::CLI.new.start
@@ -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,74 @@
1
+ class MLBScoreboard::CLI
2
+
3
+ def start
4
+ welcome
5
+ menu
6
+ goodbye
7
+ end
8
+
9
+ def welcome
10
+ puts "*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"
11
+ puts "*~* Welcome to MLB Scoreboard *~*"
12
+ puts "*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"
13
+ end
14
+
15
+ def menu
16
+ list_games
17
+ puts "\n"
18
+ puts "Please enter the number of the game to see the details or type exit: "
19
+ user_input = gets.strip.to_i
20
+
21
+ if user_input > 0 && user_input <= @matchups.length
22
+ box_score(user_input)
23
+ elsif user_input > @matchups.length
24
+ menu
25
+ elsif user_input == "exit"
26
+ exit
27
+ else
28
+ list_games
29
+ end
30
+ end
31
+
32
+ def list_games
33
+ puts "\nYesterday's Games Around the MLB"
34
+ @matchups = MLBScoreboard::Matchups.today
35
+ @matchups.each.with_index(1) do |matchup, index|
36
+ puts "#{index}. #{matchup}"
37
+ end
38
+ end
39
+
40
+ def box_score(user_input)
41
+ user_input = user_input.to_i - 1
42
+
43
+ teams = MLBScoreboard::Matchups.scrape_teams(user_input)
44
+ runs = MLBScoreboard::Matchups.scrape_runs(user_input)
45
+ hits = MLBScoreboard::Matchups.scrape_hits(user_input)
46
+ errors = MLBScoreboard::Matchups.scrape_errors(user_input)
47
+ home_line = [teams[0], runs[0], hits[0], errors[0]]
48
+ away_line = [teams[1], runs[1], hits[1], errors[1]]
49
+
50
+ rows = []
51
+ rows << home_line
52
+ rows << away_line
53
+
54
+ table = Terminal::Table.new :headings => ['Team', 'R', 'H', 'E'], :rows => rows
55
+
56
+ puts table
57
+
58
+ puts "\nWould you like to see the list again or exit?"
59
+ user_input = gets.strip
60
+ if user_input == "exit"
61
+ exit
62
+ else
63
+ menu
64
+ end
65
+
66
+ end
67
+
68
+ def goodbye
69
+ puts "*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"
70
+ puts "*~* Thanks for using Scoreboard *~*"
71
+ puts "*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"
72
+ end
73
+
74
+ end
@@ -0,0 +1,70 @@
1
+ class MLBScoreboard::Matchups
2
+
3
+ attr_accessor :teams, :runs, :hits, :errors, :time
4
+
5
+ def self.today
6
+ self.scrape_matchups
7
+ end
8
+
9
+ def self.scrape_matchups
10
+ teams = []
11
+
12
+ #clock to get previous day so that we get those day's scores
13
+ time = DateTime.now - 1
14
+ day = time.strftime("%d")
15
+ month = time.strftime("%m")
16
+ year = time.strftime("%Y")
17
+
18
+ #scrape of all matchups
19
+ url = "http://m.mlb.com/gdcross/components/game/mlb/year_#{year}/month_#{month}/day_#{day}/master_scoreboard.json"
20
+ doc = Nokogiri::HTML(open(url))
21
+
22
+ #parsing the data down to the specific key values we need
23
+ data_hash = JSON.parse(doc)
24
+ @each_game = data_hash["data"]["games"]["game"]
25
+
26
+ #loop through games, shovel teams into array, format array into quality string for user display
27
+ i = 0
28
+ while i < @each_game.length
29
+ home_team = @each_game[i]["home_team_name"]
30
+ away_team = @each_game[i]["away_team_name"]
31
+ teams << "#{home_team} vs #{away_team}"
32
+ i += 1
33
+ end
34
+
35
+ teams
36
+ end
37
+
38
+ def self.scrape_teams(i)
39
+ team = []
40
+ team << @each_game[i]["home_team_name"]
41
+ team << @each_game[i]["away_team_name"]
42
+ end
43
+
44
+ def self.scrape_time(i)
45
+ time = @each_game[i]["time"]
46
+ "#{time}"
47
+ end
48
+
49
+ def self.scrape_runs(i)
50
+ runs = []
51
+ runs << @each_game[i]["linescore"]["r"]["home"]
52
+ runs << @each_game[i]["linescore"]["r"]["away"]
53
+ runs
54
+ end
55
+
56
+ def self.scrape_hits(i)
57
+ hits = []
58
+ hits << @each_game[i]["linescore"]["h"]["home"]
59
+ hits << @each_game[i]["linescore"]["h"]["away"]
60
+ hits
61
+ end
62
+
63
+ def self.scrape_errors(i)
64
+ errors = []
65
+ errors << @each_game[i.to_i - 1]["linescore"]["e"]["home"]
66
+ errors << @each_game[i.to_i - 1]["linescore"]["e"]["away"]
67
+ errors
68
+ end
69
+
70
+ end
@@ -0,0 +1,9 @@
1
+ require 'terminal-table'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'json'
5
+
6
+ require 'bundler/setup'
7
+ require 'version.rb'
8
+ require 'cli.rb'
9
+ require 'matchups.rb'
@@ -0,0 +1,3 @@
1
+ module MLBScoreboard
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mlb_scoreboard"
8
+ spec.version = MLBScoreboard::VERSION
9
+ spec.authors = ["Steve Frost"]
10
+ spec.email = ["ffrostt@gmail.com"]
11
+
12
+ spec.summary = "MLB Scoreboard is a CLI program that displays matchups and box scores from the official MLB API"
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/steveafrost/scoreboard-cli-gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_runtime_dependency "terminal-table", "~> 1.6.0"
26
+ spec.add_runtime_dependency "nokogiri", "~>1.6.8"
27
+ spec.add_runtime_dependency "json", "~> 1.8.3"
28
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mlb_scoreboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Steve Frost
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-25 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: terminal-table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.8
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.8
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.3
97
+ description: MLB Scoreboard is a CLI program that displays matchups and box scores
98
+ from the official MLB API
99
+ email:
100
+ - ffrostt@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - CODE_OF_CONDUCT.md
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - NOTES.md
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/mlb_scoreboard
114
+ - bin/setup
115
+ - lib/cli.rb
116
+ - lib/matchups.rb
117
+ - lib/mlb_scoreboard.rb
118
+ - lib/version.rb
119
+ - mlb_scoreboard.gemspec
120
+ homepage: https://github.com/steveafrost/scoreboard-cli-gem
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: MLB Scoreboard is a CLI program that displays matchups and box scores from
144
+ the official MLB API
145
+ test_files: []