Class: SportsDataApi::Nfl::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/sports_data_api/nfl/team.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(team_hash, conference = nil, division = nil) ⇒ Team

Returns a new instance of Team.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sports_data_api/nfl/team.rb', line 7

def initialize(team_hash, conference = nil, division = nil)
  if team_hash
    @id = team_hash['id']
    @name = team_hash['name']
    @conference = conference
    @division = division
    @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

Instance Attribute Details

#conferenceObject (readonly)

Returns the value of attribute conference.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def conference
  @conference
end

#divisionObject (readonly)

Returns the value of attribute division.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def division
  @division
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def id
  @id
end

#marketObject (readonly)

Returns the value of attribute market.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def market
  @market
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def name
  @name
end

#playersObject (readonly)

Returns the value of attribute players.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def players
  @players
end

#pointsObject (readonly)

Returns the value of attribute points.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def points
  @points
end

#quartersObject (readonly)

Returns the value of attribute quarters.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def quarters
  @quarters
end

#remaining_challengesObject (readonly)

Returns the value of attribute remaining_challenges.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def remaining_challenges
  @remaining_challenges
end

#remaining_timeoutsObject (readonly)

Returns the value of attribute remaining_timeouts.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def remaining_timeouts
  @remaining_timeouts
end

#scoreObject (readonly)

Sum the score of each quarter



42
43
44
# File 'lib/sports_data_api/nfl/team.rb', line 42

def score
  @score
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def statistics
  @statistics
end

#venueObject (readonly)

Returns the value of attribute venue.



4
5
6
# File 'lib/sports_data_api/nfl/team.rb', line 4

def venue
  @venue
end

Instance Method Details

#==(other) ⇒ Object

Compare the Team with another team



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sports_data_api/nfl/team.rb', line 48

def ==(other)
  # Must have an id to compare
  return false if id.nil?

  if other.is_a? SportsDataApi::Nfl::Team
    other.id && id === other.id
  elsif other.is_a? Symbol
    id.to_sym === other
  else
    super(other)
  end
end