Sha256: b4b254987fde14b9730501478c149dba15fab4a81a625d99d029aa85d728adf8

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require 'json'

module Battlesnake
  ##
  # Represents a Battlesnake game.
  class Game < Base
    # @return [Hash] snake as a data structure usable by other objects.
    attr_reader :as_json

    # @return [String] unique identifier for this game.
    attr_reader :id

    # @return [Hash] information about the ruleset being used to run this game.
    attr_reader :ruleset

    # @return [String] name of the map used to populate the game board with snakes, food, and hazards.
    attr_reader :map

    # @return [Integer] how much time player APIs have to respond to requests for this game.
    attr_reader :timeout

    # @return [String] source of this game.
    attr_reader :source

    ##
    # Returns a new instance of Game.
    #
    # @param json_or_hash [String,Hash] can be a hash of attributes, or a JSON string which
    #   represents such a structure.
    #
    # @return [Game]
    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
battlesnake-0.1.7 lib/battlesnake/game.rb
battlesnake-0.1.5 lib/battlesnake/game.rb
battlesnake-0.1.4 lib/battlesnake/game.rb
battlesnake-0.1.3 lib/battlesnake/game.rb
battlesnake-0.1.2 lib/battlesnake/game.rb