Class: Quaker3::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/quaker3/game.rb

Overview

Represents the Game model extract from Quake 3 Arena log file

Author:

  • Renan Gigliotti

Constant Summary collapse

KILLER_WORLD =
'<world>'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



11
12
13
# File 'lib/quaker3/game.rb', line 11

def initialize
  @kills = []
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/quaker3/game.rb', line 7

def id
  @id
end

#killsObject

Returns the value of attribute kills.



7
8
9
# File 'lib/quaker3/game.rb', line 7

def kills
  @kills
end

Instance Method Details

#to_hHash

Generate a hash that represent’s a Game model

Returns:

  • (Hash)

    from game



17
18
19
20
21
22
23
# File 'lib/quaker3/game.rb', line 17

def to_h
  {
    'id' => @id,
    'total_kills' => @kills.length,
    'kills' => @kills.map(&:to_h)
  }
end

#to_h_groupedHash

Generate a hash that represent’s a Game grouped statistics

Returns:

  • (Hash)

    from game grouped statistics



27
28
29
30
31
32
33
34
# File 'lib/quaker3/game.rb', line 27

def to_h_grouped
  {
    'id' => @id,
    'total_kills' => @kills.length,
    'players' => players,
    'score' => score.sort { |a, b| b[:score] <=> a[:score] }
  }
end

#to_h_grouped_by_modeHash

Generate a hash that represent’s a Game grouped by kill mode

Returns:

  • (Hash)

    from game grouped by kill mode



38
39
40
41
42
43
44
# File 'lib/quaker3/game.rb', line 38

def to_h_grouped_by_mode
  {
    'id' => @id,
    'total_kills' => @kills.length,
    'modes' => modes
  }
end