Class: LolReplay::Game

Inherits:
Object
  • Object
show all
Includes:
HashMethodAccessor
Defined in:
lib/lolreplay/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashMethodAccessor

#method_missing

Constructor Details

#initialize(path) ⇒ Game

Constructor takes a path to a .lrf file. The file path that it is given is read and the meta data is extracted for later use.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lolreplay/game.rb', line 11

def initialize path
  @path = path

  @data = File.open(path) do |f|
    f.read(4) # skip first four bytes
    size = f.read(4).unpack("L").first
    JSON.parse f.read(size), symbolize_names: true
  end

  @players = @data[:players].map { |p| Player.new p }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HashMethodAccessor

Instance Attribute Details

#jsonObject

Returns the value of attribute json.



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

def json
  @json
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#playersObject

Returns the value of attribute players.



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

def players
  @players
end

Instance Method Details

#player(name) ⇒ Object

Gets a player by name. If the player was not present in this game, nil is returned.

Example:

puts game.player "Samwho"
#=> #<LolReplay::Player:0x8317074>


30
31
32
33
34
35
36
# File 'lib/lolreplay/game.rb', line 30

def player name
  @players.each do |player|
    return player if player.name == name
  end

  nil
end