Class: RUBG::Match

Inherits:
RubgEndpoint show all
Defined in:
lib/rubg/match.rb

Instance Attribute Summary collapse

Attributes inherited from RubgEndpoint

#data, #errors, #ratelimit, #ratelimit_remaining, #raw_response, #response_ts

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Match

Returns a new instance of Match.



13
14
15
16
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubg/match.rb', line 13

def initialize( args )
  args                  = self.class.defaults.merge(args)
  super({
    :response => args[:response]
    })
  if args[:response]["data"]
    @match_id         = args[:match_data]["id"]
    @created          = args[:match_data]["attributes"]["createdAt"]
    @duration         = args[:match_data]["attributes"]["duration"]
    @mode             = args[:match_data]["attributes"]["gameMode"]
    @map              = convert_map_name(args[:match_data]["attributes"]["mapName"])
    @patch_version    = args[:match_data]["attributes"]["patchVersion"]
    @shard            = args[:match_data]["attributes"]["shardId"]
    @stats            = args[:match_data]["attributes"]["stats"]
    @tags             = args[:match_data]["attributes"]["tags"]
    @title_id         = args[:match_data]["attributes"]["titleId"]
    @telemetry_id     = args[:match_data]["relationships"]["assets"]["data"][0]["id"]
    @rounds           = args[:match_data]["relationships"]["rounds"]["data"]
    @spectators       = args[:match_data]["relationships"]["spectators"]["data"]
    @link             = args[:match_data]["links"]["self"]
    @telemetry_link   = args[:match_included].detect {|i| i["type"] == "asset" }["attributes"]["URL"]
    
    @rosters          = []
    @participants     = []
    generate_roster_objects(args[:match_included])
    

    @player_count     = @participants.count
    @roster_count     = @rosters.count
    @winners          = @rosters.detect {|r| r.won}


    #aggregates
    @names              = @participants.collect(&:name).sort!
    @survived           = @participants.select {|m| m.death_type == "alive"}
    @dbnos              = @participants.sum {|m| m.dbnos}
    @assists            = @participants.sum {|m| m.assists}
    @boosts             = @participants.sum {|m| m.boosts}
    @damage_dealt       = @participants.sum {|m| m.damage_dealt}
    @damage_dealt_avg   = ((participants.sum {|m| m.damage_dealt}).to_f/self.player_count.to_f).to_i
    @headshot_kills     = @participants.sum {|m| m.headshot_kills}
    @heals              = @participants.sum {|m| m.heals}
    @kills              = @participants.sum {|m| m.kills}
    @ride_distance_avg  = ((participants.sum {|m| m.ride_distance}).to_f/self.player_count.to_f).to_i
    @revives            = @participants.sum {|m| m.revives}
    @road_kills         = @participants.sum {|m| m.road_kills}
    @team_kills         = @participants.sum {|m| m.team_kills}
    @time_survived_avg  = ((participants.sum {|m| m.time_survived}).to_f/self.player_count.to_f).to_i
    @vehicle_destroys   = @participants.sum {|m| m.vehicle_destroys}
    @walk_distance_avg  = ((participants.sum {|m| m.walk_distance}).to_f/self.player_count.to_f).to_i
    @weapons_acquired   = @participants.sum {|m| m.weapons_acquired}
  end
end

Instance Attribute Details

#assistsObject (readonly)

Returns the value of attribute assists.



3
4
5
# File 'lib/rubg/match.rb', line 3

def assists
  @assists
end

#boostsObject (readonly)

Returns the value of attribute boosts.



3
4
5
# File 'lib/rubg/match.rb', line 3

def boosts
  @boosts
end

#createdObject (readonly)

Returns the value of attribute created.



3
4
5
# File 'lib/rubg/match.rb', line 3

def created
  @created
end

#damage_dealtObject (readonly)

Returns the value of attribute damage_dealt.



3
4
5
# File 'lib/rubg/match.rb', line 3

def damage_dealt
  @damage_dealt
end

#damage_dealt_avgObject (readonly)

Returns the value of attribute damage_dealt_avg.



3
4
5
# File 'lib/rubg/match.rb', line 3

def damage_dealt_avg
  @damage_dealt_avg
end

#dbnosObject (readonly)

Returns the value of attribute dbnos.



3
4
5
# File 'lib/rubg/match.rb', line 3

def dbnos
  @dbnos
end

#death_typesObject (readonly)

Returns the value of attribute death_types.



3
4
5
# File 'lib/rubg/match.rb', line 3

def death_types
  @death_types
end

#durationObject (readonly)

Returns the value of attribute duration.



3
4
5
# File 'lib/rubg/match.rb', line 3

def duration
  @duration
end

#headshot_killsObject (readonly)

Returns the value of attribute headshot_kills.



3
4
5
# File 'lib/rubg/match.rb', line 3

def headshot_kills
  @headshot_kills
end

#healsObject (readonly)

Returns the value of attribute heals.



3
4
5
# File 'lib/rubg/match.rb', line 3

def heals
  @heals
end

#killsObject (readonly)

Returns the value of attribute kills.



3
4
5
# File 'lib/rubg/match.rb', line 3

def kills
  @kills
end

Returns the value of attribute link.



3
4
5
# File 'lib/rubg/match.rb', line 3

def link
  @link
end

#mapObject (readonly)

Returns the value of attribute map.



3
4
5
# File 'lib/rubg/match.rb', line 3

def map
  @map
end

#match_idObject (readonly)

Returns the value of attribute match_id.



3
4
5
# File 'lib/rubg/match.rb', line 3

def match_id
  @match_id
end

#modeObject (readonly)

Returns the value of attribute mode.



3
4
5
# File 'lib/rubg/match.rb', line 3

def mode
  @mode
end

#namesObject (readonly)

Returns the value of attribute names.



3
4
5
# File 'lib/rubg/match.rb', line 3

def names
  @names
end

#participantsObject

Returns the value of attribute participants.



10
11
12
# File 'lib/rubg/match.rb', line 10

def participants
  @participants
end

#patch_versionObject (readonly)

Returns the value of attribute patch_version.



3
4
5
# File 'lib/rubg/match.rb', line 3

def patch_version
  @patch_version
end

#player_countObject (readonly)

Returns the value of attribute player_count.



3
4
5
# File 'lib/rubg/match.rb', line 3

def player_count
  @player_count
end

#revivesObject (readonly)

Returns the value of attribute revives.



3
4
5
# File 'lib/rubg/match.rb', line 3

def revives
  @revives
end

#ride_distance_avgObject (readonly)

Returns the value of attribute ride_distance_avg.



3
4
5
# File 'lib/rubg/match.rb', line 3

def ride_distance_avg
  @ride_distance_avg
end

#road_killsObject (readonly)

Returns the value of attribute road_kills.



3
4
5
# File 'lib/rubg/match.rb', line 3

def road_kills
  @road_kills
end

#roster_countObject (readonly)

Returns the value of attribute roster_count.



3
4
5
# File 'lib/rubg/match.rb', line 3

def roster_count
  @roster_count
end

#rostersObject

Returns the value of attribute rosters.



10
11
12
# File 'lib/rubg/match.rb', line 10

def rosters
  @rosters
end

#roundsObject (readonly)

Returns the value of attribute rounds.



3
4
5
# File 'lib/rubg/match.rb', line 3

def rounds
  @rounds
end

#shardObject (readonly)

Returns the value of attribute shard.



3
4
5
# File 'lib/rubg/match.rb', line 3

def shard
  @shard
end

#spectatorsObject (readonly)

Returns the value of attribute spectators.



3
4
5
# File 'lib/rubg/match.rb', line 3

def spectators
  @spectators
end

#statsObject (readonly)

Returns the value of attribute stats.



3
4
5
# File 'lib/rubg/match.rb', line 3

def stats
  @stats
end

#survivedObject (readonly)

Returns the value of attribute survived.



3
4
5
# File 'lib/rubg/match.rb', line 3

def survived
  @survived
end

#tagsObject (readonly)

Returns the value of attribute tags.



3
4
5
# File 'lib/rubg/match.rb', line 3

def tags
  @tags
end

#team_killsObject (readonly)

Returns the value of attribute team_kills.



3
4
5
# File 'lib/rubg/match.rb', line 3

def team_kills
  @team_kills
end

#telemetry_idObject (readonly)

Returns the value of attribute telemetry_id.



3
4
5
# File 'lib/rubg/match.rb', line 3

def telemetry_id
  @telemetry_id
end

Returns the value of attribute telemetry_link.



3
4
5
# File 'lib/rubg/match.rb', line 3

def telemetry_link
  @telemetry_link
end

#time_survived_avgObject (readonly)

Returns the value of attribute time_survived_avg.



3
4
5
# File 'lib/rubg/match.rb', line 3

def time_survived_avg
  @time_survived_avg
end

#title_idObject (readonly)

Returns the value of attribute title_id.



3
4
5
# File 'lib/rubg/match.rb', line 3

def title_id
  @title_id
end

#vehicle_destroysObject (readonly)

Returns the value of attribute vehicle_destroys.



3
4
5
# File 'lib/rubg/match.rb', line 3

def vehicle_destroys
  @vehicle_destroys
end

#walk_distance_avgObject (readonly)

Returns the value of attribute walk_distance_avg.



3
4
5
# File 'lib/rubg/match.rb', line 3

def walk_distance_avg
  @walk_distance_avg
end

#weapons_acquiredObject (readonly)

Returns the value of attribute weapons_acquired.



3
4
5
# File 'lib/rubg/match.rb', line 3

def weapons_acquired
  @weapons_acquired
end

#winnersObject (readonly) Also known as: winner

Returns the value of attribute winners.



3
4
5
# File 'lib/rubg/match.rb', line 3

def winners
  @winners
end

Class Method Details

.fetch(args) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rubg/match.rb', line 68

def self.fetch( args )
  args                  = self.defaults.merge(args)

  endpoint = "match"
  
  match_id = args[:query_params][:match_id]
  args[:query_params].delete(:match_id)

  super({
    :client         => args[:client],
    :endpoint       => endpoint,
    :lookup_id      => match_id,
    :shard          => args[:shard],
    :query_params   => args[:query_params]
    })
  
  match_data      = @response["data"]
  match_included  = @response["included"] 
  
  RUBG::Match.new({
    :client         => args[:client],
    :response       => @response,
    :match_data     => match_data,
    :match_included => match_included
    })
end