class Quaker3::Game
Represents the Game
model extract from Quake 3 Arena log file @author Renan Gigliotti
Constants
- KILLER_WORLD
Attributes
id[RW]
kills[RW]
Public Class Methods
new()
click to toggle source
# File lib/quaker3/game.rb, line 11 def initialize @kills = [] end
Public Instance Methods
to_h()
click to toggle source
Generate a hash that represent’s a Game
model @return [Hash] from game
# File lib/quaker3/game.rb, line 17 def to_h { 'id' => @id, 'total_kills' => @kills.length, 'kills' => @kills.map(&:to_h) } end
to_h_grouped()
click to toggle source
Generate a hash that represent’s a Game
grouped statistics @return [Hash] from game grouped statistics
# 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_mode()
click to toggle source
Generate a hash that represent’s a Game
grouped by kill mode @return [Hash] from game grouped by kill mode
# File lib/quaker3/game.rb, line 38 def to_h_grouped_by_mode { 'id' => @id, 'total_kills' => @kills.length, 'modes' => modes } end
Private Instance Methods
kills_by_player(player)
click to toggle source
# File lib/quaker3/game.rb, line 72 def kills_by_player(player) kills.filter do |kill| kill.killer.eql?(player) && !kill.killer.eql?(kill.killed) end end
modes()
click to toggle source
# File lib/quaker3/game.rb, line 63 def modes @kills.map(&:mode).uniq.map do |mode| { 'mode' => mode, 'total_kills' => kills.filter { |kill| kill.mode.eql? mode }.length } end end
players()
click to toggle source
# File lib/quaker3/game.rb, line 48 def players (@kills.filter { |kill| kill.killer != KILLER_WORLD }.map(&:killer) + @kills.filter do |kill| kill.killed != KILLER_WORLD end.map(&:killed)).uniq end
score()
click to toggle source
# File lib/quaker3/game.rb, line 54 def score players.map do |player| { 'name' => player, 'score' => kills_by_player(player).map { |kill| kill.killer == KILLER_WORLD ? -1 : 1 }.sum } end end