class SportsDataApi::Ncaafb::Team
Attributes
conference[R]
division[R]
id[R]
market[R]
name[R]
players[R]
points[R]
quarters[R]
remaining_challenges[R]
remaining_timeouts[R]
score[R]
statistics[R]
subdivision[R]
venue[R]
Public Class Methods
new(team_hash, conference = nil, division = nil, subdivision = nil)
click to toggle source
# File lib/sports_data_api/ncaafb/team.rb, line 7 def initialize(team_hash, conference = nil, division = nil, subdivision = nil) if team_hash @id = team_hash['id'] @name = team_hash['name'] @conference = conference @division = division @subdivision = subdivision @market = team_hash['market'] @remaining_challenges = team_hash['remaining_challenges'] @remaining_timeouts = team_hash['remaining_timeouts'] @quarters = [] if team_hash['scoring'] team_hash['scoring'].each do |scoring_hash| @quarters[scoring_hash['quarter']-1] = scoring_hash['points'] end end @quarters = @quarters.fill(0, @quarters.size, 4 - @quarters.size) # Parse the Venue data if it exists if team_hash.key?('venue') @venue = Venue.new(team_hash['venue']) end if team_hash['statistics'] @statistics = parse_team_statistics(team_hash['statistics']) @players = parse_player_statistics(team_hash['statistics']) end if team_hash['players'] @players = TeamRoster.new(team_hash).players end @points = team_hash['points'] || score end end
Public Instance Methods
==(other)
click to toggle source
Compare the Team
with another team
Calls superclass method
# File lib/sports_data_api/ncaafb/team.rb, line 49 def ==(other) # Must have an id to compare return false if id.nil? if other.is_a? SportsDataApi::Ncaafb::Team other.id && id === other.id elsif other.is_a? Symbol id.to_sym === other else super(other) end end
Private Instance Methods
parse_player_statistics(stats_hash)
click to toggle source
# File lib/sports_data_api/ncaafb/team.rb, line 72 def parse_player_statistics(stats_hash) players = [] stats_hash.keys.each do |key| next if !stats_hash[key]['players'] stats_hash[key]['players'].each do |p| player = players.select{|a| a['id'] == p['id']}.first || {} players << player if !players.select{|a| a['id'] == p['id']}.first ['id', 'name', 'jersey', 'position'].each do |k| player[k] = p.delete(k) end player[key] = p end end players end
parse_team_statistics(stats_hash)
click to toggle source
# File lib/sports_data_api/ncaafb/team.rb, line 64 def parse_team_statistics(stats_hash) stats = {} stats_hash.keys.each do |key| stats[key] = stats_hash[key]['team'] end stats end