Class: Match

Inherits:
Object
  • Object
show all
Defined in:
lib/api/utils/match.rb

Overview

This class is used to get the data from a match

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Match

Returns a new instance of Match.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/api/utils/match.rb', line 12

def initialize(data)
  @meta_data = data['data']['metadata']
  @player_data = data['data']['players']
  @team_data = data['data']['teams']

  fetch_game_info
  fetch_game_type
  fetch_game_statistics

  fetch_players
end

Instance Attribute Details

#all_playersObject (readonly)

Returns the value of attribute all_players.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def all_players
  @all_players
end

#blue_rounds_lostObject (readonly)

Returns the value of attribute blue_rounds_lost.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def blue_rounds_lost
  @blue_rounds_lost
end

#blue_rounds_wonObject (readonly)

Returns the value of attribute blue_rounds_won.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def blue_rounds_won
  @blue_rounds_won
end

#blue_teamObject (readonly)

Returns the value of attribute blue_team.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def blue_team
  @blue_team
end

#clusterObject (readonly)

Returns the value of attribute cluster.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def cluster
  @cluster
end

#game_lengthObject (readonly)

Returns the value of attribute game_length.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def game_length
  @game_length
end

#game_startObject (readonly)

Returns the value of attribute game_start.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def game_start
  @game_start
end

#game_start_patchedObject (readonly)

Returns the value of attribute game_start_patched.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def game_start_patched
  @game_start_patched
end

#game_versionObject (readonly)

Returns the value of attribute game_version.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def game_version
  @game_version
end

#mapObject (readonly)

Returns the value of attribute map.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def map
  @map
end

#matchidObject (readonly)

Returns the value of attribute matchid.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def matchid
  @matchid
end

#modeObject (readonly)

Returns the value of attribute mode.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def mode
  @mode
end

#platformObject (readonly)

Returns the value of attribute platform.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def platform
  @platform
end

#queueObject (readonly)

Returns the value of attribute queue.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def queue
  @queue
end

#red_rounds_lostObject (readonly)

Returns the value of attribute red_rounds_lost.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def red_rounds_lost
  @red_rounds_lost
end

#red_rounds_wonObject (readonly)

Returns the value of attribute red_rounds_won.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def red_rounds_won
  @red_rounds_won
end

#red_teamObject (readonly)

Returns the value of attribute red_team.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def red_team
  @red_team
end

#regionObject (readonly)

Returns the value of attribute region.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def region
  @region
end

#rounds_playedObject (readonly)

Returns the value of attribute rounds_played.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def rounds_played
  @rounds_played
end

#season_idObject (readonly)

Returns the value of attribute season_id.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def season_id
  @season_id
end

#winning_teamObject (readonly)

Returns the value of attribute winning_team.



7
8
9
# File 'lib/api/utils/match.rb', line 7

def winning_team
  @winning_team
end

Instance Method Details

#accuracy(name, tag) ⇒ Object



36
37
38
39
# File 'lib/api/utils/match.rb', line 36

def accuracy(name, tag)
  result = @all_players.select { |player| player.name.gsub(' ', '') == name.gsub(' ', '') && player.tag == tag }
  [result[0].headshots, result[0].bodyshots, result[0].legshots]
end

#mvpObject



24
25
26
# File 'lib/api/utils/match.rb', line 24

def mvp
  @all_players.max_by(&:score)
end

#mvp_blueObject



32
33
34
# File 'lib/api/utils/match.rb', line 32

def mvp_blue
  @blue_team.max_by(&:score)
end

#mvp_redObject



28
29
30
# File 'lib/api/utils/match.rb', line 28

def mvp_red
  @red_team.max_by(&:score)
end

#player(name, tag) ⇒ Object



41
42
43
# File 'lib/api/utils/match.rb', line 41

def player(name, tag)
  @all_players.select { |player| player.name.gsub(' ', '') == name.gsub(' ', '') && player.tag == tag }
end