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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e58bd8ed8496688340a3935ca15ba4fa711e4e29
4
- data.tar.gz: a727e66c02cf331d08321ba090a6b57339c0211a
3
+ metadata.gz: 3645da79fd2ce3881d9dc0ce399b80548d01b62a
4
+ data.tar.gz: 6e42203cab469ae22f753c47274d284152483800
5
5
  SHA512:
6
- metadata.gz: 2596101e0a8c5bc371738560d03011d47ecf1c9afa6c65abd8acb7d24a5b1b92d3364ca0560d813117be40feea7553cd4d8c6bfe2d1cbd855f193e1be25a12cb
7
- data.tar.gz: 3899196bbf95d142ecfc4bc3146b0187f0e655730ffe6b93de07afbc74688fa899c440579b19529c061470f360d0fa1c0f3cf3edd7ae7748744c0cba9a0132c4
6
+ metadata.gz: 8e4daca595ab99d865ccc9f27835f7b07a6ad5d9775ab71dbb8559a6eef5b4b42390b4c37ff33dd4d2492c8fcd10ed51f52e49e38c1bfdc8aa4da55bc4b9e831
7
+ data.tar.gz: 7381dc0f7bd020ee49ebe424b9acf6f63dc9d85abe46c4a24de56c51d27a8b6f80399122fc8ff88103371956801328909bc0332fe103db9c41a1c60b17c92b35
@@ -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(team = nil)
51
- YankeeScore::Game.all.each do |game|
52
- if team == game.home_team.name || team == game.away_team.name
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
 
@@ -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
- self.status == "Final" || self.status == "Postponed" || self.status == "Game Over"
58
+ END_GAME_STATE.include?(self.status)
24
59
  end
25
60
 
26
61
  def is_active?
27
- not_active = ["Pre-Game","Preview", "Warmup"]
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
- # def initialize(home_team = nil, away_team = nil)
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
- @date = Date.today
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
- url = "#{@@base_url}year_#{date.year}/month_#{date.strftime("%m")}/day_#{date.strftime("%d")}/master_scoreboard.json"
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.each do |game_hash|
36
- g = YankeeScore::Game.new(YankeeScore::Team.new(game_hash[:home_name_abbrev]), YankeeScore::Team.new(game_hash[:away_name_abbrev]))
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
 
@@ -1,3 +1,3 @@
1
1
  module YankeeScore
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-13 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler