Class: Sportradar::Api::Football::Scoring

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/football/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/football/scoring.rb', line 7

def initialize(data, **opts)
  @api      = opts[:api]
  @game     = opts[:game]
  
  @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/football/scoring.rb', line 5

def api
  @api
end

#awayObject

Returns the value of attribute away.



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

def away
  @away
end

#homeObject

Returns the value of attribute home.



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

def home
  @home
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#scoresObject

Returns the value of attribute scores.



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

def scores
  @scores
end

Instance Method Details

#points(team_id) ⇒ Object



42
43
44
# File 'lib/sportradar/api/football/scoring.rb', line 42

def points(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
# File 'lib/sportradar/api/football/scoring.rb', line 17

def update(data, source: nil, **opts)
  new_scores = case source
  when :box
    parse_from_box(data)
  when :extended_box
    parse_from_box(data)
  when :pbp
    parse_from_pbp(data)
  when :summary
    parse_from_summary(data)
  when :statistics
    parse_from_statistics(data)
  else
    if data['quarter'] || data['half']
      parse_from_pbp(data)
    elsif data['team']
      parse_from_box(data)
    else # schedule requests
      {}
    end
  end
  @scores.each { |k, v| v.merge!(new_scores.delete(k) || {} ) }
  new_scores.each { |k, v| @scores.merge!(k => v) }
end