Class: Team

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/mlb_gd2/team.rb

Constant Summary

Constants included from Helpers

Helpers::GD2_MLB_BASE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#boxscore, #build_base_url, #generate_nokogiri_html, #generate_nokogiri_xml, #valid_game?

Constructor Details

#initialize(boxscore, flag) ⇒ Team

Returns a new instance of Team.



13
14
15
16
17
18
19
20
21
# File 'lib/mlb_gd2/team.rb', line 13

def initialize(boxscore, flag)
  @name = boxscore.attribute("#{flag}_fname").value
  @linescore = boxscore.xpath("//inning_line_score").map { |inning| inning["#{flag}"] }
  @runs = boxscore.xpath("//linescore").first.attribute("#{flag}_team_runs").value
  @hits = boxscore.xpath("//linescore").first.attribute("#{flag}_team_hits").value
  @errors = boxscore.xpath("//linescore").first.attribute("#{flag}_team_errors").value
  @batters = boxscore.search("batting[team_flag='#{flag}']>batter").map { |batter_xml| Batter.new(batter_xml) }
  @pitchers = boxscore.search("pitching[team_flag='#{flag}']>pitcher").map { |pitcher_xml| Pitcher.new(pitcher_xml) }
end

Instance Attribute Details

#battersObject (readonly)

Returns the value of attribute batters.



9
10
11
# File 'lib/mlb_gd2/team.rb', line 9

def batters
  @batters
end

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/mlb_gd2/team.rb', line 9

def errors
  @errors
end

#hitsObject (readonly)

Returns the value of attribute hits.



9
10
11
# File 'lib/mlb_gd2/team.rb', line 9

def hits
  @hits
end

#linescoreObject (readonly)

Returns the value of attribute linescore.



9
10
11
# File 'lib/mlb_gd2/team.rb', line 9

def linescore
  @linescore
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/mlb_gd2/team.rb', line 9

def name
  @name
end

#pitchersObject (readonly)

Returns the value of attribute pitchers.



9
10
11
# File 'lib/mlb_gd2/team.rb', line 9

def pitchers
  @pitchers
end

#runsObject (readonly)

Returns the value of attribute runs.



9
10
11
# File 'lib/mlb_gd2/team.rb', line 9

def runs
  @runs
end