tictactoe_j8th 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66d20ba2e1cacc30029cc615d91958fc24a1ced6
4
- data.tar.gz: c123145b5bc58bf774032b247aa37bd7d03f7ac4
3
+ metadata.gz: 9eba6487c8c021ba766d97f1fd3ae0a33f4a5205
4
+ data.tar.gz: b5c9588eaf83b893ddbc9bb1ad139514a5f0c38a
5
5
  SHA512:
6
- metadata.gz: c6ebd647c5a33b7190c95476a08b2d3a0b8a4cc295a595c44db7c0d85cfe72aa5b88c63dc1571e46461bc14f58003970bbeaab03a4dee74ae7aba0bec022447b
7
- data.tar.gz: b4ef4f7a71cc547795842f883d8ce665ea73ac38f312e4b2d5a2a775ff948d952788eed9e0569a37d77617c87d9a8074832085d0a8fd8bf30ab989d9cdbdd800
6
+ metadata.gz: 0dfb68103ca67e6102885b021ba67782318ccc367818978bb3bae88c9f2dd265a6fd71bdf580ba5dca7d164fc5ea1bbbeca4ffbccba393ea541b2596adb66ff5
7
+ data.tar.gz: c13e7a4923c28970eec11901a7a5a5b6028e358b1508dd8e5fdc940e99e1425af38a83cae958f29944470bf6c3bec27dd5b97121deef3f5808211bcc8ed7ab2c
@@ -57,6 +57,25 @@ module TictactoeJ8th
57
57
  copy
58
58
  end
59
59
 
60
+ def to_s
61
+ string = ''
62
+ board.each do |spot|
63
+ string += spot.nil? ? 'E' : spot.to_s
64
+ end
65
+ string
66
+ end
67
+
68
+ ###############################
69
+ # Public Class Methods
70
+ ###############################
71
+ def self.from_s(string)
72
+ board = Board.new
73
+ (0..BOARD_SIZE-1).each do |i|
74
+ board.place(string[i].to_sym, i)
75
+ end
76
+ board
77
+ end
78
+
60
79
  private
61
80
  attr_accessor :board
62
81
  end
@@ -1,3 +1,3 @@
1
1
  module TictactoeJ8th
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/spec/board_spec.rb CHANGED
@@ -82,4 +82,24 @@ describe Board do
82
82
  )
83
83
  end
84
84
  end
85
+
86
+ context '#to_s' do
87
+ it 'returns a string representation of the board.' do
88
+ board.place(:X, 0)
89
+ board.place(:O, 3)
90
+ board.place(:X, 2)
91
+
92
+ expect(board.to_s).to eq('XEXOEEEEE')
93
+ end
94
+ end
95
+
96
+ context '#from_s' do
97
+ it 'returns a board from a string' do
98
+ string = 'XEXOEEEEE'
99
+ board = Board::from_s(string)
100
+ (0..Board::BOARD_SIZE-1).each do |i|
101
+ expect(board[i].to_s).to eq(string[i])
102
+ end
103
+ end
104
+ end
85
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tictactoe_j8th
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - j8th