Class: Sportradar::Api::Soccer::Team
- Defined in:
- lib/sportradar/api/soccer/team.rb
Instance Attribute Summary collapse
-
#abbreviation ⇒ Object
(also: #alias)
readonly
Returns the value of attribute abbreviation.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#jerseys ⇒ Object
readonly
Returns the value of attribute jerseys.
-
#league_group ⇒ Object
readonly
Returns the value of attribute league_group.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#name ⇒ Object
(also: #market, #display_name, #full_name)
readonly
Returns the value of attribute name.
-
#player_stats ⇒ Object
Returns the value of attribute player_stats.
-
#qualifier ⇒ Object
readonly
Returns the value of attribute qualifier.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
-
#team_stats ⇒ Object
readonly
Returns the value of attribute team_stats.
-
#tournament_id ⇒ Object
Returns the value of attribute tournament_id.
-
#venue ⇒ Object
Returns the value of attribute venue.
Instance Method Summary collapse
- #api ⇒ Object
- #get_results ⇒ Object
- #get_roster ⇒ Object
- #get_schedule ⇒ Object
- #get_season_stats(*args) ⇒ Object
- #get_statistics(tourn_id = self.tournament_id) ⇒ Object
- #get_tournament_id(data, **opts) ⇒ Object
- #ingest_results(data) ⇒ Object
- #ingest_roster(data) ⇒ Object
- #ingest_schedule(data) ⇒ Object
- #ingest_statistics(data) ⇒ Object
-
#initialize(data = {}, league_group: nil, **opts) ⇒ Team
constructor
A new instance of Team.
- #matches ⇒ Object
- #path_base ⇒ Object
- #path_results ⇒ Object
- #path_roster ⇒ Object
- #path_schedule ⇒ Object
- #path_statistics(tourn_id = self.tournament_id) ⇒ Object
- #players ⇒ Object
- #queue_results ⇒ Object
- #queue_roster ⇒ Object
- #queue_schedule ⇒ Object
- #queue_statistics ⇒ Object
- #update(data, **opts) ⇒ Object
- #update_player_stats(player, stats, game = nil) ⇒ Object
Methods inherited from Data
#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data
Constructor Details
#initialize(data = {}, league_group: nil, **opts) ⇒ Team
Returns a new instance of Team.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sportradar/api/soccer/team.rb', line 14 def initialize(data = {}, league_group: nil, **opts) @response = data @id = data['id'] @api = opts[:api] @league_group = league_group || data['league_group'] || @api&.league_group @players_hash = {} @player_stats = {} @matches_hash = {} update(data, **opts) end |
Instance Attribute Details
#abbreviation ⇒ Object (readonly) Also known as: alias
Returns the value of attribute abbreviation.
7 8 9 |
# File 'lib/sportradar/api/soccer/team.rb', line 7 def abbreviation @abbreviation end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
7 8 9 |
# File 'lib/sportradar/api/soccer/team.rb', line 7 def country @country end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
7 8 9 |
# File 'lib/sportradar/api/soccer/team.rb', line 7 def country_code @country_code end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/sportradar/api/soccer/team.rb', line 7 def id @id end |
#jerseys ⇒ Object (readonly)
Returns the value of attribute jerseys.
12 13 14 |
# File 'lib/sportradar/api/soccer/team.rb', line 12 def jerseys @jerseys end |
#league_group ⇒ Object (readonly)
Returns the value of attribute league_group.
7 8 9 |
# File 'lib/sportradar/api/soccer/team.rb', line 7 def league_group @league_group end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
12 13 14 |
# File 'lib/sportradar/api/soccer/team.rb', line 12 def manager @manager end |
#name ⇒ Object (readonly) Also known as: market, display_name, full_name
Returns the value of attribute name.
7 8 9 |
# File 'lib/sportradar/api/soccer/team.rb', line 7 def name @name end |
#player_stats ⇒ Object
Returns the value of attribute player_stats.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def player_stats @player_stats end |
#qualifier ⇒ Object (readonly)
Returns the value of attribute qualifier.
7 8 9 |
# File 'lib/sportradar/api/soccer/team.rb', line 7 def qualifier @qualifier end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/soccer/team.rb', line 5 def response @response end |
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
12 13 14 |
# File 'lib/sportradar/api/soccer/team.rb', line 12 def statistics @statistics end |
#team_stats ⇒ Object (readonly)
Returns the value of attribute team_stats.
12 13 14 |
# File 'lib/sportradar/api/soccer/team.rb', line 12 def team_stats @team_stats end |
#tournament_id ⇒ Object
Returns the value of attribute tournament_id.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def tournament_id @tournament_id end |
#venue ⇒ Object
Returns the value of attribute venue.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def venue @venue end |
Instance Method Details
#api ⇒ Object
90 91 92 |
# File 'lib/sportradar/api/soccer/team.rb', line 90 def api @api || Sportradar::Api::Soccer::Api.new(league_group: @league_group) end |
#get_results ⇒ Object
117 118 119 120 |
# File 'lib/sportradar/api/soccer/team.rb', line 117 def get_results data = api.get_data(path_results).to_h ingest_results(data) end |
#get_roster ⇒ Object
101 102 103 104 |
# File 'lib/sportradar/api/soccer/team.rb', line 101 def get_roster data = api.get_data(path_roster).to_h ingest_roster(data) end |
#get_schedule ⇒ Object
133 134 135 136 |
# File 'lib/sportradar/api/soccer/team.rb', line 133 def get_schedule data = api.get_data(path_schedule).to_h ingest_schedule(data) end |
#get_season_stats(*args) ⇒ Object
153 154 155 |
# File 'lib/sportradar/api/soccer/team.rb', line 153 def get_season_stats(*args) get_statistics end |
#get_statistics(tourn_id = self.tournament_id) ⇒ Object
149 150 151 152 |
# File 'lib/sportradar/api/soccer/team.rb', line 149 def get_statistics(tourn_id = self.tournament_id) data = api.get_data(path_statistics(tourn_id)).to_h ingest_statistics(data) end |
#get_tournament_id(data, **opts) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sportradar/api/soccer/team.rb', line 62 def get_tournament_id(data, **opts) @tournament_id ||= if opts[:tournament] opts[:tournament].id elsif opts[:season]&.tournament_id opts[:season]&.tournament_id elsif opts[:match]&.tournament_id opts[:match]&.tournament_id elsif data['tournament_id'] data['tournament_id'] elsif data['tournament'] data.dig('tournament', 'id') elsif data['season'] data.dig('season', 'tournament_id') end end |
#ingest_results(data) ⇒ Object
121 122 123 124 |
# File 'lib/sportradar/api/soccer/team.rb', line 121 def ingest_results(data) update(data) data end |
#ingest_roster(data) ⇒ Object
105 106 107 108 |
# File 'lib/sportradar/api/soccer/team.rb', line 105 def ingest_roster(data) update(data) data end |
#ingest_schedule(data) ⇒ Object
137 138 139 140 |
# File 'lib/sportradar/api/soccer/team.rb', line 137 def ingest_schedule(data) update(data) data end |
#ingest_statistics(data) ⇒ Object
156 157 158 159 |
# File 'lib/sportradar/api/soccer/team.rb', line 156 def ingest_statistics(data) update(data) data end |
#matches ⇒ Object
86 87 88 |
# File 'lib/sportradar/api/soccer/team.rb', line 86 def matches @matches_hash.values end |
#path_base ⇒ Object
94 95 96 |
# File 'lib/sportradar/api/soccer/team.rb', line 94 def path_base "teams/#{ id }" end |
#path_results ⇒ Object
114 115 116 |
# File 'lib/sportradar/api/soccer/team.rb', line 114 def path_results "#{ path_base }/results" end |
#path_roster ⇒ Object
98 99 100 |
# File 'lib/sportradar/api/soccer/team.rb', line 98 def path_roster "#{ path_base }/profile" end |
#path_schedule ⇒ Object
130 131 132 |
# File 'lib/sportradar/api/soccer/team.rb', line 130 def path_schedule "#{ path_base }/schedule" end |
#path_statistics(tourn_id = self.tournament_id) ⇒ Object
146 147 148 |
# File 'lib/sportradar/api/soccer/team.rb', line 146 def path_statistics(tourn_id = self.tournament_id) "tournaments/#{ tourn_id }/#{ path_base }/statistics" end |
#players ⇒ Object
82 83 84 |
# File 'lib/sportradar/api/soccer/team.rb', line 82 def players @players_hash.values end |
#queue_results ⇒ Object
125 126 127 128 |
# File 'lib/sportradar/api/soccer/team.rb', line 125 def queue_results url, headers, , timeout = api.get_request_info(path_results) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_results)} end |
#queue_roster ⇒ Object
109 110 111 112 |
# File 'lib/sportradar/api/soccer/team.rb', line 109 def queue_roster url, headers, , timeout = api.get_request_info(path_roster) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_roster)} end |
#queue_schedule ⇒ Object
141 142 143 144 |
# File 'lib/sportradar/api/soccer/team.rb', line 141 def queue_schedule url, headers, , timeout = api.get_request_info(path_schedule) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_schedule)} end |
#queue_statistics ⇒ Object
160 161 162 163 |
# File 'lib/sportradar/api/soccer/team.rb', line 160 def queue_statistics url, headers, , timeout = api.get_request_info(path_statistics) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_statistics)} end |
#update(data, **opts) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sportradar/api/soccer/team.rb', line 27 def update(data, **opts) @id = data['id'] if data['id'] @league_group = opts[:league_group] || data['league_group'] || @league_group get_tournament_id(data, **opts) if data["team"] update(data["team"]) end @name = data['name'] if data['name'] @country = data['country'] if data['country'] @country_code = data['country_code'] if data['country_code'] @abbreviation = data['abbreviation'] if data['abbreviation'] @qualifier = data['qualifier'] if data['qualifier'] @venue = Venue.new(data['venue']) if data['venue'] create_data(@players_hash, data['players'], klass: Player, api: api, team: self, **opts) if data['players'] create_data(@players_hash, data['player_statistics'], klass: Player, api: api, team: self, **opts) if data['player_statistics'] @team_stats = data['team_statistics'] if data['team_statistics'] # parse_players(data.dig('players'), opts[:match]) if data.dig('players') if opts[:match] opts[:match].update_stats(self, data['statistics']) if data['statistics'] end create_data(@matches_hash, Soccer.parse_results(data['results']), klass: Match, api: api, team: self) if data['results'] create_data(@matches_hash, data['schedule'], klass: Match, api: api, team: self) if data['schedule'] # TODO roster @jerseys = data['jerseys'] if data['jerseys'] @manager = data['manager'] if data['manager'] @statistics = data['statistics'] if data['statistics'] end |
#update_player_stats(player, stats, game = nil) ⇒ Object
78 79 80 |
# File 'lib/sportradar/api/soccer/team.rb', line 78 def update_player_stats(player, stats, game = nil) game ? game.update_player_stats(player, stats) : @player_stats.merge(player.id => stats.to_h.merge(player: player)) end |