Class: Sportradar::Api::Soccer::Scoring

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/soccer/scoring.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, **opts) ⇒ Scoring

Returns a new instance of Scoring.



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

def initialize(data, **opts)
  @api      = opts[:api]
  @match    = opts[:match]
  
  @scores = {}
  @id = data['id']
  
  update(data, **opts)
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



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

def api
  @api
end

#awayObject

Returns the value of attribute away.



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

def away
  @away
end

#homeObject

Returns the value of attribute home.



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

def home
  @home
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#scoresObject

Returns the value of attribute scores.



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

def scores
  @scores
end

Instance Method Details

#goals(team_id) ⇒ Object



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

def goals(team_id)
  @score[team_id].to_i
end

#update(data, source: nil, **opts) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sportradar/api/soccer/scoring.rb', line 17

def update(data, source: nil, **opts)
  # new_scores = case source
  # when :box
  #   parse_from_box(data)
  # when :timeline
  #   parse_from_timeline(data)
  # when :summary
  #   parse_from_box(data)
  # else
  #   if data['period'] || data['half']
  #     parse_from_timeline(data)
  #   elsif data['team']
  #     parse_from_box(data)
  #   else # schedule requests
  #     {}
  #   end
  # end
  new_scores = parse_from_timeline(data)
  # parse data structure
  # handle data from team (all periods)
  # handle data from period (both teams)
  # handle data from match?
  @scores.each { |k, v| v.merge!(new_scores.delete(k) || {} ) }
  new_scores.each { |k, v| @scores.merge!(k => v) }
end