sashite-cell 2.0.0 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4fefcdbade2adc694035b6fbff032fb8e03466e35406a67f2a9d1c61b9fd600
4
- data.tar.gz: 42c3150a201310805948eaa2e9e6bf05fc9c198925024d7a203f0093d6ee969a
3
+ metadata.gz: 2bd53ed1ca6d52f558a3b84a2ab3b4d8b169c0bdc957bc6cc2b4b3f52d52df11
4
+ data.tar.gz: 3174e1859f910636c3c66732beb1b75c3ea4930a35fd609a0fd914947ab6c69e
5
5
  SHA512:
6
- metadata.gz: 185910faaa10494b20d39b58ac3f25007d432d63d230de76cf666762a215ab8177283c0fe167efc28fdc24b4abcc55bdb25211fc9d216856b62d889005e57c8c
7
- data.tar.gz: 43fe0766f8fe932e2a57dec85c89a07db4f30a543319f035b7e893a8122cfaf30ed90a635515bb9867a1509dc9e374ecf3c0b16c6efb39b419413a4811aebfe2
6
+ metadata.gz: d709b3784aa4250a0e237047d9b8cee21ad330f23b18bc364f9ddde43d58200695ae5e2ea1456cb7d722c896e7f4d200066410276b9c13f7dbad40c18308752d
7
+ data.tar.gz: bc3f86c59a69f42581b5c8cbfed3823a62649ae4898cfb1447c9657c9bd8e4d38722571face0df3c05a5f021e3c1641d8b32db41bd088ee7421370a4a2eeb76a
data/README.md CHANGED
@@ -5,13 +5,13 @@
5
5
  ![Ruby](https://github.com/sashite/cell.rb/actions/workflows/main.yml/badge.svg?branch=main)
6
6
  [![License](https://img.shields.io/github/license/sashite/cell.rb?label=License&logo=github)](https://github.com/sashite/cell.rb/raw/main/LICENSE.md)
7
7
 
8
- > **CELL** (Cell Encoding Location Label) support for the Ruby language.
8
+ > **CELL** (Coordinate Encoding for Layered Locations) support for the Ruby language.
9
9
 
10
10
  ## What is CELL?
11
11
 
12
- CELL (Cell Encoding Location Label) is a standardized format for representing coordinates on multi-dimensional game boards using a cyclical ASCII character system. CELL supports unlimited dimensional coordinate systems through the systematic repetition of three distinct character sets.
12
+ CELL (Coordinate Encoding for Layered Locations) is a standardized format for representing coordinates on multi-dimensional game boards using a cyclical ASCII character system. CELL supports unlimited dimensional coordinate systems through the systematic repetition of three distinct character sets.
13
13
 
14
- This gem implements the [CELL Specification v1.0.0](https://sashite.dev/documents/cell/1.0.0/), providing a Ruby interface for working with multi-dimensional game coordinates through a clean, functional API.
14
+ This gem implements the [CELL Specification v1.0.0](https://sashite.dev/specs/cell/1.0.0/), providing a Ruby interface for working with multi-dimensional game coordinates through a clean, functional API.
15
15
 
16
16
  ## Installation
17
17
 
@@ -125,14 +125,16 @@ chess_squares.all? { |square| Sashite::Cell.valid?(square) }
125
125
  # => true
126
126
  ```
127
127
 
128
- ### Shogi Board (9x9)
128
+ ### Shōgi Board (9x9)
129
129
 
130
130
  ```ruby
131
- # Japanese shogi uses 9x9 board
132
- shogi_position = "5e" # 5th file, e rank
133
- Sashite::Cell.valid?(shogi_position) # => true
134
- Sashite::Cell.dimensions(shogi_position) # => 2
135
- Sashite::Cell.to_indices(shogi_position) # => [4, 4]
131
+ # CELL coordinates for shōgi positions
132
+ shogi_positions = %w[a1 e5 i9] # Left corner, center, right corner
133
+ shogi_positions.all? { |pos| Sashite::Cell.valid?(pos) }
134
+ # => true
135
+
136
+ # Convert to indices for board representation
137
+ Sashite::Cell.to_indices("e5") # => [4, 4] (center of 9x9 board)
136
138
  ```
137
139
 
138
140
  ### 3D Tic-Tac-Toe (3x3x3)
@@ -142,6 +144,11 @@ Sashite::Cell.to_indices(shogi_position) # => [4, 4]
142
144
  positions_3d = %w[a1A b2B c3C a2B b3C c1A]
143
145
  positions_3d.all? { |pos| Sashite::Cell.valid?(pos) && Sashite::Cell.dimensions(pos) == 3 }
144
146
  # => true
147
+
148
+ # Winning diagonal across all three dimensions
149
+ diagonal_win = %w[a1A b2B c3C]
150
+ diagonal_win.map { |pos| Sashite::Cell.to_indices(pos) }
151
+ # => [[0,0,0], [1,1,1], [2,2,2]]
145
152
  ```
146
153
 
147
154
  ### Multi-dimensional Coordinates
@@ -179,7 +186,7 @@ Sashite::Cell.parse(coord_5d) # => ["b", "2", "B", "b", "2"]
179
186
 
180
187
  ### Constants
181
188
 
182
- - `Sashite::Cell::REGEX` - Regular expression for CELL validation: `/\A(?:[a-z]+|[1-9]\d*|[A-Z]+)+\z/`
189
+ - `Sashite::Cell::REGEX` - Regular expression for CELL validation per specification v1.0.0
183
190
 
184
191
  ## Properties of CELL
185
192
 
@@ -188,7 +195,7 @@ Sashite::Cell.parse(coord_5d) # => ["b", "2", "B", "b", "2"]
188
195
  * **ASCII-based**: Pure ASCII characters for universal compatibility
189
196
  * **Unambiguous**: Each coordinate maps to exactly one location
190
197
  * **Scalable**: Extends naturally from 1D to unlimited dimensions
191
- * **Functional**: Provides a clean, stateless API for coordinate operations
198
+ * **Rule-agnostic**: Independent of specific game mechanics
192
199
 
193
200
  ## Character Set Details
194
201
 
@@ -234,6 +241,9 @@ end_position = "e4"
234
241
 
235
242
  Sashite::Cell.valid?(start_position) # => true
236
243
  Sashite::Cell.valid?(end_position) # => true
244
+
245
+ # Convert to array indices for board representation
246
+ Sashite::Cell.to_indices("e4") # => [4, 3]
237
247
  ```
238
248
 
239
249
  ### Go (19x19)
@@ -258,17 +268,80 @@ tesseract_pos = "h8Hh8"
258
268
  # Validate high-dimensional coordinates
259
269
  Sashite::Cell.valid?(hypercube_4d) # => true
260
270
  Sashite::Cell.dimensions(tesseract_pos) # => 5
271
+
272
+ # Convert for mathematical operations
273
+ Sashite::Cell.to_indices(hypercube_4d) # => [0, 0, 0, 0]
274
+ ```
275
+
276
+ ## Specification Compliance
277
+
278
+ This implementation strictly follows the [CELL Specification v1.0.0](https://sashite.dev/specs/cell/1.0.0/) and includes:
279
+
280
+ - **Exact regex**: Uses the official validation pattern from the specification
281
+ - **Complete API**: All methods and behaviors defined in the specification
282
+ - **Full test coverage**: Validates against all specification examples
283
+ - **Round-trip safety**: Guaranteed coordinate ↔ indices conversion integrity
284
+
285
+ ### Specification Examples
286
+
287
+ All examples from the CELL specification work correctly:
288
+
289
+ ```ruby
290
+ # Basic Examples from spec
291
+ Sashite::Cell.valid?("a") # => true (1D)
292
+ Sashite::Cell.valid?("a1") # => true (2D)
293
+ Sashite::Cell.valid?("a1A") # => true (3D)
294
+ Sashite::Cell.valid?("a1Aa1A") # => true (6D)
295
+
296
+ # Extended Alphabet Examples from spec
297
+ Sashite::Cell.valid?("aa1AA") # => true
298
+ Sashite::Cell.valid?("z26Z") # => true
299
+ Sashite::Cell.valid?("abc123XYZ") # => true
300
+
301
+ # Invalid Examples from spec
302
+ Sashite::Cell.valid?("") # => false
303
+ Sashite::Cell.valid?("a0") # => false
304
+ Sashite::Cell.valid?("1a") # => false
305
+ Sashite::Cell.valid?("a1a") # => false
261
306
  ```
262
307
 
263
308
  ## Documentation
264
309
 
265
- - [Official CELL Specification](https://sashite.dev/documents/cell/1.0.0/)
310
+ - [Official CELL Specification v1.0.0](https://sashite.dev/specs/cell/1.0.0/)
266
311
  - [API Documentation](https://rubydoc.info/github/sashite/cell.rb/main)
312
+ - [CELL Examples](https://sashite.dev/specs/cell/1.0.0/examples/)
313
+
314
+ ## Development
315
+
316
+ ```sh
317
+ # Clone the repository
318
+ git clone https://github.com/sashite/cell.rb.git
319
+ cd cell.rb
320
+
321
+ # Install dependencies
322
+ bundle install
323
+
324
+ # Run tests
325
+ ruby test.rb
326
+
327
+ # Generate documentation
328
+ yard doc
329
+ ```
330
+
331
+ ## Contributing
332
+
333
+ 1. Fork the repository
334
+ 2. Create a feature branch (`git checkout -b feature/new-feature`)
335
+ 3. Add tests for your changes
336
+ 4. Ensure all tests pass (`ruby test.rb`)
337
+ 5. Commit your changes (`git commit -am 'Add new feature'`)
338
+ 6. Push to the branch (`git push origin feature/new-feature`)
339
+ 7. Create a Pull Request
267
340
 
268
341
  ## License
269
342
 
270
- The [gem](https://rubygems.org/gems/sashite-cell) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
343
+ Available as open source under the [MIT License](https://opensource.org/licenses/MIT).
271
344
 
272
- ## About Sashité
345
+ ## About
273
346
 
274
- This project is maintained by [Sashité](https://sashite.com/) — promoting chess variants and sharing the beauty of Chinese, Japanese, and Western chess cultures.
347
+ Maintained by [Sashité](https://sashite.com/) — promoting chess variants and sharing the beauty of board game cultures.
data/lib/sashite/cell.rb CHANGED
@@ -1,20 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sashite
4
- # CELL (Cell Encoding Location Label) implementation for Ruby
4
+ # CELL (Coordinate Encoding for Layered Locations) implementation for Ruby
5
5
  #
6
6
  # Provides functionality for working with multi-dimensional game board coordinates
7
7
  # using a cyclical ASCII character system.
8
8
  #
9
- # @see https://sashite.dev/documents/cell/1.0.0/ CELL Specification v1.0.0
9
+ # This implementation is strictly compliant with CELL Specification v1.0.0
10
+ # @see https://sashite.dev/specs/cell/1.0.0/ CELL Specification v1.0.0
10
11
  module Cell
11
- # Regular expression for validating CELL coordinates according to specification
12
- # This is the exact regex from the CELL specification v1.0.0
13
- # Using non-capturing groups to avoid Ruby's nested quantifier warning
14
- REGEX = /\A[a-z]+(?:[1-9]\d*[A-Z]+[a-z]+)*(?:[1-9]\d*(?:[A-Z]*))?\z/
12
+ # Regular expression from CELL Specification v1.0.0
13
+ # Note: Line breaks must be rejected separately (see valid?)
14
+ REGEX = /^[a-z]+(?:[1-9][0-9]*[A-Z]+[a-z]+)*(?:[1-9][0-9]*[A-Z]*)?$/
15
15
 
16
16
  # Check if a string represents a valid CELL coordinate
17
17
  #
18
+ # Implements full-string matching as required by the CELL specification.
19
+ # Rejects any input containing line breaks (\r or \n).
20
+ #
18
21
  # @param string [String] the string to validate
19
22
  # @return [Boolean] true if the string is a valid CELL coordinate
20
23
  #
@@ -23,11 +26,12 @@ module Sashite
23
26
  # Sashite::Cell.valid?("a1A") # => true
24
27
  # Sashite::Cell.valid?("*") # => false
25
28
  # Sashite::Cell.valid?("a0") # => false
29
+ # Sashite::Cell.valid?("a1\n") # => false
26
30
  def self.valid?(string)
27
31
  return false unless string.is_a?(String)
28
32
  return false if string.empty?
33
+ return false if string.include?("\r") || string.include?("\n")
29
34
 
30
- # Use the formal regex for validation
31
35
  string.match?(REGEX)
32
36
  end
33
37
 
@@ -104,13 +108,17 @@ module Sashite
104
108
 
105
109
  # Get the validation regular expression
106
110
  #
107
- # @return [Regexp] the CELL validation regex
111
+ # Note: This regex alone does not guarantee full compliance. The valid?
112
+ # method additionally rejects strings containing line breaks, as required
113
+ # by the specification's anchoring requirements.
114
+ #
115
+ # @return [Regexp] the CELL validation regex from specification v1.0.0
108
116
  def self.regex
109
117
  REGEX
110
118
  end
111
119
 
112
120
  # Recursively parse a coordinate string into components
113
- # following the strict CELL specification pattern
121
+ # following the strict CELL specification cyclical pattern
114
122
  #
115
123
  # @param string [String] the remaining string to parse
116
124
  # @param dimension [Integer] the current dimension (1-indexed)
@@ -123,23 +131,21 @@ module Sashite
123
131
 
124
132
  return [] if component.nil?
125
133
 
126
- # Invalid format according to CELL specification
127
-
128
134
  # Extract component and recursively parse the rest
129
135
  remaining = string[component.length..]
130
136
  [component] + parse_recursive(remaining, dimension + 1)
131
137
  end
132
138
 
133
139
  # Determine the character set type for a given dimension
134
- # Following CELL specification: dimension n % 3 determines character set
140
+ # Following CELL specification cyclical system: dimension n % 3 determines character set
135
141
  #
136
142
  # @param dimension [Integer] the dimension number (1-indexed)
137
143
  # @return [Symbol] :lowercase, :numeric, or :uppercase
138
144
  def self.dimension_type(dimension)
139
145
  case dimension % 3
140
- when 1 then :lowercase
141
- when 2 then :numeric
142
- when 0 then :uppercase
146
+ when 1 then :lowercase # n % 3 = 1: Latin lowercase letters
147
+ when 2 then :numeric # n % 3 = 2: Arabic numerals
148
+ when 0 then :uppercase # n % 3 = 0: Latin uppercase letters
143
149
  end
144
150
  end
145
151
 
@@ -152,14 +158,16 @@ module Sashite
152
158
  def self.extract_component(string, type)
153
159
  case type
154
160
  when :lowercase
155
- match = string.match(/\A([a-z]+)/)
161
+ # Latin lowercase letters: [a-z]+
162
+ match = string.match(/^([a-z]+)/)
156
163
  match ? match[1] : nil
157
164
  when :numeric
158
- # CELL specification requires positive integers only (no zero)
159
- match = string.match(/\A([1-9]\d*)/)
165
+ # Arabic numerals: [1-9][0-9]* (CELL specification requires positive integers only)
166
+ match = string.match(/^([1-9][0-9]*)/)
160
167
  match ? match[1] : nil
161
168
  when :uppercase
162
- match = string.match(/\A([A-Z]+)/)
169
+ # Latin uppercase letters: [A-Z]+
170
+ match = string.match(/^([A-Z]+)/)
163
171
  match ? match[1] : nil
164
172
  end
165
173
  end
@@ -197,7 +205,7 @@ module Sashite
197
205
  end
198
206
 
199
207
  # Convert letter sequence to 0-indexed position
200
- # Extended alphabet: a=0, b=1, ..., z=25, aa=26, ab=27, ..., zz=701, aaa=702, etc.
208
+ # Extended alphabet per CELL specification: a=0, b=1, ..., z=25, aa=26, ab=27, ..., zz=701, aaa=702, etc.
201
209
  #
202
210
  # @param letters [String] the letter sequence
203
211
  # @return [Integer] the 0-indexed position
@@ -219,7 +227,7 @@ module Sashite
219
227
  end
220
228
 
221
229
  # Convert 0-indexed position to letter sequence
222
- # Extended alphabet: 0=a, 1=b, ..., 25=z, 26=aa, 27=ab, ..., 701=zz, 702=aaa, etc.
230
+ # Extended alphabet per CELL specification: 0=a, 1=b, ..., 25=z, 26=aa, 27=ab, ..., 701=zz, 702=aaa, etc.
223
231
  #
224
232
  # @param index [Integer] the 0-indexed position
225
233
  # @return [String] the letter sequence
@@ -248,5 +256,9 @@ module Sashite
248
256
 
249
257
  result
250
258
  end
259
+
260
+ private_class_method :parse_recursive, :dimension_type, :extract_component
261
+ private_class_method :component_to_index, :index_to_component
262
+ private_class_method :letters_to_index, :index_to_letters
251
263
  end
252
264
  end
data/lib/sashite-cell.rb CHANGED
@@ -1,8 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "sashite/cell"
4
+
3
5
  # Sashité namespace for board game notation libraries
6
+ #
7
+ # Sashité provides a collection of libraries for representing and manipulating
8
+ # board game concepts according to the Sashité Protocol specifications.
9
+ #
10
+ # @see https://sashite.dev/protocol/ Sashité Protocol
11
+ # @see https://sashite.dev/specs/ Sashité Specifications
12
+ # @author Sashité
4
13
  module Sashite
5
- # @see https://sashite.dev/documents/cell/1.0.0/ CELL Specification v1.0.0
6
14
  end
7
-
8
- require_relative "sashite/cell"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashite-cell
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
@@ -10,9 +10,9 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: CELL defines a standardized format for representing coordinates on multi-dimensional
13
- game boards using diverse writing systems from around the world. This gem provides
14
- a Ruby interface for working with multi-dimensional game coordinates through a clean,
15
- functional API.
13
+ game boards using a cyclical ASCII character system. This gem provides a Ruby interface
14
+ for working with unlimited dimensional game coordinates through a clean, functional
15
+ API that strictly follows the CELL Specification v1.0.0.
16
16
  email: contact@cyril.email
17
17
  executables: []
18
18
  extensions: []
@@ -30,7 +30,9 @@ metadata:
30
30
  documentation_uri: https://rubydoc.info/github/sashite/cell.rb/main
31
31
  homepage_uri: https://github.com/sashite/cell.rb
32
32
  source_code_uri: https://github.com/sashite/cell.rb
33
- specification_uri: https://sashite.dev/documents/cell/1.0.0/
33
+ specification_uri: https://sashite.dev/specs/cell/1.0.0/
34
+ wiki_uri: https://sashite.dev/specs/cell/1.0.0/examples/
35
+ funding_uri: https://github.com/sponsors/sashite
34
36
  rubygems_mfa_required: 'true'
35
37
  rdoc_options: []
36
38
  require_paths:
@@ -46,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
48
  - !ruby/object:Gem::Version
47
49
  version: '0'
48
50
  requirements: []
49
- rubygems_version: 3.6.9
51
+ rubygems_version: 3.7.2
50
52
  specification_version: 4
51
- summary: CELL (Cell Encoding Location Label) implementation for Ruby
53
+ summary: CELL (Coordinate Encoding for Layered Locations) implementation for Ruby
52
54
  test_files: []