Class: Sportradar::Api::Soccer::TeamGroup
- Defined in:
- lib/sportradar/api/soccer/team_group.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#league_group ⇒ Object
readonly
Returns the value of attribute league_group.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tournament_id ⇒ Object
readonly
Returns the value of attribute tournament_id.
Instance Method Summary collapse
- #api ⇒ Object
- #get_tournament_id(data, **opts) ⇒ Object
-
#initialize(data = {}, league_group: nil, **opts) ⇒ TeamGroup
constructor
A new instance of TeamGroup.
- #team(id) ⇒ Object
- #teams ⇒ 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) ⇒ TeamGroup
Returns a new instance of TeamGroup.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 7 def initialize(data = {}, league_group: nil, **opts) @response = data @id = data["id"] || data['name'] @api = opts[:api] @league_group = league_group || data['league_group'] || @api&.league_group @teams_hash = {} update(data, **opts) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 5 def id @id end |
#league_group ⇒ Object (readonly)
Returns the value of attribute league_group.
5 6 7 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 5 def league_group @league_group end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 5 def name @name end |
#tournament_id ⇒ Object (readonly)
Returns the value of attribute tournament_id.
5 6 7 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 5 def tournament_id @tournament_id end |
Instance Method Details
#api ⇒ Object
50 51 52 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 50 def api @api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group) end |
#get_tournament_id(data, **opts) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 27 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'] data.dig('tournament', 'id') elsif data['season'] data.dig('season', 'tournament_id') end end |
#team(id) ⇒ Object
46 47 48 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 46 def team(id) @teams_hash[id] end |
#teams ⇒ Object
42 43 44 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 42 def teams @teams_hash.values end |
#update(data, **opts) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/sportradar/api/soccer/team_group.rb', line 18 def update(data, **opts) @name = data['name'] get_tournament_id(data, **opts) if team_data = (data['teams'] || data['team_standings']) create_data(@teams_hash, team_data, klass: Team, api: api, tournament: opts[:tournament], team_group: self) end end |