yankee_score 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yankee_score/cli.rb +3 -6
- data/lib/yankee_score/game.rb +37 -9
- data/lib/yankee_score/score_scraper.rb +6 -29
- data/lib/yankee_score/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3645da79fd2ce3881d9dc0ce399b80548d01b62a
|
4
|
+
data.tar.gz: 6e42203cab469ae22f753c47274d284152483800
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e4daca595ab99d865ccc9f27835f7b07a6ad5d9775ab71dbb8559a6eef5b4b42390b4c37ff33dd4d2492c8fcd10ed51f52e49e38c1bfdc8aa4da55bc4b9e831
|
7
|
+
data.tar.gz: 7381dc0f7bd020ee49ebe424b9acf6f63dc9d85abe46c4a24de56c51d27a8b6f80399122fc8ff88103371956801328909bc0332fe103db9c41a1c60b17c92b35
|
data/lib/yankee_score/cli.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require "pry"
|
2
1
|
class YankeeScore::CLI
|
3
|
-
attr_accessor :game
|
4
2
|
|
5
3
|
def initialize
|
6
4
|
@score_scraper = YankeeScore::ScoreScraper.new
|
@@ -47,11 +45,10 @@ class YankeeScore::CLI
|
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
|
-
def search_team(
|
51
|
-
YankeeScore::Game.
|
52
|
-
|
48
|
+
def search_team(team_abbrev)
|
49
|
+
games = YankeeScore::Game.find_team_by_abbrev(team_abbrev)
|
50
|
+
games.each do |game|
|
53
51
|
print_game(game)
|
54
|
-
end
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
data/lib/yankee_score/game.rb
CHANGED
@@ -7,6 +7,8 @@ class YankeeScore::Game
|
|
7
7
|
:inning_state,
|
8
8
|
:score
|
9
9
|
|
10
|
+
PRE_GAME_STATE = ["Pre-Game","Preview", "Warmup"]
|
11
|
+
END_GAME_STATE = ["Final", "Postponed", "Game Over"]
|
10
12
|
|
11
13
|
def initialize(home_team, away_team)
|
12
14
|
@home_team = home_team
|
@@ -15,27 +17,53 @@ class YankeeScore::Game
|
|
15
17
|
|
16
18
|
@@all = []
|
17
19
|
|
20
|
+
def self.all
|
21
|
+
@@all
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.reset_all!
|
25
|
+
@@all.clear
|
26
|
+
end
|
27
|
+
|
18
28
|
def save
|
19
29
|
@@all << self
|
20
30
|
end
|
21
31
|
|
32
|
+
def self.create_from_json(game_hash)
|
33
|
+
game = self.new(YankeeScore::Team.new(game_hash[:home_name_abbrev]), YankeeScore::Team.new(game_hash[:away_name_abbrev]))
|
34
|
+
|
35
|
+
game.start_time = game_hash[:time]
|
36
|
+
game.status = game_hash[:status][:status]
|
37
|
+
game.inning = game_hash[:status][:inning]
|
38
|
+
game.inning_state = game_hash[:status][:inning_state]
|
39
|
+
|
40
|
+
|
41
|
+
if game_hash.has_key?(:linescore)
|
42
|
+
game.home_team.runs = game_hash[:linescore][:r][:home]
|
43
|
+
game.away_team.runs = game_hash[:linescore][:r][:away]
|
44
|
+
game.score = "#{game.away_team.runs}-#{game.home_team.runs}"
|
45
|
+
end
|
46
|
+
|
47
|
+
game.save
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def self.find_team_by_abbrev(team_abbrev)
|
52
|
+
self.all.select do |team|
|
53
|
+
team_abbrev == team.home_team.name || team_abbrev == team.away_team.name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
22
57
|
def is_over?
|
23
|
-
|
58
|
+
END_GAME_STATE.include?(self.status)
|
24
59
|
end
|
25
60
|
|
26
61
|
def is_active?
|
27
|
-
|
28
|
-
self.inning.to_i >= 1 && !is_over? && !not_active.include?(status)
|
62
|
+
self.inning.to_i >= 1 && !is_over? && PRE_GAME_STATE.include?(status)
|
29
63
|
end
|
30
64
|
|
31
65
|
|
32
66
|
|
33
|
-
def self.all
|
34
|
-
@@all
|
35
|
-
end
|
36
67
|
|
37
|
-
def self.reset_all!
|
38
|
-
@@all.clear
|
39
|
-
end
|
40
68
|
|
41
69
|
end
|
@@ -1,23 +1,18 @@
|
|
1
1
|
class YankeeScore::ScoreScraper
|
2
2
|
|
3
|
-
|
4
|
-
# @home_team = home_team
|
5
|
-
# @away_team = away_team
|
6
|
-
# end
|
3
|
+
|
7
4
|
@@base_url = "http://gd2.mlb.com/components/game/mlb/"
|
8
5
|
|
9
|
-
def date
|
10
|
-
|
6
|
+
def build_url(date = Date.today)
|
7
|
+
"#{@@base_url}year_#{date.year}/month_#{date.strftime("%m")}/day_#{date.strftime("%d")}/master_scoreboard.json"
|
11
8
|
end
|
12
9
|
|
13
10
|
def data
|
14
|
-
|
15
|
-
uri = URI.parse(url)
|
11
|
+
uri = URI.parse(self.build_url)
|
16
12
|
response = Net::HTTP.get_response(uri)
|
17
13
|
@data = response.body
|
18
14
|
end
|
19
15
|
|
20
|
-
# data.games.game[8].away_name_abbrev
|
21
16
|
|
22
17
|
def json
|
23
18
|
@json ||= JSON.parse(data, symbolize_names: true)
|
@@ -27,28 +22,10 @@ class YankeeScore::ScoreScraper
|
|
27
22
|
json[:data][:games][:game]
|
28
23
|
end
|
29
24
|
|
30
|
-
# def find_game(team = "NYY")
|
31
|
-
# games.find { |game| game[:home_name_abbrev] == team || game[:away_name_abbrev]}
|
32
|
-
# end
|
33
25
|
|
34
26
|
def load_games
|
35
|
-
games.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
g.start_time = game_hash[:time]
|
40
|
-
g.status = game_hash[:status][:status]
|
41
|
-
g.inning = game_hash[:status][:inning]
|
42
|
-
g.inning_state = game_hash[:status][:inning_state]
|
43
|
-
|
44
|
-
|
45
|
-
if game_hash.has_key?(:linescore)
|
46
|
-
g.home_team.runs = game_hash[:linescore][:r][:home]
|
47
|
-
g.away_team.runs = game_hash[:linescore][:r][:away]
|
48
|
-
g.score = "#{g.away_team.runs}-#{g.home_team.runs}"
|
49
|
-
end
|
50
|
-
|
51
|
-
g.save
|
27
|
+
games.select do |game_hash|
|
28
|
+
YankeeScore::Game.create_from_json(game_hash)
|
52
29
|
end
|
53
30
|
end
|
54
31
|
|
data/lib/yankee_score/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yankee_score
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shmuwol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|