score-scraper 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: 70160ecdd5e6ed47f348f75742d3ecca2c32f64d
4
- data.tar.gz: 735793df360361db8839d1798ab52840be4ed20c
3
+ metadata.gz: 671f58899aa77cd0056dbbddb71c4f3d03b281f3
4
+ data.tar.gz: adc77cdf00a2347f19d1e195bff226855768ba3a
5
5
  SHA512:
6
- metadata.gz: 3a25b632e318c2d4522c1864616b8c316592300245e2e47fa1e7b4ea993f6a26d183c31f91106b6a56892bbf91013dc670ae5d974d87d01052cb3b763fd39e7e
7
- data.tar.gz: 5e8f0fe00934dfed0e15dec07c19b85ed41fc57fa198e92ef6bca40951b10e047d9a5c9e491e7cc73c3d5e751f1b72fd12942c719b877c788293e0f7d6f17500
6
+ metadata.gz: 17c436826987df2db7744b3eaf67538756ba81c253d0c114d6f22fbb15698f982535cf688e5316ce798e8e3b931fc2823c114f5c65f6175dfe253770c0d8b982
7
+ data.tar.gz: 2478043a1f6f7d353f389fa1b59f9e39100dd5126f2795bac110aa75d17af6fbef96c1f305806f900eb9cfae8eb87ac10ce8608553e415f511a784de6e7a2f26
Binary file
data/README.md CHANGED
@@ -21,14 +21,24 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
+ ### Get scores of games for nba teams
24
25
  ```ruby
25
- require 'score-scraper'
26
+ require 'score_scraper'
27
+
28
+ scraper = ScoreScraper::Scrapers::Nba.new(Time.now.strftime("%Y-%m-%d"), # Date you want to search
29
+ ['chi','det']) # Teams you want to find, pass nothing in for all teams
30
+
31
+ # team_games will return Game objects for the teams defined in the initialize
32
+ games = scraper.team_games
33
+ # => [#<ScoreScraper::Game:0x00000001b00b48 @home_team=#<ScoreScraper::Team:0x00000001b00e68 @city="Houston", @nickname="Rockets", @abbreviation="HOU", @score=0>, @away_team=#<ScoreScraper::Team:0x00000001b00c38 @city="Dallas", @nickname="Mavericks", @abbreviation="DAL", @score=0>, @game_state="1Q">, #<ScoreScraper::Game:0x00000001b00530 @home_team=#<ScoreScraper::Team:0x00000001b008c8 @city="Toronto", @nickname="Raptors", @abbreviation="TOR", @score=0>, @away_team=#<ScoreScraper::Team:0x00000001b00670 @city="Los Angeles", @nickname="Clippers", @abbreviation="LAC", @score=0>, @game_state="6:00 pm ET">]
26
34
  ```
27
35
 
28
36
  ## Development
29
37
 
30
38
  Contributions are welcome, feel free to expand on current functionality or add new leagues.
31
39
 
40
+
41
+
32
42
  ## Contributing
33
43
 
34
44
  Bug reports and pull requests are welcome on GitHub at https://github.com/DNeier/score-scraper.
@@ -1,11 +1,11 @@
1
- module ScoreScraper
2
- class Game
3
- attr_reader :home_team, :away_team, :game_state
1
+ module ScoreScraper
2
+ class Game
3
+ attr_reader :home_team, :away_team, :game_state
4
4
 
5
- def initialize(attrs)
6
- @home_team = attrs[:home_team] || {}
7
- @away_team = attrs[:away_team] || {}
8
- @game_state = attrs[:game_state] || ''
9
- end
10
- end
5
+ def initialize(attrs)
6
+ @home_team = attrs[:home_team] || {}
7
+ @away_team = attrs[:away_team] || {}
8
+ @game_state = attrs[:game_state] || ''
9
+ end
10
+ end
11
11
  end
@@ -1,40 +1,40 @@
1
1
  module ScoreScraper
2
- class Scoreboard
2
+ class Scoreboard
3
3
 
4
- def initialize(search_date = nil, teams = [])
5
- @teams = teams
6
- @search_date = search_date || Time.now.strftime("%Y-%m-%d")
7
- end
4
+ def initialize(search_date = nil, teams = [])
5
+ @teams = teams
6
+ @search_date = search_date || Time.now.strftime("%Y-%m-%d")
7
+ end
8
8
 
9
- def games(game_separator = '|')
10
- game_array = []
9
+ def games(game_separator = '|')
10
+ game_array = []
11
11
 
12
- team_games.each do |game|
13
- game_array << single_game(game)
14
- end
12
+ team_games.each do |game|
13
+ game_array << single_game(game)
14
+ end
15
15
 
16
- game_array.join(game_separator)
17
- end
16
+ game_array.join(game_separator)
17
+ end
18
18
 
19
- private
19
+ private
20
20
 
21
- attr_reader :search_date, :teams
22
-
23
- def parser
24
- raise 'must be implemented by child class'
25
- end
21
+ attr_reader :search_date, :teams
22
+
23
+ def parser
24
+ raise 'must be implemented by child class'
25
+ end
26
26
 
27
- def single_game(game)
28
- home_team = game.home_team
29
- away_team = game.away_team
27
+ def single_game(game)
28
+ home_team = game.home_team
29
+ away_team = game.away_team
30
30
 
31
- " #{away_team.abbreviation} #{away_team.score} - #{home_team.score} #{home_team.abbreviation} #{game.game_state} "
32
- end
31
+ " #{away_team.abbreviation} #{away_team.score} - #{home_team.score} #{home_team.abbreviation} #{game.game_state} "
32
+ end
33
33
 
34
- def team_games
35
- return @team_games unless @team_games.nil?
34
+ def team_games
35
+ return @team_games unless @team_games.nil?
36
36
 
37
- @team_games = parser.games_for_teams || {}
38
- end
39
- end
37
+ @team_games = parser.games_for_teams || {}
38
+ end
39
+ end
40
40
  end
@@ -1,16 +1,16 @@
1
1
  module ScoreScraper
2
- module Scoreboards
3
- extend self
2
+ module Scoreboards
3
+ extend self
4
4
 
5
- attr_reader :registered
6
- @registered = []
5
+ attr_reader :registered
6
+ @registered = []
7
7
 
8
- def register(class_name, autoload_require)
9
- ScoreScraper::Scoreboards.autoload(class_name, autoload_require)
10
- self.registered.push(class_name)
11
- end
8
+ def register(class_name, autoload_require)
9
+ ScoreScraper::Scoreboards.autoload(class_name, autoload_require)
10
+ self.registered.push(class_name)
11
+ end
12
12
 
13
- end
13
+ end
14
14
  end
15
15
 
16
16
  ScoreScraper::Scoreboards.register(:Nba, 'score_scraper/scoreboards/nba')
@@ -1,12 +1,12 @@
1
1
  module ScoreScraper
2
- module Scoreboards
3
- class Mlb < Scoreboard
2
+ module Scoreboards
3
+ class Mlb < Scoreboard
4
4
 
5
- private
5
+ private
6
6
 
7
- def parser
8
- @parser ||= ScoreScraper::Scrapers::Mlb.new(search_date, teams)
9
- end
10
- end
11
- end
7
+ def parser
8
+ @parser ||= ScoreScraper::Scrapers::Mlb.new(search_date, teams)
9
+ end
10
+ end
11
+ end
12
12
  end
@@ -1,12 +1,12 @@
1
1
  module ScoreScraper
2
- module Scoreboards
3
- class Nba < Scoreboard
2
+ module Scoreboards
3
+ class Nba < Scoreboard
4
4
 
5
- private
5
+ private
6
6
 
7
- def parser
8
- @parser ||= ScoreScraper::Scrapers::Nba.new(search_date, teams)
9
- end
10
- end
11
- end
7
+ def parser
8
+ @parser ||= ScoreScraper::Scrapers::Nba.new(search_date, teams)
9
+ end
10
+ end
11
+ end
12
12
  end
@@ -1,97 +1,97 @@
1
1
  module ScoreScraper
2
- class Scraper
3
- def initialize(search_date = nil, teams = [])
4
- @teams = teams
5
- @search_date = search_date || Time.now.strftime("%Y-%m-%d")
6
- end
7
-
8
- def team_games
9
- team_games = []
10
- (games || []).each do |game|
11
- if teams.empty? || is_team_game?(game)
12
- team_games << ScoreScraper::Game.new({
13
- home_team: home_team(game),
14
- away_team: away_team(game),
15
- game_state: game_state(game)
16
- })
17
- end
18
- end
19
-
20
- team_games
21
- end
22
-
23
- private
24
-
25
- attr_reader :search_date, :teams
26
-
27
- def search_day
28
- @current_day ||= search_date.split('-')[2]
29
- end
30
-
31
- def search_month
32
- @current_month ||= search_date.split('-')[1]
33
- end
34
-
35
- def search_year
36
- @current_year ||= search_date.split('-')[0]
37
- end
38
-
39
- def formatted_url
40
- raise 'Must be implemented in child class'
41
- end
42
-
43
- def games
44
- raise 'Must be implemented in child class'
45
- end
46
-
47
- def abbreviation(game, is_home = false)
48
- raise 'Must be implemented in child class'
49
- end
50
-
51
- def away_team(game)
52
- get_game(game)
53
- end
54
-
55
- def city(game, is_home = false)
56
- raise 'Must be implemented in child class'
57
- end
58
-
59
- def get_game(game, is_home = false)
60
- ScoreScraper::Team.new({
61
- city: city(game, is_home),
62
- nickname: nickname(game, is_home),
63
- abbreviation: abbreviation(game, is_home),
64
- seore: score(game, is_home)
65
- })
66
- end
67
-
68
- def game_state(game)
69
- raise 'Must be implemented in child class'
70
- end
71
-
72
- def home_team(game)
73
- get_game(game, true)
74
- end
75
-
76
- def nickname(game, is_home = false)
77
- raise 'Must be implemented in child class'
78
- end
79
-
80
- def score(game, is_home = false)
81
- raise 'Must be implemented in child class'
82
- end
83
-
84
- def is_team_game?(game)
85
- teams.include?(get_abbreviation(game, true).downcase) || teams.include?(get_abbreviation(game).downcase)
86
- end
87
-
88
- def parsed_data
89
- return @parsed_data unless @parsed_data.nil?
90
-
91
- file = open(formatted_url)
92
- file_data = file.read
93
-
94
- @parsed_data = JSON.parse(file_data)
95
- end
96
- end
2
+ class Scraper
3
+ def initialize(search_date = nil, teams = [])
4
+ @teams = teams
5
+ @search_date = search_date || Time.now.strftime("%Y-%m-%d")
6
+ end
7
+
8
+ def team_games
9
+ team_games = []
10
+ (games || []).each do |game|
11
+ if teams.empty? || is_team_game?(game)
12
+ team_games << ScoreScraper::Game.new({
13
+ home_team: home_team(game),
14
+ away_team: away_team(game),
15
+ game_state: game_state(game)
16
+ })
17
+ end
18
+ end
19
+
20
+ team_games
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :search_date, :teams
26
+
27
+ def search_day
28
+ @current_day ||= search_date.split('-')[2]
29
+ end
30
+
31
+ def search_month
32
+ @current_month ||= search_date.split('-')[1]
33
+ end
34
+
35
+ def search_year
36
+ @current_year ||= search_date.split('-')[0]
37
+ end
38
+
39
+ def formatted_url
40
+ raise 'Must be implemented in child class'
41
+ end
42
+
43
+ def games
44
+ raise 'Must be implemented in child class'
45
+ end
46
+
47
+ def abbreviation(game, is_home = false)
48
+ raise 'Must be implemented in child class'
49
+ end
50
+
51
+ def away_team(game)
52
+ get_game(game)
53
+ end
54
+
55
+ def city(game, is_home = false)
56
+ raise 'Must be implemented in child class'
57
+ end
58
+
59
+ def get_game(game, is_home = false)
60
+ ScoreScraper::Team.new({
61
+ city: city(game, is_home),
62
+ nickname: nickname(game, is_home),
63
+ abbreviation: abbreviation(game, is_home),
64
+ seore: score(game, is_home)
65
+ })
66
+ end
67
+
68
+ def game_state(game)
69
+ raise 'Must be implemented in child class'
70
+ end
71
+
72
+ def home_team(game)
73
+ get_game(game, true)
74
+ end
75
+
76
+ def nickname(game, is_home = false)
77
+ raise 'Must be implemented in child class'
78
+ end
79
+
80
+ def score(game, is_home = false)
81
+ raise 'Must be implemented in child class'
82
+ end
83
+
84
+ def is_team_game?(game)
85
+ teams.include?(abbreviation(game, true).downcase) || teams.include?(abbreviation(game).downcase)
86
+ end
87
+
88
+ def parsed_data
89
+ return @parsed_data unless @parsed_data.nil?
90
+
91
+ file = open(formatted_url)
92
+ file_data = file.read
93
+
94
+ @parsed_data = JSON.parse(file_data)
95
+ end
96
+ end
97
97
  end
@@ -1,16 +1,16 @@
1
1
  module ScoreScraper
2
- module Scrapers
3
- extend self
2
+ module Scrapers
3
+ extend self
4
4
 
5
- attr_reader :registered
6
- @registered = []
5
+ attr_reader :registered
6
+ @registered = []
7
7
 
8
- def register(class_name, autoload_require)
9
- ScoreScraper::Scrapers.autoload(class_name, autoload_require)
10
- self.registered.push(class_name)
11
- end
8
+ def register(class_name, autoload_require)
9
+ ScoreScraper::Scrapers.autoload(class_name, autoload_require)
10
+ self.registered.push(class_name)
11
+ end
12
12
 
13
- end
13
+ end
14
14
  end
15
15
 
16
16
  ScoreScraper::Scrapers.register(:Nba, 'score_scraper/scrapers/nba')
@@ -1,52 +1,52 @@
1
1
  module ScoreScraper
2
- module Scrapers
3
- class Mlb < Scraper
4
-
5
- private
6
-
7
- def formatted_url
8
- @formatted_url ||= "http://chicago.cubs.mlb.com/gdcross/components/game/mlb/year_#{search_year}/month_#{search_month}/day_#{search_day}/master_scoreboard.json"
9
- end
10
-
11
- def games
12
- @games ||= parsed_data['data']['games']['game']
13
- end
14
-
15
- def abbreviation(game, is_home = false)
16
- game["#{key_type(is_home)}_name_abbrev"]
17
- end
18
-
19
- def city(game, is_home = false)
20
- game["#{key_type(is_home)}_team_city"]
21
- end
22
-
23
- def game_state(game)
24
- game_state = ''
25
- game_status = game['status']['status']
26
-
27
- if game_status.downcase == 'final' || game_status.downcase == 'game over'
28
- game_state = 'F'
29
- elsif game_status.downcase == 'preview'
30
- game_state = game['time']
31
- elsif game['status']['top_inning'] && game['status']['inning']
32
- is_top_inning = game['status']['top_inning'].downcase == 'y'
33
- game_state = is_top_inning ? "T#{game['status']['inning']}" : "B#{game['status']['inning']}"
34
- end
35
-
36
- game_state
37
- end
38
-
39
- def nickname(game, is_home = false)
40
- game["#{key_type(is_home)}_team_name"]
41
- end
42
-
43
- def score(game, is_home = false)
44
- game['linescore'] ? game['linescore']['r']["#{key_type(is_home)}"] : ''
45
- end
46
-
47
- def key_type(is_home = false)
48
- is_home ? 'home' : 'away'
49
- end
50
- end
51
- end
2
+ module Scrapers
3
+ class Mlb < Scraper
4
+
5
+ private
6
+
7
+ def formatted_url
8
+ @formatted_url ||= "http://chicago.cubs.mlb.com/gdcross/components/game/mlb/year_#{search_year}/month_#{search_month}/day_#{search_day}/master_scoreboard.json"
9
+ end
10
+
11
+ def games
12
+ @games ||= parsed_data['data']['games']['game']
13
+ end
14
+
15
+ def abbreviation(game, is_home = false)
16
+ game["#{key_type(is_home)}_name_abbrev"]
17
+ end
18
+
19
+ def city(game, is_home = false)
20
+ game["#{key_type(is_home)}_team_city"]
21
+ end
22
+
23
+ def game_state(game)
24
+ game_state = ''
25
+ game_status = game['status']['status']
26
+
27
+ if game_status.downcase == 'final' || game_status.downcase == 'game over'
28
+ game_state = 'F'
29
+ elsif game_status.downcase == 'preview'
30
+ game_state = game['time']
31
+ elsif game['status']['top_inning'] && game['status']['inning']
32
+ is_top_inning = game['status']['top_inning'].downcase == 'y'
33
+ game_state = is_top_inning ? "T#{game['status']['inning']}" : "B#{game['status']['inning']}"
34
+ end
35
+
36
+ game_state
37
+ end
38
+
39
+ def nickname(game, is_home = false)
40
+ game["#{key_type(is_home)}_team_name"]
41
+ end
42
+
43
+ def score(game, is_home = false)
44
+ game['linescore'] ? game['linescore']['r']["#{key_type(is_home)}"] : ''
45
+ end
46
+
47
+ def key_type(is_home = false)
48
+ is_home ? 'home' : 'away'
49
+ end
50
+ end
51
+ end
52
52
  end
@@ -1,60 +1,60 @@
1
1
  module ScoreScraper
2
- module Scrapers
3
- class Nba < Scraper
2
+ module Scrapers
3
+ class Nba < Scraper
4
4
 
5
- private
5
+ private
6
6
 
7
- def formatted_url
8
- @formatted_url ||= "http://data.nba.com/jsonp/5s/json/cms/noseason/scoreboard/#{search_year}#{search_month}#{search_day}/games.json"
9
- end
7
+ def formatted_url
8
+ @formatted_url ||= "http://data.nba.com/jsonp/5s/json/cms/noseason/scoreboard/#{search_year}#{search_month}#{search_day}/games.json"
9
+ end
10
10
 
11
- def games
12
- @games ||= parsed_data['sports_content']['games']['game']
13
- end
11
+ def games
12
+ @games ||= parsed_data['sports_content']['games']['game']
13
+ end
14
14
 
15
- def abbreviation(game, is_home = false)
16
- game["#{key_type(is_home)}"]['abbreviation']
17
- end
15
+ def abbreviation(game, is_home = false)
16
+ game["#{key_type(is_home)}"]['abbreviation']
17
+ end
18
18
 
19
- def city(game, is_home = false)
20
- game["#{key_type(is_home)}"]['city']
21
- end
19
+ def city(game, is_home = false)
20
+ game["#{key_type(is_home)}"]['city']
21
+ end
22
22
 
23
- def game_state(game)
24
- game_state = ''
25
- game_status = game['period_time']['period_status']
23
+ def game_state(game)
24
+ game_state = ''
25
+ game_status = game['period_time']['period_status']
26
26
 
27
- if game_status.downcase == 'final'
28
- game_state = 'F'
29
- elsif game['period_time']['period_value'].to_i > 0
30
- game_state = "#{game['period_time']['period_value']}Q"
31
- else
32
- game_state = game_status
33
- end
27
+ if game_status.downcase == 'final'
28
+ game_state = 'F'
29
+ elsif game['period_time']['period_value'].to_i > 0
30
+ game_state = "#{game['period_time']['period_value']}Q"
31
+ else
32
+ game_state = game_status
33
+ end
34
34
 
35
- game_state
36
- end
35
+ game_state
36
+ end
37
37
 
38
- def nickname(game, is_home = false)
39
- game["#{key_type(is_home)}"]['nickname']
40
- end
38
+ def nickname(game, is_home = false)
39
+ game["#{key_type(is_home)}"]['nickname']
40
+ end
41
41
 
42
- def score(game, is_home = false)
43
- game["#{key_type(is_home)}"]['score']
44
- end
42
+ def score(game, is_home = false)
43
+ game["#{key_type(is_home)}"]['score']
44
+ end
45
45
 
46
- def key_type(is_home = false)
47
- is_home ? 'home' : 'visitor'
48
- end
46
+ def key_type(is_home = false)
47
+ is_home ? 'home' : 'visitor'
48
+ end
49
49
 
50
- def parsed_data
51
- return @parsed_data unless @parsed_data.nil?
50
+ def parsed_data
51
+ return @parsed_data unless @parsed_data.nil?
52
52
 
53
- file = open(formatted_url)
54
- file_data = file.read
53
+ file = open(formatted_url)
54
+ file_data = file.read
55
55
 
56
- @parsed_data = JSON.parse(file_data[16...-2])
57
- end
58
- end
59
- end
56
+ @parsed_data = JSON.parse(file_data[16...-2])
57
+ end
58
+ end
59
+ end
60
60
  end
@@ -1,12 +1,12 @@
1
- module ScoreScraper
2
- class Team
3
- attr_reader :city, :nickname, :abbreviation, :score
1
+ module ScoreScraper
2
+ class Team
3
+ attr_reader :city, :nickname, :abbreviation, :score
4
4
 
5
- def initialize(attrs)
6
- @city = attrs[:city] || ''
7
- @nickname = attrs[:nickname] || ''
8
- @abbreviation = attrs[:abbreviation] || 'NIL'
9
- @score = attrs[:score] || 0
10
- end
11
- end
5
+ def initialize(attrs)
6
+ @city = attrs[:city] || ''
7
+ @nickname = attrs[:nickname] || ''
8
+ @abbreviation = attrs[:abbreviation] || 'NIL'
9
+ @score = attrs[:score] || 0
10
+ end
11
+ end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module ScoreScraper
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "json", "~> 1.8"
21
+ spec.add_runtime_dependency "json", "~> 1.8"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.11"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: score-scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derrick Neier