nhl_scores 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ad5d2576599fd06f992809804a35a3d25ea9e20
4
+ data.tar.gz: daa7df9594b8f60de4232c97051169b850ce3d0f
5
+ SHA512:
6
+ metadata.gz: 6833e8001310bccde36a7260da9e5e6fe295551fde9fce864ad496e3662d3b7d86b519bf156cf263ac110ab3275e1e3cc1ada0ec6be84241d228a870b4a1dd09
7
+ data.tar.gz: ee53ea6fde55a5e3465d8a5896089bfa7c0d8dc11e239f59bf14851a353c2de387933a05ac554f85b73813b26dc5d824a35e39f028ed84a53abd24384062f7a1
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "httparty"
6
+ gem "thor"
7
+
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rspec", "~> 2.14"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.0"
15
+ gem "jeweler", "~> 1.8.7"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ diff-lcs (1.2.5)
7
+ faraday (0.8.8)
8
+ multipart-post (~> 1.2.0)
9
+ git (1.2.6)
10
+ github_api (0.10.1)
11
+ addressable
12
+ faraday (~> 0.8.1)
13
+ hashie (>= 1.2)
14
+ multi_json (~> 1.4)
15
+ nokogiri (~> 1.5.2)
16
+ oauth2
17
+ hashie (2.0.5)
18
+ highline (1.6.20)
19
+ httparty (0.12.0)
20
+ json (~> 1.8)
21
+ multi_xml (>= 0.5.2)
22
+ httpauth (0.2.0)
23
+ jeweler (1.8.8)
24
+ builder
25
+ bundler (~> 1.0)
26
+ git (>= 1.2.5)
27
+ github_api (= 0.10.1)
28
+ highline (>= 1.6.15)
29
+ nokogiri (= 1.5.10)
30
+ rake
31
+ rdoc
32
+ json (1.8.1)
33
+ jwt (0.1.8)
34
+ multi_json (>= 1.5)
35
+ multi_json (1.8.2)
36
+ multi_xml (0.5.5)
37
+ multipart-post (1.2.0)
38
+ nokogiri (1.5.10)
39
+ oauth2 (0.9.2)
40
+ faraday (~> 0.8)
41
+ httpauth (~> 0.2)
42
+ jwt (~> 0.1.4)
43
+ multi_json (~> 1.0)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ rack (1.5.2)
47
+ rake (10.1.1)
48
+ rdoc (3.12.2)
49
+ json (~> 1.4)
50
+ rspec (2.14.1)
51
+ rspec-core (~> 2.14.0)
52
+ rspec-expectations (~> 2.14.0)
53
+ rspec-mocks (~> 2.14.0)
54
+ rspec-core (2.14.7)
55
+ rspec-expectations (2.14.4)
56
+ diff-lcs (>= 1.1.3, < 2.0)
57
+ rspec-mocks (2.14.4)
58
+ thor (0.18.1)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ bundler (~> 1.0)
65
+ httparty
66
+ jeweler (~> 1.8.7)
67
+ rdoc (~> 3.12)
68
+ rspec (~> 2.14)
69
+ thor
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Travis Loncar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ NHL Scores
2
+ ----------
3
+
4
+ [![Build Status](https://travis-ci.org/tbloncar/nhl_scores.png?branch=master)](https://travis-ci.org/tbloncar/nhl_scores)
5
+
6
+ Use Ruby to fetch details about recent, current, and upcoming regular season NHL matchups.
7
+
8
+ #### Installation
9
+
10
+ Tested with `ruby-2.0.0-p247`.
11
+
12
+ gem install nhl_scores
13
+
14
+ #### Usage Details
15
+
16
+ An instance of the `NHLScores::Games` class gives you access to NHL game
17
+ data fetched from [this
18
+ endpoint](http://live.nhle.com/GameData/RegularSeasonScoreboardv3.jsonp).
19
+ Instances of this class are initialized with an array of
20
+ `NHLScores::Game` instances in the `games` attribute. The
21
+ following methods are at your disposal for interacting with
22
+ the `NHLScores::Games` instance.
23
+
24
+ - `NHLScores::Games#all` - Returns an array of all games available via the endpoint
25
+ - `NHLScores::Games#recent` - Returns an array of games recently completed
26
+ - `NHLScores::Games#in_progress` - Returns an array of current games (including
27
+ those in pre-game)
28
+ - `NHLScores::Games#upcoming` - Returns an array of upcoming games
29
+
30
+ Each array consists of zero or more instances of the aforementioned
31
+ `NHLScores::Game` class. Each game instance has the following properties:
32
+
33
+ - `id`
34
+ - `date`
35
+ - `start_time`
36
+ - `home_team`
37
+ - `away_team`
38
+ - `home_team_score`
39
+ - `away_team_score`
40
+ - `status`
41
+ - `ustv` (US television)
42
+ - `catv` (Canadian television)
43
+
44
+ The public API also exposes the following methods:
45
+
46
+ - `NHLScores::Game#winner` - Returns the winning team for a completed game
47
+ - `NHLScores::Game#loser` - Returns the losing team for a completed game
48
+ - `NHLScores::Game#winner_score` - Returns the winning score for a completed game
49
+ - `NHLScores::Game#losing_score` - Returns the losing score for a completed game
50
+ - `NHLScores::Game#leader` - Returns the leading team for a game in progress
51
+ - `NHLScores::Game#trailer` - Returns the trailing team for a game in progress
52
+ - `NHLScores::Game#leader_score` - Returns the leading score for a game in progress
53
+ - `NHLScores::Game#trailer_score` - Returns the trailing score for a game in progress
54
+
55
+ #### CLI
56
+
57
+ This gem comes with a CLI that can be used to fetch details about recent,
58
+ current, and upcoming games via the command line.
59
+
60
+ **Recent Scores**
61
+
62
+ nhl recent
63
+
64
+ **Current Scores**
65
+
66
+ nhl current
67
+
68
+ **Upcoming Games**
69
+
70
+ nhl upcoming
71
+
72
+ **Narrow the Response**
73
+
74
+ You can use the `--team (-t)` option with a team abbreviation to
75
+ narrow your results. The full list of team abbreviation-name mappings
76
+ can be found in `lib/nhl_scores.rb`.
77
+
78
+ nhl upcoming -t pit
79
+
80
+ Let's go Pens.
81
+
82
+ #### License
83
+
84
+ Copyright (c) 2014 Travis Loncar.
85
+
86
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
87
+ this software and associated documentation files (the "Software"), to deal in
88
+ the Software without restriction, including without limitation the rights to
89
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
90
+ of the Software, and to permit persons to whom the Software is furnished to do
91
+ so, subject to the following conditions:
92
+
93
+ The above copyright notice and this permission notice shall be included in all
94
+ copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
97
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
99
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
100
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
101
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
102
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "nhl_scores"
18
+ gem.homepage = "http://github.com/tbloncar/nhl_scores"
19
+ gem.license = "MIT"
20
+ gem.summary = "Use Ruby to grab live/recent NHL scores and upcoming matchup details."
21
+ gem.description = "Use Ruby to grab live/recent NHL scores and upcoming matchup details. This gem ships with a minimal CLI."
22
+ gem.email = "loncar.travis@gmail.com"
23
+ gem.authors = ["Travis Loncar"]
24
+ # dependencies defined in Gemfile
25
+ gem.add_dependency 'httparty'
26
+ gem.add_dependency 'thor'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rdoc/task'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "nhl_scores #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/nhl ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'nhl_scores'
4
+
5
+ NHLScores::CLI.start(ARGV)
@@ -0,0 +1,85 @@
1
+ require 'thor'
2
+
3
+ module NHLScores
4
+ class CLI < Thor
5
+ attr_reader :games
6
+
7
+ def initialize(*args)
8
+ super
9
+ @games = NHLScores::Games.new
10
+ end
11
+
12
+ desc 'recent', 'get scores of RECENT games'
13
+ method_option 'team', aliases: '-t', type: :string, default: nil, desc: 'Specify a single team by abbreviation.'
14
+ def recent
15
+ games = @games.recent(team_abbrev: options['team'])
16
+ output_games(games, 'recent')
17
+ end
18
+
19
+ desc 'current', 'get scores of CURRENT games'
20
+ method_option 'team', aliases: '-t', type: :string, default: nil, desc: 'Specify a single team by abbreviation.'
21
+ def current
22
+ games = @games.in_progress(team_abbrev: options['team'])
23
+ output_games(games, 'current')
24
+ end
25
+
26
+ desc 'upcoming', 'get UPCOMING games on schedule'
27
+ method_option 'team', aliases: '-t', type: :string, default: nil, desc: 'Specify a single team by abbreviation.'
28
+ def upcoming
29
+ games = @games.upcoming(team_abbrev: options['team'])
30
+ output_games(games, 'upcoming')
31
+ end
32
+
33
+ private
34
+
35
+ def output_games(games, type)
36
+ puts
37
+ title = "#{type.upcase} NHL GAMES"
38
+ underline = "-" * title.length
39
+ puts title.align.yellow
40
+ puts underline.align
41
+ puts
42
+ if games.any?
43
+ games.each do |game|
44
+ send("output_#{type}_game", game)
45
+ end
46
+ else
47
+ puts "There are no #{type} games.".align
48
+ end
49
+ puts
50
+ end
51
+
52
+ def output_recent_game(game)
53
+ puts "#{game.date}:".align + " #{game.winner} defeat #{game.loser} (#{game.winner_score}-#{game.loser_score})"
54
+ end
55
+
56
+ def output_current_game(game)
57
+ if game.started?
58
+ score_descriptor = score_descriptor_string(game)
59
+ output = "IN PROGRESS:".align + " #{game.leader} #{score_descriptor} #{game.trailer} (#{game.leader_score}-#{game.trailer_score})"
60
+ else
61
+ output = "PRE GAME:".align + " #{game.home_team} vs. #{game.away_team}"
62
+ end
63
+ output += tv_string(game)
64
+ puts output
65
+ end
66
+
67
+ def output_upcoming_game(game)
68
+ output = "#{game.date} @ #{game.start_time} (EST):".align + " #{game.home_team} vs. #{game.away_team}"
69
+ output += tv_string(game)
70
+ puts output
71
+ end
72
+
73
+ def tv_string(game)
74
+ return " on #{game.ustv} (US)" if !game.ustv.empty? && game.catv.empty?
75
+ return " on #{game.catv} (CA)" if !game.catv.empty? && game.ustv.empty?
76
+ return " on #{game.ustv} (US) & #{game.catv} (CA)" if !game.ustv.empty? && !game.catv.empty?
77
+ return ""
78
+ end
79
+
80
+ def score_descriptor_string(game)
81
+ return "tied with" if game.home_team_score == game.away_team_score
82
+ return "lead"
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,121 @@
1
+ module NHLScores
2
+ class Game
3
+ attr_reader :id, :date, :start_time, :home_team, :away_team, :home_team_score,
4
+ :away_team_score, :status, :ustv, :catv
5
+
6
+ require 'httparty'
7
+
8
+ def initialize(game_attributes)
9
+ @id = game_attributes["id"]
10
+ @date = game_attributes["ts"]
11
+ @start_time = game_attributes["bs"]
12
+ @home_team = alter_team_name("#{game_attributes["htn"]} #{game_attributes["htv"].capitalize}")
13
+ @away_team = alter_team_name("#{game_attributes["atn"]} #{game_attributes["atv"].capitalize}")
14
+ @home_team_score = game_attributes["hts"]
15
+ @away_team_score = game_attributes["ats"]
16
+ @status = game_attributes["tsc"]
17
+ @ustv = game_attributes["ustv"]
18
+ @catv = game_attributes["catv"]
19
+ end
20
+
21
+ def started?
22
+ return false if status.empty? || home_team_score.empty? || away_team_score.empty?
23
+ return true
24
+ end
25
+
26
+ def winner
27
+ not_final_message
28
+ high_score_team
29
+ end
30
+
31
+ def loser
32
+ not_final_message
33
+ low_score_team
34
+ end
35
+
36
+ def winner_score
37
+ not_final_message
38
+ high_score
39
+ end
40
+
41
+ def loser_score
42
+ not_final_message
43
+ low_score
44
+ end
45
+
46
+ def leader
47
+ not_in_progress_message
48
+ high_score_team
49
+ end
50
+
51
+ def trailer
52
+ not_in_progress_message
53
+ low_score_team
54
+ end
55
+
56
+ def leader_score
57
+ not_in_progress_message
58
+ high_score
59
+ end
60
+
61
+ def trailer_score
62
+ not_in_progress_message
63
+ low_score
64
+ end
65
+
66
+ def includes_team?(team_name)
67
+ return home_team == team_name || away_team == team_name
68
+ end
69
+
70
+ def team_name(team_abbrev)
71
+ return TEAM_ABBREV_MAP[team_abbrev] if TEAM_ABBREV_MAP.has_key?(team_abbrev)
72
+ end
73
+
74
+ private
75
+
76
+ def alter_team_name(team_name)
77
+ case team_name
78
+ when "NY Rangers Rangers"
79
+ return "New York Rangers"
80
+ when "NY Islanders Islanders"
81
+ return "New York Islanders"
82
+ when "Toronto Mapleleafs"
83
+ return "Toronto Maple Leafs"
84
+ when "Columbus Bluejackets"
85
+ return "Columbus Blue Jackets"
86
+ when "Detroit Redwings"
87
+ return "Detroit Red Wings"
88
+ else
89
+ return team_name
90
+ end
91
+ end
92
+
93
+ def high_score
94
+ return home_team_score if home_team_score == away_team_score
95
+ home_team_score > away_team_score ? home_team_score : away_team_score
96
+ end
97
+
98
+ def low_score
99
+ return away_team_score if home_team_score == away_team_score
100
+ home_team_score > away_team_score ? away_team_score : home_team_score
101
+ end
102
+
103
+ def high_score_team
104
+ return home_team if home_team_score == away_team_score
105
+ home_team_score > away_team_score ? home_team : away_team
106
+ end
107
+
108
+ def low_score_team
109
+ return away_team if home_team_score == away_team_score
110
+ home_team_score > away_team_score ? away_team : home_team
111
+ end
112
+
113
+ def not_final_message
114
+ "This game is not final." if status != "final"
115
+ end
116
+
117
+ def not_in_progress_message
118
+ "This game is not in progress." if status != "progress"
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,37 @@
1
+ module NHLScores
2
+ class Games
3
+ attr_reader :games
4
+
5
+ require 'httparty'
6
+
7
+ def initialize
8
+ response = HTTParty.get(ENDPOINT).sub("loadScoreboard(", "").sub(")", "")
9
+ @games = JSON.parse(response)["games"].map { |game_attributes| Game.new(game_attributes) }
10
+ end
11
+
12
+ def all(team_abbrev: nil)
13
+ return @games if team_abbrev.nil?
14
+ team_name = team_name(team_abbrev)
15
+ return @games.select { |game| game if game.includes_team?(team_name) }
16
+ end
17
+
18
+ def recent(team_abbrev: nil)
19
+ all(team_abbrev: team_abbrev).select { |game| game if game.status == "final" }
20
+ end
21
+
22
+ def in_progress(team_abbrev: nil)
23
+ all(team_abbrev: team_abbrev).select { |game| game if game.status == "progress" }
24
+ end
25
+
26
+ def upcoming(team_abbrev: nil)
27
+ all(team_abbrev: team_abbrev).select { |game| game if game.status == "" }
28
+ end
29
+
30
+ private
31
+
32
+ def team_name(team_abbrev)
33
+ return TEAM_ABBREV_MAP[team_abbrev.to_sym] if TEAM_ABBREV_MAP.has_key?(team_abbrev.to_sym)
34
+ raise ArgumentError, 'Invalid abbreviation.'
35
+ end
36
+ end
37
+ end
data/lib/nhl_scores.rb ADDED
@@ -0,0 +1,52 @@
1
+ require_relative 'nhl_scores/game'
2
+ require_relative 'nhl_scores/games'
3
+ require_relative 'nhl_scores/cli'
4
+
5
+ module NHLScores
6
+ ENDPOINT = "http://live.nhle.com/GameData/RegularSeasonScoreboardv3.jsonp"
7
+
8
+ TEAM_ABBREV_MAP = {
9
+ ana: "Anaheim Ducks",
10
+ bos: "Boston Bruins",
11
+ buf: "Buffalo Sabres",
12
+ car: "Carolina Hurricanes",
13
+ cbj: "Columbus Blue Jackets",
14
+ cgy: "Calgary Flames",
15
+ chi: "Chicago Blackhawks",
16
+ col: "Colorado",
17
+ dal: "Dallas Stars",
18
+ det: "Detroit Red Wings",
19
+ edm: "Edmonton Oilers",
20
+ fla: "Florida Panthers",
21
+ la: "Los Angeles Kings",
22
+ min: "Minnesota Wild",
23
+ mtl: "Montréal Canadiens",
24
+ nas: "Nashville Predators",
25
+ nj: "New Jersey Devils",
26
+ nyi: "New York Islanders",
27
+ nyr: "New York Rangers",
28
+ ott: "Ottawa Senators",
29
+ phi: "Philadelphia Flyers",
30
+ phx: "Phoenix Coyotes",
31
+ pit: "Pittsburgh Penguins",
32
+ sj: "San Jose Sharks",
33
+ stl: "St Louis Blues",
34
+ tb: "Tampa Bay Lightning",
35
+ tor: "Toronto Maple Leafs",
36
+ van: "Vancouver Canucks",
37
+ wpg: "Winnipeg Jets",
38
+ wsh: "Washington Capitals"
39
+ }
40
+ end
41
+
42
+ class String
43
+ def yellow; color(self, "\e[0;33m"); end
44
+
45
+ def color(text, color_code)
46
+ "#{color_code}#{text}\e[0m"
47
+ end
48
+
49
+ def align
50
+ self.rjust(32)
51
+ end
52
+ end
@@ -0,0 +1,133 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module NHLScores
4
+ describe NHLScores do
5
+ it 'should include a team abbreviation to name map' do
6
+ TEAM_ABBREV_MAP.should be_true
7
+ TEAM_ABBREV_MAP[:pit].should == "Pittsburgh Penguins"
8
+ TEAM_ABBREV_MAP[:mtl].should == "Montréal Canadiens"
9
+ end
10
+ end
11
+
12
+ describe Games do
13
+ subject(:games) { NHLScores::Games.new }
14
+
15
+ it 'should be valid' do
16
+ games.should be_true
17
+ end
18
+
19
+ it 'should be initialized with games' do
20
+ games.games.should be_true
21
+ games.games.first.class.should == NHLScores::Game
22
+ end
23
+
24
+ it 'should provide an array of all games' do
25
+ games.all.class.should == Array
26
+ games.all.count.should == games.games.count
27
+ end
28
+
29
+ it 'should provide an array of recent games' do
30
+ games.recent.class.should == Array
31
+ if games.recent.any?
32
+ games.recent.first.status.should == "final"
33
+ games.recent.last.status.should == "final"
34
+ end
35
+ end
36
+
37
+ it 'should provide an array of games in progress' do
38
+ games.in_progress.class.should == Array
39
+ if games.in_progress.any?
40
+ games.in_progress.first.status.should == "progress"
41
+ games.in_progress.last.status.should == "progress"
42
+ end
43
+ end
44
+
45
+ it 'should provide an array of upcoming games' do
46
+ games.upcoming.class.should == Array
47
+ if games.upcoming.any?
48
+ games.upcoming.first.status.should == ""
49
+ games.upcoming.first.status.should == ""
50
+ end
51
+ end
52
+
53
+ context 'with team abbreviation provided' do
54
+ it 'should provide an array of all games including team' do
55
+ games.all(team_abbrev: :pit).first.includes_team?("Pittsburgh Penguins").should be_true if games.all(team_abbrev: :pit).any?
56
+ games.all(team_abbrev: :wsh).first.includes_team?("Washington Capitals").should be_true if games.all(team_abbrev: :wsh).any?
57
+ end
58
+
59
+ it 'should provide an array of recent games including team' do
60
+ games.recent(team_abbrev: :tb).first.includes_team?("Tampa Bay Lightning").should be_true if games.recent(team_abbrev: :tb).any?
61
+ games.recent(team_abbrev: :phx).first.includes_team?("Phoenix Coyotes").should be_true if games.recent(team_abbrev: :phx).any?
62
+ end
63
+
64
+ it 'should provide an array of games in progress including team' do
65
+ games.in_progress(team_abbrev: :pit).first.includes_team?("Pittsburgh Penguins").should be_true if games.in_progress(team_abbrev: :pit).any?
66
+ games.in_progress(team_abbrev: :col).first.includes_team?("Colorado Avalanche").should be_true if games.in_progress(team_abbrev: :col).any?
67
+ end
68
+
69
+ it 'should provide an array of upcoming games including team' do
70
+ games.upcoming(team_abbrev: :ana).first.includes_team?("Anaheim Ducks").should be_true if games.upcoming(team_abbrev: :ana).any?
71
+ games.upcoming(team_abbrev: :nyr).first.includes_team?("New York Rangers").should be_true if games.upcoming(team_abbrev: :nyr).any?
72
+ end
73
+ end
74
+ end
75
+
76
+ describe Game do
77
+ context 'when final' do
78
+ subject(:game) { NHLScores::Games.new.recent.first }
79
+
80
+ it 'should be valid' do
81
+ game.should be_true
82
+ end
83
+
84
+ it 'should be initialized with the appropriate attributes' do
85
+ game.should respond_to(:id)
86
+ game.should respond_to(:date)
87
+ game.should respond_to(:start_time)
88
+ game.should respond_to(:home_team)
89
+ game.should respond_to(:away_team)
90
+ game.should respond_to(:home_team_score)
91
+ game.should respond_to(:away_team_score)
92
+ game.should respond_to(:status)
93
+ game.should respond_to(:ustv)
94
+ game.should respond_to(:catv)
95
+ end
96
+
97
+ it 'should provide the winning team' do
98
+ winner = game.home_team_score > game.away_team_score ? game.home_team : game.away_team
99
+ game.winner.should == winner
100
+ end
101
+
102
+ it 'should provide the losing team' do
103
+ loser = game.home_team_score > game.away_team_score ? game.away_team : game.home_team
104
+ game.loser.should == loser
105
+ end
106
+
107
+ it 'should provide the winning team\'s score' do
108
+ winner_score = game.home_team_score > game.away_team_score ? game.home_team_score : game.away_team_score
109
+ game.winner_score.should == winner_score
110
+ end
111
+
112
+ it 'should provide the losing team\'s score' do
113
+ loser_score = game.home_team_score > game.away_team_score ? game.away_team_score : game.home_team_score
114
+ game.loser_score.should == loser_score
115
+ end
116
+
117
+ it 'should indicate whether or not a certain team was/is involved' do
118
+ game.includes_team?(game.home_team).should be_true
119
+ game.includes_team?(game.away_team).should be_true
120
+ end
121
+ end
122
+
123
+ context 'when in progress' do
124
+
125
+ end
126
+ end
127
+
128
+ describe CLI do
129
+ it 'should be initialized with games' do
130
+ subject.games.should be_true
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'nhl_scores'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nhl_scores
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Travis Loncar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.7
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.7
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Use Ruby to grab live/recent NHL scores and upcoming matchup details.
126
+ This gem ships with a minimal CLI.
127
+ email: loncar.travis@gmail.com
128
+ executables:
129
+ - nhl
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.md
134
+ files:
135
+ - .document
136
+ - .rspec
137
+ - .travis.yml
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - VERSION
144
+ - bin/nhl
145
+ - lib/nhl_scores.rb
146
+ - lib/nhl_scores/cli.rb
147
+ - lib/nhl_scores/game.rb
148
+ - lib/nhl_scores/games.rb
149
+ - spec/nhl_scores_spec.rb
150
+ - spec/spec_helper.rb
151
+ homepage: http://github.com/tbloncar/nhl_scores
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.0.6
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Use Ruby to grab live/recent NHL scores and upcoming matchup details.
175
+ test_files: []