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.
-
#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_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.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sportradar/api/soccer/team.rb', line 13 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.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def abbreviation @abbreviation end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def country @country end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def country_code @country_code end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def id @id end |
#jerseys ⇒ Object (readonly)
Returns the value of attribute jerseys.
11 12 13 |
# File 'lib/sportradar/api/soccer/team.rb', line 11 def jerseys @jerseys end |
#league_group ⇒ Object (readonly)
Returns the value of attribute league_group.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def league_group @league_group end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
11 12 13 |
# File 'lib/sportradar/api/soccer/team.rb', line 11 def manager @manager end |
#name ⇒ Object (readonly) Also known as: market, display_name, full_name
Returns the value of attribute name.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def name @name end |
#player_stats ⇒ Object
Returns the value of attribute player_stats.
5 6 7 |
# File 'lib/sportradar/api/soccer/team.rb', line 5 def player_stats @player_stats end |
#qualifier ⇒ Object (readonly)
Returns the value of attribute qualifier.
6 7 8 |
# File 'lib/sportradar/api/soccer/team.rb', line 6 def qualifier @qualifier end |
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
11 12 13 |
# File 'lib/sportradar/api/soccer/team.rb', line 11 def statistics @statistics end |
#team_stats ⇒ Object (readonly)
Returns the value of attribute team_stats.
11 12 13 |
# File 'lib/sportradar/api/soccer/team.rb', line 11 def team_stats @team_stats end |
#tournament_id ⇒ Object
Returns the value of attribute tournament_id.
5 6 7 |
# File 'lib/sportradar/api/soccer/team.rb', line 5 def tournament_id @tournament_id end |
#venue ⇒ Object
Returns the value of attribute venue.
5 6 7 |
# File 'lib/sportradar/api/soccer/team.rb', line 5 def venue @venue end |
Instance Method Details
#api ⇒ Object
89 90 91 |
# File 'lib/sportradar/api/soccer/team.rb', line 89 def api @api || Sportradar::Api::Soccer::Api.new(league_group: @league_group) end |
#get_results ⇒ Object
116 117 118 119 |
# File 'lib/sportradar/api/soccer/team.rb', line 116 def get_results data = api.get_data(path_results).to_h ingest_results(data) end |
#get_roster ⇒ Object
100 101 102 103 |
# File 'lib/sportradar/api/soccer/team.rb', line 100 def get_roster data = api.get_data(path_roster).to_h ingest_roster(data) end |
#get_schedule ⇒ Object
132 133 134 135 |
# File 'lib/sportradar/api/soccer/team.rb', line 132 def get_schedule data = api.get_data(path_schedule).to_h ingest_schedule(data) end |
#get_statistics(tourn_id = self.tournament_id) ⇒ Object
148 149 150 151 |
# File 'lib/sportradar/api/soccer/team.rb', line 148 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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sportradar/api/soccer/team.rb', line 61 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
120 121 122 123 |
# File 'lib/sportradar/api/soccer/team.rb', line 120 def ingest_results(data) update(data) data end |
#ingest_roster(data) ⇒ Object
104 105 106 107 |
# File 'lib/sportradar/api/soccer/team.rb', line 104 def ingest_roster(data) update(data) data end |
#ingest_schedule(data) ⇒ Object
136 137 138 139 |
# File 'lib/sportradar/api/soccer/team.rb', line 136 def ingest_schedule(data) update(data) data end |
#ingest_statistics(data) ⇒ Object
152 153 154 155 |
# File 'lib/sportradar/api/soccer/team.rb', line 152 def ingest_statistics(data) update(data) data end |
#matches ⇒ Object
85 86 87 |
# File 'lib/sportradar/api/soccer/team.rb', line 85 def matches @matches_hash.values end |
#path_base ⇒ Object
93 94 95 |
# File 'lib/sportradar/api/soccer/team.rb', line 93 def path_base "teams/#{ id }" end |
#path_results ⇒ Object
113 114 115 |
# File 'lib/sportradar/api/soccer/team.rb', line 113 def path_results "#{ path_base }/results" end |
#path_roster ⇒ Object
97 98 99 |
# File 'lib/sportradar/api/soccer/team.rb', line 97 def path_roster "#{ path_base }/profile" end |
#path_schedule ⇒ Object
129 130 131 |
# File 'lib/sportradar/api/soccer/team.rb', line 129 def path_schedule "#{ path_base }/schedule" end |
#path_statistics(tourn_id = self.tournament_id) ⇒ Object
145 146 147 |
# File 'lib/sportradar/api/soccer/team.rb', line 145 def path_statistics(tourn_id = self.tournament_id) "tournaments/#{ tourn_id }/#{ path_base }/statistics" end |
#players ⇒ Object
81 82 83 |
# File 'lib/sportradar/api/soccer/team.rb', line 81 def players @players_hash.values end |
#queue_results ⇒ Object
124 125 126 127 |
# File 'lib/sportradar/api/soccer/team.rb', line 124 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
108 109 110 111 |
# File 'lib/sportradar/api/soccer/team.rb', line 108 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
140 141 142 143 |
# File 'lib/sportradar/api/soccer/team.rb', line 140 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
156 157 158 159 |
# File 'lib/sportradar/api/soccer/team.rb', line 156 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
26 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 |
# File 'lib/sportradar/api/soccer/team.rb', line 26 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
77 78 79 |
# File 'lib/sportradar/api/soccer/team.rb', line 77 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 |