Class: Sportradar::Api::Soccer::Standing

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/soccer/standing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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) ⇒ Standing

Returns a new instance of Standing.



7
8
9
10
11
12
13
14
15
16
# File 'lib/sportradar/api/soccer/standing.rb', line 7

def initialize(data = {}, league_group: nil, **opts)
  @response     = data
  @id           = data["id"] || data['type']
  @api          = opts[:api]
  @league_group = league_group || data['league_group'] || @api&.league_group

  @groups_hash = {}

  update(data, **opts)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/soccer/standing.rb', line 5

def id
  @id
end

#league_groupObject (readonly)

Returns the value of attribute league_group.



5
6
7
# File 'lib/sportradar/api/soccer/standing.rb', line 5

def league_group
  @league_group
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/sportradar/api/soccer/standing.rb', line 5

def type
  @type
end

Instance Method Details

#apiObject



43
44
45
# File 'lib/sportradar/api/soccer/standing.rb', line 43

def api
  @api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
end

#group(name = nil) ⇒ Object

nil represents the complete team listing



31
32
33
# File 'lib/sportradar/api/soccer/standing.rb', line 31

def group(name = nil) # nil represents the complete team listing
  @groups_hash[name]
end

#groups(name = nil) ⇒ Object



27
28
29
# File 'lib/sportradar/api/soccer/standing.rb', line 27

def groups(name = nil)
  @groups_hash.values
end

#team(id) ⇒ Object



39
40
41
# File 'lib/sportradar/api/soccer/standing.rb', line 39

def team(id)
  @groups_hash.values.flat_map(&:teams).detect { |team| team.id == id }
end

#teamsObject



35
36
37
# File 'lib/sportradar/api/soccer/standing.rb', line 35

def teams
  @groups_hash.values.flat_map(&:teams)
end

#update(data, **opts) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/sportradar/api/soccer/standing.rb', line 18

def update(data, **opts)
  @type           = data['type']
  @tie_break_rule = data['tie_break_rule'] if data['tie_break_rule']

  if data['groups']
    create_data(@groups_hash, data['groups'], klass: TeamGroup, api: api, identifier: 'name')
  end
end