mlb_gd2 0.1.5 → 0.2.0

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: b41f7e49bc5202d26ab922b5ac7db4d9381e3546
4
- data.tar.gz: 40bd6864d0ac255e73111225fe7a4840995c1468
3
+ metadata.gz: ed654900774c0d872251c4851a6f038a70b6434d
4
+ data.tar.gz: 42c51f436fca0f6fda8d8fd69903ffceaace7760
5
5
  SHA512:
6
- metadata.gz: 65efc088f49a55c0b10d6a64c5de0fa1e09c7796a9f3c7ddc7094b50b3972c70c18e69bc8228065f1f7ba096b6a97044d461f03587d2f35072e9064a889081d4
7
- data.tar.gz: df5cd2efb5bd7208b3038a5a11a16f8b69d80e849237326c454eb5b4a49a07e47629e60955fc420a2f8ce2ba2a473426bb9d3c8e523dedb5cbc9ae867128368e
6
+ metadata.gz: 553f5e6b237f215d381d6286469e36f89323a857f4b8712cf6036f7d52e47672325cc35dc182177cc2b6433e813f7568400030b5b40e80e3fcebd2347d22658f
7
+ data.tar.gz: 0a1c422cffd2d29491fba7ef4658abda2ecc281dcfd76343d91b0455d2524b3c06d4f51bdc574a28d0227a91ed6ef467b8a26a9a037ff76363c734b9e83ce247
data/lib/mlb_gd2/game.rb CHANGED
@@ -11,30 +11,12 @@ class Game
11
11
  @boxscore = generate_nokogiri_xml(url + 'boxscore.xml').xpath("//boxscore").first
12
12
  end
13
13
 
14
- def teams
15
- Hash[
16
- :away, boxscore["away_fname"],
17
- :home, boxscore["home_fname"]
18
- ]
14
+ def home_team
15
+ Team.new(boxscore, "home")
19
16
  end
20
17
 
21
- def linescores
22
- linescore = boxscore.xpath("//linescore").first
23
-
24
- Hash[
25
- :away, {
26
- inning_line_score: boxscore.xpath("//inning_line_score").map { |inning| inning["away"].to_i },
27
- runs: linescore["away_team_runs"].to_i,
28
- hits: linescore["away_team_hits"].to_i,
29
- errors: linescore["away_team_errors"].to_i
30
- },
31
- :home, {
32
- inning_line_score: boxscore.xpath("//inning_line_score").map { |inning| inning["home"].to_i },
33
- runs: linescore["home_team_runs"].to_i,
34
- hits: linescore["home_team_hits"].to_i,
35
- errors: linescore["home_team_errors"].to_i
36
- }
37
- ]
18
+ def away_team
19
+ Team.new(boxscore, "away")
38
20
  end
39
21
 
40
22
  private
@@ -23,7 +23,7 @@ class Gameday
23
23
  end
24
24
 
25
25
  def game_from_team(team)
26
- selected_games = games.select { |game| game.teams[:home].include?(team) || game.teams[:away].include?(team) }
26
+ selected_games = games.select { |game| game.home_team.name.include?(team) || game.away_team.name.include?(team) }
27
27
 
28
28
  if selected_games.length > 1
29
29
  puts "That query fits more than one game. Please be more specific."
@@ -0,0 +1,19 @@
1
+ require "net/http"
2
+ require "nokogiri"
3
+ require_relative "./helpers"
4
+
5
+ class Team
6
+
7
+ attr_reader :name, :linescore, :runs, :hits, :errors
8
+
9
+ include Helpers
10
+
11
+ def initialize(boxscore, flag)
12
+ @name = boxscore.attribute("#{flag}_fname").value
13
+ @linescore = boxscore.xpath("//inning_line_score").map { |inning| inning["#{flag}"] }
14
+ @runs = boxscore.xpath("//linescore").first.attribute("#{flag}_team_runs").value
15
+ @hits = boxscore.xpath("//linescore").first.attribute("#{flag}_team_hits").value
16
+ @errors = boxscore.xpath("//linescore").first.attribute("#{flag}_team_errors").value
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlb_gd2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Firth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -34,6 +34,7 @@ files:
34
34
  - lib/mlb_gd2/game.rb
35
35
  - lib/mlb_gd2/gameday.rb
36
36
  - lib/mlb_gd2/helpers.rb
37
+ - lib/mlb_gd2/team.rb
37
38
  homepage: http://rubygems.org/gems/mlb_gd2
38
39
  licenses:
39
40
  - MIT