Class: Roster

Inherits:
Object
  • Object
show all
Defined in:
lib/roster.rb

Overview

This class represents a team’s roster for a single game. Both players and coaches can be read from the roster.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#coachesObject

Returns the value of attribute coaches.



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

def coaches
  @coaches
end

#gidObject

Returns the value of attribute gid.



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

def gid
  @gid
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#playersObject

Returns the value of attribute players.



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

def players
  @players
end

#team_nameObject

Returns the value of attribute team_name.



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

def team_name
  @team_name
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#find_player_by_id(pid) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/roster.rb', line 34

def find_player_by_id(pid)
  players.each do |player|
    if player.pid == pid
      return player
    end
  end
  nil
end

#find_player_by_last_name(last_name) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/roster.rb', line 24

def find_player_by_last_name(last_name)
  players.each do |player|
    if player.last == last_name
      return player
    end
  end
  nil
end

#init(element, gid) ⇒ Object

type = home or away



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

def init(element, gid)
  self.gid = gid
  self.team_name = element.attributes['name']
  self.id = element.attributes['id']
  self.type = element.attributes['type']
  self.players = []
  self.coaches = []
  self.set_players(element)
  self.set_coaches(element)
end

#set_coaches(element) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/roster.rb', line 53

def set_coaches(element)
  element.elements.each("coach") { |element|
    coach = Coach.new
    coach.init(element)
    self.coaches << coach
  }
end

#set_players(element) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/roster.rb', line 44

def set_players(element)
  element.elements.each("player") { |element|
    player = Player.new
    player.init(element, gid)
    @players << player
  }
end