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.
-
#qualifier ⇒ Object
readonly
Returns the value of attribute qualifier.
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
-
#team_statistics ⇒ Object
readonly
Returns the value of attribute team_statistics.
-
#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
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 |
# 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 = {} @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 |
#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_statistics ⇒ Object (readonly)
Returns the value of attribute team_statistics.
11 12 13 |
# File 'lib/sportradar/api/soccer/team.rb', line 11 def team_statistics @team_statistics 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
80 81 82 |
# File 'lib/sportradar/api/soccer/team.rb', line 80 def api @api || Sportradar::Api::Soccer::Api.new(league_group: @league_group) end |
#get_results ⇒ Object
107 108 109 110 |
# File 'lib/sportradar/api/soccer/team.rb', line 107 def get_results data = api.get_data(path_results).to_h ingest_results(data) end |
#get_roster ⇒ Object
91 92 93 94 |
# File 'lib/sportradar/api/soccer/team.rb', line 91 def get_roster data = api.get_data(path_roster).to_h ingest_roster(data) end |
#get_schedule ⇒ Object
123 124 125 126 |
# File 'lib/sportradar/api/soccer/team.rb', line 123 def get_schedule data = api.get_data(path_schedule).to_h ingest_schedule(data) end |
#get_statistics(tourn_id = self.tournament_id) ⇒ Object
139 140 141 142 |
# File 'lib/sportradar/api/soccer/team.rb', line 139 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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sportradar/api/soccer/team.rb', line 56 def get_tournament_id(data, **opts) @tournament_id ||= if opts[:tournament] opts[:tournament].id elsif opts[:season] opts[:season].tournament_id elsif opts[:match] 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
111 112 113 114 |
# File 'lib/sportradar/api/soccer/team.rb', line 111 def ingest_results(data) update(data) data end |
#ingest_roster(data) ⇒ Object
95 96 97 98 |
# File 'lib/sportradar/api/soccer/team.rb', line 95 def ingest_roster(data) update(data) data end |
#ingest_schedule(data) ⇒ Object
127 128 129 130 |
# File 'lib/sportradar/api/soccer/team.rb', line 127 def ingest_schedule(data) update(data) data end |
#ingest_statistics(data) ⇒ Object
143 144 145 146 |
# File 'lib/sportradar/api/soccer/team.rb', line 143 def ingest_statistics(data) update(data) data end |
#matches ⇒ Object
76 77 78 |
# File 'lib/sportradar/api/soccer/team.rb', line 76 def matches @matches_hash.values end |
#path_base ⇒ Object
84 85 86 |
# File 'lib/sportradar/api/soccer/team.rb', line 84 def path_base "teams/#{ id }" end |
#path_results ⇒ Object
104 105 106 |
# File 'lib/sportradar/api/soccer/team.rb', line 104 def path_results "#{ path_base }/results" end |
#path_roster ⇒ Object
88 89 90 |
# File 'lib/sportradar/api/soccer/team.rb', line 88 def path_roster "#{ path_base }/profile" end |
#path_schedule ⇒ Object
120 121 122 |
# File 'lib/sportradar/api/soccer/team.rb', line 120 def path_schedule "#{ path_base }/schedule" end |
#path_statistics(tourn_id = self.tournament_id) ⇒ Object
136 137 138 |
# File 'lib/sportradar/api/soccer/team.rb', line 136 def path_statistics(tourn_id = self.tournament_id) "tournaments/#{ tourn_id }/#{ path_base }/statistics" end |
#players ⇒ Object
72 73 74 |
# File 'lib/sportradar/api/soccer/team.rb', line 72 def players @players_hash.values end |
#queue_results ⇒ Object
115 116 117 118 |
# File 'lib/sportradar/api/soccer/team.rb', line 115 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
99 100 101 102 |
# File 'lib/sportradar/api/soccer/team.rb', line 99 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
131 132 133 134 |
# File 'lib/sportradar/api/soccer/team.rb', line 131 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
147 148 149 150 |
# File 'lib/sportradar/api/soccer/team.rb', line 147 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
25 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 |
# File 'lib/sportradar/api/soccer/team.rb', line 25 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) if data['players'] create_data(@players_hash, data['player_statistics'], klass: Player, api: api, team: self) if data['player_statistics'] # TODO team statistics @team_statistics = data['team_statistics'] if data['team_statistics'] 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 |