Class: RUBG::Roster

Inherits:
Object
  • Object
show all
Defined in:
lib/rubg/roster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Roster

Returns a new instance of Roster.



12
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
# File 'lib/rubg/roster.rb', line 12

def initialize( args )

  if args[:roster_hash]
    @roster_id        = args[:roster_hash]["id"]
    @shard            = args[:roster_hash]["attributes"]["shardId"]
    @team_id          = args[:roster_hash]["attributes"]["stats"]["teamId"]
    @team             = args[:roster_hash]["relationships"]["team"]["data"]
    @rank             = args[:roster_hash]["attributes"]["stats"]["rank"]
    @won              = args[:roster_hash]["attributes"]["won"] == "true" ? true : false
    @participants     = []
    generate_participant_objects(args[:participant_array])
    @size             = @participants.count

    #aggregate roster stats
    @names              = @participants.collect(&:name)
    @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.size.to_f).to_i
    @death_types        = @participants.collect(&:death_type)
    @headshot_kills     = @participants.sum {|m| m.headshot_kills}
    @heals              = @participants.sum {|m| m.heals}
    @kills              = @participants.sum {|m| m.kills}
    @ride_distance      = @participants.sum {|m| m.ride_distance}
    @ride_distance_avg  = ((participants.sum {|m| m.ride_distance}).to_f/self.size.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      = @participants.sum {|m| m.time_survived}
    @time_survived_avg  = ((participants.sum {|m| m.time_survived}).to_f/self.size.to_f).to_i
    @vehicle_destroys   = @participants.sum {|m| m.vehicle_destroys}
    @walk_distance      = @participants.sum {|m| m.walk_distance}
    @walk_distance_avg  = ((participants.sum {|m| m.walk_distance}).to_f/self.size.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/roster.rb', line 3

def assists
  @assists
end

#boostsObject (readonly)

Returns the value of attribute boosts.



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

def boosts
  @boosts
end

#damage_dealtObject (readonly)

Returns the value of attribute damage_dealt.



3
4
5
# File 'lib/rubg/roster.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/roster.rb', line 3

def damage_dealt_avg
  @damage_dealt_avg
end

#dbnosObject (readonly) Also known as: knocks

Returns the value of attribute dbnos.



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

def dbnos
  @dbnos
end

#death_typesObject (readonly)

Returns the value of attribute death_types.



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

def death_types
  @death_types
end

#headshot_killsObject (readonly)

Returns the value of attribute headshot_kills.



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

def headshot_kills
  @headshot_kills
end

#healsObject (readonly)

Returns the value of attribute heals.



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

def heals
  @heals
end

#killsObject (readonly)

Returns the value of attribute kills.



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

def kills
  @kills
end

#namesObject (readonly)

Returns the value of attribute names.



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

def names
  @names
end

#participant_idsObject (readonly)

Returns the value of attribute participant_ids.



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

def participant_ids
  @participant_ids
end

#participantsObject

Returns the value of attribute participants.



8
9
10
# File 'lib/rubg/roster.rb', line 8

def participants
  @participants
end

#rankObject (readonly)

Returns the value of attribute rank.



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

def rank
  @rank
end

#revivesObject (readonly)

Returns the value of attribute revives.



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

def revives
  @revives
end

#ride_distanceObject (readonly)

Returns the value of attribute ride_distance.



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

def ride_distance
  @ride_distance
end

#ride_distance_avgObject (readonly)

Returns the value of attribute ride_distance_avg.



3
4
5
# File 'lib/rubg/roster.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/roster.rb', line 3

def road_kills
  @road_kills
end

#roster_idObject (readonly)

Returns the value of attribute roster_id.



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

def roster_id
  @roster_id
end

#shardObject (readonly)

Returns the value of attribute shard.



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

def shard
  @shard
end

#sizeObject (readonly) Also known as: player_count

Returns the value of attribute size.



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

def size
  @size
end

#survivedObject (readonly)

Returns the value of attribute survived.



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

def survived
  @survived
end

#teamObject (readonly)

Returns the value of attribute team.



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

def team
  @team
end

#team_idObject (readonly)

Returns the value of attribute team_id.



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

def team_id
  @team_id
end

#team_killsObject (readonly)

Returns the value of attribute team_kills.



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

def team_kills
  @team_kills
end

#time_survivedObject (readonly)

Returns the value of attribute time_survived.



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

def time_survived
  @time_survived
end

#time_survived_avgObject (readonly)

Returns the value of attribute time_survived_avg.



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

def time_survived_avg
  @time_survived_avg
end

#vehicle_destroysObject (readonly)

Returns the value of attribute vehicle_destroys.



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

def vehicle_destroys
  @vehicle_destroys
end

#walk_distanceObject (readonly)

Returns the value of attribute walk_distance.



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

def walk_distance
  @walk_distance
end

#walk_distance_avgObject (readonly)

Returns the value of attribute walk_distance_avg.



3
4
5
# File 'lib/rubg/roster.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/roster.rb', line 3

def weapons_acquired
  @weapons_acquired
end

#wonObject (readonly)

Returns the value of attribute won.



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

def won
  @won
end

Instance Method Details

#won?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/rubg/roster.rb', line 52

def won?
  @won
end