Class: Battlesnake::Game

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

Overview

Represents a Battlesnake game.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==

Constructor Details

#initialize(json_or_hash) ⇒ Game

Returns a new instance of Game.

Parameters:

  • json_or_hash (String, Hash) —

    can be a hash of attributes, or a JSON string which represents such a structure.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/battlesnake/game.rb', line 32

def initialize(json_or_hash)
  data = json_or_hash.is_a?(String) ? JSON.parse(json_or_hash) : json_or_hash

  @as_json = data

  @id = data['id']
  @ruleset = data['ruleset']
  @map = data['map']
  @timeout = data['timeout']
  @source = data['source']
end

Instance Attribute Details

#as_json ⇒ Hash (readonly)

Returns snake as a data structure usable by other objects.

Returns:

  • (Hash) —

    snake as a data structure usable by other objects.



8
9
10
# File 'lib/battlesnake/game.rb', line 8

def as_json
  @as_json
end

#id ⇒ String (readonly)

Returns unique identifier for this game.

Returns:

  • (String) —

    unique identifier for this game.



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

def id
  @id
end

#map ⇒ String (readonly)

Returns name of the map used to populate the game board with snakes, food, and hazards.

Returns:

  • (String) —

    name of the map used to populate the game board with snakes, food, and hazards.



17
18
19
# File 'lib/battlesnake/game.rb', line 17

def map
  @map
end

#ruleset ⇒ Hash (readonly)

Returns information about the ruleset being used to run this game.

Returns:

  • (Hash) —

    information about the ruleset being used to run this game.



14
15
16
# File 'lib/battlesnake/game.rb', line 14

def ruleset
  @ruleset
end

#source ⇒ String (readonly)

Returns source of this game.

Returns:

  • (String) —

    source of this game.



23
24
25
# File 'lib/battlesnake/game.rb', line 23

def source
  @source
end

#timeout ⇒ Integer (readonly)

Returns how much time player APIs have to respond to requests for this game.

Returns:

  • (Integer) —

    how much time player APIs have to respond to requests for this game.



20
21
22
# File 'lib/battlesnake/game.rb', line 20

def timeout
  @timeout
end