battlesnake 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+
3
+ module Battlesnake
4
+ ##
5
+ # Represents a Battlesnake game.
6
+ class Game < Base
7
+ # @return [Hash] snake as a data structure usable by other objects.
8
+ attr_reader :as_json
9
+
10
+ # @return [String] unique identifier for this game.
11
+ attr_reader :id
12
+
13
+ # @return [Hash] information about the ruleset being used to run this game.
14
+ attr_reader :ruleset
15
+
16
+ # @return [String] name of the map used to populate the game board with snakes, food, and hazards.
17
+ attr_reader :map
18
+
19
+ # @return [Integer] how much time player APIs have to respond to requests for this game.
20
+ attr_reader :timeout
21
+
22
+ # @return [String] source of this game.
23
+ attr_reader :source
24
+
25
+ ##
26
+ # Returns a new instance of Game.
27
+ #
28
+ # @param json_or_hash [String,Hash] can be a hash of attributes, or a JSON string which
29
+ # represents such a structure.
30
+ #
31
+ # @return [Game]
32
+ def initialize(json_or_hash)
33
+ data = json_or_hash.is_a?(String) ? JSON.parse(json_or_hash) : json_or_hash
34
+
35
+ @as_json = data
36
+
37
+ @id = data['id']
38
+ @ruleset = data['ruleset']
39
+ @map = data['map']
40
+ @timeout = data['timeout']
41
+ @source = data['source']
42
+ end
43
+ end
44
+ end
@@ -4,7 +4,7 @@ module Battlesnake
4
4
  ##
5
5
  # Represents a pair of (x,y) coordinates, and provides helper methods
6
6
  # for managing distance and direction.
7
- class Location
7
+ class Location < Base
8
8
  # @return [Integer] a positive integer representing the distance from the
9
9
  # left side of the board.
10
10
  attr_reader :x
@@ -3,7 +3,7 @@ require 'json'
3
3
  module Battlesnake
4
4
  ##
5
5
  # Represents a single Battlesnake player.
6
- class Snake
6
+ class Snake < Base
7
7
  # @return [Hash] snake as a data structure usable by other objects.
8
8
  attr_reader :as_json
9
9
 
@@ -1,4 +1,4 @@
1
1
  module Battlesnake
2
2
  # The current version of the driver.
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.2"
4
4
  end
data/lib/battlesnake.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require "battlesnake/version"
2
+ require 'battlesnake/base'
3
+ require 'battlesnake/board'
4
+ require 'battlesnake/game'
2
5
  require 'battlesnake/location'
3
6
  require 'battlesnake/snake'
4
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: battlesnake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Bellmyer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-04 00:00:00.000000000 Z
11
+ date: 2022-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -100,7 +100,10 @@ files:
100
100
  - bin/console
101
101
  - bin/setup
102
102
  - docs/Battlesnake.html
103
+ - docs/Battlesnake/Base.html
104
+ - docs/Battlesnake/Board.html
103
105
  - docs/Battlesnake/Error.html
106
+ - docs/Battlesnake/Game.html
104
107
  - docs/Battlesnake/Location.html
105
108
  - docs/Battlesnake/Snake.html
106
109
  - docs/_index.html
@@ -118,6 +121,9 @@ files:
118
121
  - docs/method_list.html
119
122
  - docs/top-level-namespace.html
120
123
  - lib/battlesnake.rb
124
+ - lib/battlesnake/base.rb
125
+ - lib/battlesnake/board.rb
126
+ - lib/battlesnake/game.rb
121
127
  - lib/battlesnake/location.rb
122
128
  - lib/battlesnake/snake.rb
123
129
  - lib/battlesnake/version.rb