sashite-snn 3.0.0 → 4.0.0

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: 517b0310bd57b5d0b931a5f14eb1c4d6257bbd6d4f215c467ff475c8b42542fc
4
- data.tar.gz: 2fa5a177d6350dd2501b87eac5a567f5cf48c681439b3af23f2bae1df99579a3
3
+ metadata.gz: 4ac2f8ab9d58cfef67f10ed341bc46b3f811e68135a69d3bdbf7fe173b05a490
4
+ data.tar.gz: d59666f8d93c0c62662ca3b69efed7c766a4cf63bfe98120860abc5c0f0346c9
5
5
  SHA512:
6
- metadata.gz: 200ef38765b8c581f93c51657699e4b420c26abe1d355227ff47892b493f787ec9c03e7202a91b9466c99c97a95a1b914837e59bb2784ef6568cc2ca3f94dd49
7
- data.tar.gz: 6b01e73ad4e61246e8e61a4e0bd85f7b3f0fcb964f7532c42d6c95a2b5b665c64487e032e46cb7b77806b3a410137536812aac3278428b2c31af8d91811597ec
6
+ metadata.gz: ed7ee97498cff47f267672216daf578e0a92fbbbbb9693ecb4115f9a1ceabf0728128170a097d16a46b6a931d4cfa80121656f06024e0c9aebf666c8995fee1b
7
+ data.tar.gz: c5190b3f14919ad833288f05528a88bd9b5cb6e0de441da79f4db7507f541e01b5fd33d7c0d2fa853abf4b5890250ab50bc787a4a4aea0525109d9164db12d2d
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Cyril Kato
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -1,24 +1,30 @@
1
- # Snn.rb
1
+ # snn.rb
2
2
 
3
3
  [![Version](https://img.shields.io/github/v/tag/sashite/snn.rb?label=Version&logo=github)](https://github.com/sashite/snn.rb/tags)
4
4
  [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/sashite/snn.rb/main)
5
- ![Ruby](https://github.com/sashite/snn.rb/actions/workflows/main.yml/badge.svg?branch=main)
6
- [![License](https://img.shields.io/github/license/sashite/snn.rb?label=License&logo=github)](https://github.com/sashite/snn.rb/raw/main/LICENSE.md)
5
+ [![CI](https://github.com/sashite/snn.rb/actions/workflows/ruby.yml/badge.svg?branch=main)](https://github.com/sashite/snn.rb/actions)
6
+ [![License](https://img.shields.io/github/license/sashite/snn.rb)](https://github.com/sashite/snn.rb/blob/main/LICENSE)
7
7
 
8
- > **SNN** (Style Name Notation) implementation for the Ruby language.
8
+ > **SNN** (Style Name Notation) implementation for Ruby.
9
9
 
10
- ## What is SNN?
10
+ ## Overview
11
11
 
12
- SNN (Style Name Notation) is a formal, rule-agnostic naming system for identifying **styles** in abstract strategy board games such as chess, shōgi, xiangqi, and their many variants. Each style is represented by a canonical, human-readable ASCII name (e.g., `"Chess"`, `"Shogi"`, `"Xiangqi"`, `"Minishogi"`).
12
+ This library implements the [SNN Specification v1.0.0](https://sashite.dev/specs/snn/1.0.0/).
13
13
 
14
- This gem implements the [SNN Specification v1.0.0](https://sashite.dev/specs/snn/1.0.0/), supporting validation, parsing, and comparison of style names.
14
+ ### Implementation Constraints
15
+
16
+ | Constraint | Value | Rationale |
17
+ |------------|-------|-----------|
18
+ | Max string length | 32 | Sufficient for realistic style names |
19
+
20
+ These constraints enable bounded memory usage and safe parsing.
15
21
 
16
22
  ## Installation
17
23
 
18
24
  ```ruby
19
25
  # In your Gemfile
20
26
  gem "sashite-snn"
21
- ````
27
+ ```
22
28
 
23
29
  Or install manually:
24
30
 
@@ -28,160 +34,136 @@ gem install sashite-snn
28
34
 
29
35
  ## Usage
30
36
 
31
- ### Basic Operations
37
+ ### Parsing (String → StyleName)
38
+
39
+ Convert an SNN string into a `StyleName` object.
32
40
 
33
41
  ```ruby
34
42
  require "sashite/snn"
35
43
 
36
- # Parse SNN strings into style name objects
37
- name = Sashite::Snn.parse("Shogi") # => #<Snn::Name value="Shogi">
38
- name.to_s # => "Shogi"
39
- name.value # => "Shogi"
44
+ # Standard parsing (raises on error)
45
+ snn = Sashite::Snn.parse("Chess")
46
+ snn.name # => "Chess"
40
47
 
41
- # Create from string or symbol
42
- name = Sashite::Snn.name("Chess") # => #<Snn::Name value="Chess">
43
- name = Sashite::Snn::Name.new(:Xiangqi) # => #<Snn::Name value="Xiangqi">
48
+ # With numeric suffix
49
+ snn = Sashite::Snn.parse("Chess960")
50
+ snn.name # => "Chess960"
44
51
 
45
- # Validate SNN strings
46
- Sashite::Snn.valid?("Go9x9") # => true
47
- Sashite::Snn.valid?("chess") # => false (must start with uppercase)
48
- Sashite::Snn.valid?("3DChess") # => false (invalid character)
52
+ # Invalid input raises ArgumentError
53
+ Sashite::Snn.parse("chess") # => raises ArgumentError, "invalid format"
54
+ Sashite::Snn.parse("") # => raises ArgumentError, "empty input"
49
55
  ```
50
56
 
51
- ### Normalization and Comparison
57
+ ### Formatting (StyleName → String)
58
+
59
+ Convert a `StyleName` back to an SNN string.
52
60
 
53
61
  ```ruby
54
- a = Sashite::Snn.parse("Chess960")
55
- b = Sashite::Snn.parse("Chess960")
62
+ # From StyleName object
63
+ snn = Sashite::Snn::StyleName.new("Chess")
64
+ snn.to_s # => "Chess"
56
65
 
57
- a == b # => true
58
- a.same_base_name?(Sashite::Snn.parse("Chess")) # => true if both resolve to same SIN
59
- a.to_s # => "Chess960"
66
+ # String interpolation
67
+ "Playing #{snn}" # => "Playing Chess"
60
68
  ```
61
69
 
62
- ### Canonical Representation
70
+ ### Validation
63
71
 
64
72
  ```ruby
65
- # All names are normalized to a canonical format
66
- name = Sashite::Snn.parse("Minishogi")
67
- name.value # => "Minishogi"
68
- name.to_s # => "Minishogi"
73
+ # Boolean check
74
+ Sashite::Snn.valid?("Chess") # => true
75
+ Sashite::Snn.valid?("Chess960") # => true
76
+ Sashite::Snn.valid?("chess") # => false (lowercase start)
77
+ Sashite::Snn.valid?("") # => false (empty)
69
78
  ```
70
79
 
71
- ### Collections and Filtering
80
+ ### Accessing Data
72
81
 
73
82
  ```ruby
74
- names = %w[Chess Shogi Makruk Antichess Minishogi].map { |n| Sashite::Snn.parse(n) }
83
+ snn = Sashite::Snn.parse("Chess960")
75
84
 
76
- # Filter by prefix
77
- names.select { |n| n.value.start_with?("Mini") }.map(&:to_s)
78
- # => ["Minishogi"]
85
+ # Get the name (attribute)
86
+ snn.name # => "Chess960"
79
87
  ```
80
88
 
81
- ## Format Specification
89
+ ## API Reference
82
90
 
83
- ### Structure
91
+ ### Types
84
92
 
85
- ```
86
- <uppercase-letter>[<lowercase-letter | digit>]*
93
+ ```ruby
94
+ # StyleName represents a validated SNN style name.
95
+ class Sashite::Snn::StyleName
96
+ # Creates a StyleName from a valid name string.
97
+ # Raises ArgumentError if the name is invalid.
98
+ #
99
+ # @param name [String] SNN style name
100
+ # @return [StyleName]
101
+ def initialize(name)
102
+
103
+ # Returns the style name.
104
+ #
105
+ # @return [String]
106
+ def name
107
+
108
+ # Returns the SNN string representation.
109
+ #
110
+ # @return [String]
111
+ def to_s
112
+ end
87
113
  ```
88
114
 
89
- ### Grammar (BNF)
115
+ ### Constants
90
116
 
91
- ```bnf
92
- <snn> ::= <uppercase-letter> <tail>
93
-
94
- <tail> ::= "" ; Single letter (e.g., "X")
95
- | <alphanumeric-char> <tail> ; Extended name
96
-
97
- <alphanumeric-char> ::= <lowercase-letter> | <digit>
98
-
99
- <uppercase-letter> ::= "A" | "B" | "C" | ... | "Z"
100
- <lowercase-letter> ::= "a" | "b" | "c" | ... | "z"
101
- <digit> ::= "0" | "1" | "2" | "3" | ... | "9"
117
+ ```ruby
118
+ Sashite::Snn::StyleName::MAX_STRING_LENGTH # => 32
102
119
  ```
103
120
 
104
- ### Regular Expression
121
+ ### Parsing
105
122
 
106
123
  ```ruby
107
- /\A[A-Z][a-z0-9]*\z/
124
+ # Parses an SNN string into a StyleName.
125
+ # Raises ArgumentError if the string is not valid.
126
+ #
127
+ # @param string [String] SNN style name string
128
+ # @return [StyleName]
129
+ # @raise [ArgumentError] if invalid
130
+ def Sashite::Snn.parse(string)
108
131
  ```
109
132
 
110
- ## Design Principles
111
-
112
- * **Human-readable**: Names like `"Shogi"` or `"Chess960"` are intuitive and descriptive.
113
- * **Canonical**: One valid name per game style within a given context.
114
- * **ASCII-only**: Compatible with all systems.
115
- * **Scalable**: Supports unlimited distinct names for current and future game variants.
116
-
117
- ## Integration with SIN
118
-
119
- SNN names serve as the formal source for SIN character identifiers. For example:
120
-
121
- | SNN | SIN |
122
- | --------- | ------- |
123
- | `Chess` | `C`/`c` |
124
- | `Shogi` | `S`/`s` |
125
- | `Xiangqi` | `X`/`x` |
126
- | `Makruk` | `M`/`m` |
127
-
128
- Multiple SNN names may map to the same SIN character (e.g., `"Chess"` and `"Chess960"` both → `C`), but SNN provides unambiguous naming within broader contexts.
129
-
130
- ## Examples
133
+ ### Validation
131
134
 
132
135
  ```ruby
133
- Sashite::Snn.parse("Chess") # => #<Snn::Name value="Chess">
134
- Sashite::Snn.parse("Chess960") # => #<Snn::Name value="Chess960">
135
- Sashite::Snn.valid?("Minishogi") # => true
136
- Sashite::Snn.valid?("miniShogi") # => false
136
+ # Reports whether string is a valid SNN style name.
137
+ #
138
+ # @param string [String] SNN style name string
139
+ # @return [Boolean]
140
+ def Sashite::Snn.valid?(string)
137
141
  ```
138
142
 
139
- ## API Reference
140
-
141
- ### Main Module
142
-
143
- * `Sashite::Snn.valid?(str)` – Returns `true` if the string is valid SNN.
144
- * `Sashite::Snn.parse(str)` – Returns a `Sashite::Snn::Name` object.
145
- * `Sashite::Snn.name(sym_or_str)` – Alias for constructing a name.
146
-
147
- ### `Sashite::Snn::Name`
143
+ ### Errors
148
144
 
149
- * `#value` Returns the canonical string value.
150
- * `#to_s` – Returns the string representation.
151
- * `#==`, `#eql?`, `#hash` – Value-based equality.
152
- * `#same_base_name?(other)` – Optional helper for SIN mapping equivalence.
145
+ All parsing and validation errors raise `ArgumentError` with descriptive messages:
153
146
 
154
- ## Development
147
+ | Message | Cause |
148
+ |---------|-------|
149
+ | `"empty input"` | String length is 0 |
150
+ | `"input too long"` | String exceeds 32 characters |
151
+ | `"invalid format"` | Does not match SNN format |
155
152
 
156
- ```sh
157
- # Clone the repository
158
- git clone https://github.com/sashite/snn.rb.git
159
- cd snn.rb
160
-
161
- # Install dependencies
162
- bundle install
153
+ ## Design Principles
163
154
 
164
- # Run tests
165
- ruby test.rb
155
+ - **Bounded values**: Maximum string length prevents resource exhaustion
156
+ - **Object-oriented**: `StyleName` class enables methods and encapsulation
157
+ - **Ruby idioms**: `valid?` predicate, `to_s` conversion, `ArgumentError` for invalid input
158
+ - **Immutable style names**: `freeze` after construction
159
+ - **No dependencies**: Pure Ruby standard library only
166
160
 
167
- # Generate documentation
168
- yard doc
169
- ```
161
+ ## Related Specifications
170
162
 
171
- ## Contributing
172
-
173
- 1. Fork the repository
174
- 2. Create a feature branch (`git checkout -b feature/new-feature`)
175
- 3. Add tests for your changes
176
- 4. Ensure all tests pass (`ruby test.rb`)
177
- 5. Commit your changes (`git commit -am 'Add new feature'`)
178
- 6. Push to the branch (`git push origin feature/new-feature`)
179
- 7. Create a Pull Request
163
+ - [Game Protocol](https://sashite.dev/game-protocol/) — Conceptual foundation
164
+ - [SNN Specification](https://sashite.dev/specs/snn/1.0.0/) — Official specification
165
+ - [SNN Examples](https://sashite.dev/specs/snn/1.0.0/examples/) Usage examples
180
166
 
181
167
  ## License
182
168
 
183
- Available as open source under the [MIT License](https://opensource.org/licenses/MIT).
184
-
185
- ## About
186
-
187
- Maintained by [Sashité](https://sashite.com/) — promoting chess variants and sharing the beauty of board game cultures.
169
+ Available as open source under the [Apache License 2.0](https://opensource.org/licenses/Apache-2.0).
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sashite
4
+ module Snn
5
+ # Constants for the SNN (Style Name Notation) specification.
6
+ #
7
+ # Defines validation constraints for SNN tokens.
8
+ #
9
+ # @example
10
+ # Sashite::Snn::Constants::MAX_STRING_LENGTH # => 32
11
+ #
12
+ # @see https://sashite.dev/specs/snn/1.0.0/
13
+ module Constants
14
+ # Maximum length of a valid SNN string.
15
+ #
16
+ # @return [Integer] 32
17
+ MAX_STRING_LENGTH = 32
18
+
19
+ # Empty string constant for internal use.
20
+ #
21
+ # @return [String] ""
22
+ EMPTY_STRING = ""
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sashite
4
+ module Snn
5
+ module Errors
6
+ class Argument < ::ArgumentError
7
+ # Error messages for SNN parsing and validation.
8
+ #
9
+ # @example
10
+ # Messages::EMPTY_INPUT # => "empty input"
11
+ # Messages::INPUT_TOO_LONG # => "input too long"
12
+ # Messages::INVALID_FORMAT # => "invalid format"
13
+ module Messages
14
+ # Parsing error messages.
15
+
16
+ # Error message for empty input string.
17
+ EMPTY_INPUT = "empty input"
18
+
19
+ # Error message for input exceeding maximum length.
20
+ INPUT_TOO_LONG = "input too long"
21
+
22
+ # Error message for invalid SNN format.
23
+ INVALID_FORMAT = "invalid format"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "argument/messages"
4
+
5
+ module Sashite
6
+ module Sin
7
+ module Errors
8
+ # Namespace for ArgumentError-related constants and messages.
9
+ #
10
+ # Provides structured access to error messages used when raising
11
+ # ArgumentError exceptions throughout the library.
12
+ #
13
+ # @example Raising an error with a message
14
+ # raise ArgumentError, Argument::Messages::EMPTY_INPUT
15
+ #
16
+ # @see Argument::Messages
17
+ class Argument < ::ArgumentError
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "errors/argument"
4
+
5
+ module Sashite
6
+ module Snn
7
+ # Namespace for SNN error classes.
8
+ module Errors
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "constants"
4
+ require_relative "errors"
5
+
6
+ module Sashite
7
+ module Snn
8
+ # Secure parser for SNN (Style Name Notation) strings.
9
+ #
10
+ # Designed for untrusted input: validates bounds first, parses character
11
+ # by character, and enforces strict constraints at every step.
12
+ #
13
+ # @example
14
+ # Parser.parse("Chess") # => "Chess"
15
+ # Parser.parse("Chess960") # => "Chess960"
16
+ # Parser.parse("chess") # => raises Errors::Argument
17
+ #
18
+ # @see https://sashite.dev/specs/snn/1.0.0/
19
+ module Parser
20
+ # Byte ranges for validation
21
+ UPPERCASE_MIN = 0x41 # A
22
+ UPPERCASE_MAX = 0x5A # Z
23
+ LOWERCASE_MIN = 0x61 # a
24
+ LOWERCASE_MAX = 0x7A # z
25
+ DIGIT_MIN = 0x30 # 0
26
+ DIGIT_MAX = 0x39 # 9
27
+
28
+ class << self
29
+ # Parses an SNN string, validating its format.
30
+ #
31
+ # @param input [String] The SNN string to parse
32
+ # @return [String] The validated SNN string
33
+ # @raise [Errors::Argument] If the input is invalid
34
+ #
35
+ # @example
36
+ # Parser.parse("Chess") # => "Chess"
37
+ # Parser.parse("Chess960") # => "Chess960"
38
+ # Parser.parse("") # => raises Errors::Argument
39
+ def parse(input)
40
+ validate_input_type!(input)
41
+ validate_not_empty!(input)
42
+ validate_length!(input)
43
+ validate_format!(input)
44
+
45
+ input
46
+ end
47
+
48
+ # Reports whether the input is a valid SNN string.
49
+ #
50
+ # @param input [Object] The input to validate
51
+ # @return [Boolean] true if valid, false otherwise
52
+ #
53
+ # @example
54
+ # Parser.valid?("Chess") # => true
55
+ # Parser.valid?("chess") # => false
56
+ # Parser.valid?(nil) # => false
57
+ def valid?(input)
58
+ parse(input)
59
+ true
60
+ rescue Errors::Argument
61
+ false
62
+ end
63
+
64
+ private
65
+
66
+ # Validates input is a String.
67
+ def validate_input_type!(input)
68
+ return if ::String === input
69
+
70
+ raise Errors::Argument, Errors::Argument::Messages::INVALID_FORMAT
71
+ end
72
+
73
+ # Validates input is not empty.
74
+ def validate_not_empty!(input)
75
+ return unless input.empty?
76
+
77
+ raise Errors::Argument, Errors::Argument::Messages::EMPTY_INPUT
78
+ end
79
+
80
+ # Validates input does not exceed maximum length.
81
+ def validate_length!(input)
82
+ return if input.bytesize <= Constants::MAX_STRING_LENGTH
83
+
84
+ raise Errors::Argument, Errors::Argument::Messages::INPUT_TOO_LONG
85
+ end
86
+
87
+ # Validates the SNN format using byte-level parsing.
88
+ #
89
+ # Format: uppercase letter, then letters, then optional digits at end.
90
+ def validate_format!(input)
91
+ bytes = input.bytes
92
+ index = 0
93
+
94
+ # State 1: First byte must be uppercase letter
95
+ raise_invalid_format! unless uppercase?(bytes[index])
96
+ index += 1
97
+
98
+ # State 2: Parse letters (transition to digits allowed)
99
+ while index < bytes.length
100
+ byte = bytes[index]
101
+
102
+ if letter?(byte)
103
+ index += 1
104
+ elsif digit?(byte)
105
+ # Transition to digit state
106
+ index += 1
107
+ break
108
+ else
109
+ raise_invalid_format!
110
+ end
111
+ end
112
+
113
+ # State 3: Parse remaining digits only (no return to letters)
114
+ while index < bytes.length
115
+ byte = bytes[index]
116
+ raise_invalid_format! unless digit?(byte)
117
+ index += 1
118
+ end
119
+ end
120
+
121
+ # Character class predicates
122
+
123
+ def uppercase?(byte)
124
+ byte >= UPPERCASE_MIN && byte <= UPPERCASE_MAX
125
+ end
126
+
127
+ def lowercase?(byte)
128
+ byte >= LOWERCASE_MIN && byte <= LOWERCASE_MAX
129
+ end
130
+
131
+ def letter?(byte)
132
+ uppercase?(byte) || lowercase?(byte)
133
+ end
134
+
135
+ def digit?(byte)
136
+ byte >= DIGIT_MIN && byte <= DIGIT_MAX
137
+ end
138
+
139
+ def raise_invalid_format!
140
+ raise Errors::Argument, Errors::Argument::Messages::INVALID_FORMAT
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "constants"
4
+ require_relative "errors"
5
+ require_relative "parser"
6
+
7
+ module Sashite
8
+ module Snn
9
+ # Represents a validated SNN (Style Name Notation) style name.
10
+ #
11
+ # A StyleName encodes a single attribute:
12
+ # - name: the validated SNN string (PascalCase with optional numeric suffix)
13
+ #
14
+ # Instances are immutable (frozen after creation).
15
+ #
16
+ # @example Creating style names
17
+ # snn = StyleName.new("Chess")
18
+ # snn = StyleName.new("Chess960")
19
+ #
20
+ # @example String conversion
21
+ # StyleName.new("Chess").to_s # => "Chess"
22
+ # StyleName.new("Chess960").to_s # => "Chess960"
23
+ #
24
+ # @see https://sashite.dev/specs/snn/1.0.0/
25
+ class StyleName
26
+ # Maximum length of a valid SNN string.
27
+ MAX_STRING_LENGTH = Constants::MAX_STRING_LENGTH
28
+
29
+ # @return [String] The validated SNN style name
30
+ attr_reader :name
31
+
32
+ # Creates a new StyleName instance.
33
+ #
34
+ # @param name [String] The SNN style name
35
+ # @return [StyleName] A new frozen StyleName instance
36
+ # @raise [Errors::Argument] If the name is invalid
37
+ #
38
+ # @example
39
+ # StyleName.new("Chess")
40
+ # StyleName.new("Chess960")
41
+ def initialize(name)
42
+ @name = Parser.parse(name)
43
+
44
+ freeze
45
+ end
46
+
47
+ # ========================================================================
48
+ # String Conversion
49
+ # ========================================================================
50
+
51
+ # Returns the SNN string representation.
52
+ #
53
+ # @return [String] The style name
54
+ #
55
+ # @example
56
+ # StyleName.new("Chess").to_s # => "Chess"
57
+ def to_s
58
+ name
59
+ end
60
+
61
+ # ========================================================================
62
+ # Equality
63
+ # ========================================================================
64
+
65
+ # Checks equality with another StyleName.
66
+ #
67
+ # @param other [Object] The object to compare
68
+ # @return [Boolean] true if equal
69
+ #
70
+ # @example
71
+ # snn1 = StyleName.new("Chess")
72
+ # snn2 = StyleName.new("Chess")
73
+ # snn1 == snn2 # => true
74
+ def ==(other)
75
+ return false unless self.class === other
76
+
77
+ name == other.name
78
+ end
79
+
80
+ alias eql? ==
81
+
82
+ # Returns a hash code for the StyleName.
83
+ #
84
+ # @return [Integer] Hash code
85
+ def hash
86
+ name.hash
87
+ end
88
+
89
+ # Returns an inspect string for the StyleName.
90
+ #
91
+ # @return [String] Inspect representation
92
+ #
93
+ # @example
94
+ # StyleName.new("Chess").inspect # => "#<Sashite::Snn::StyleName Chess>"
95
+ def inspect
96
+ "#<#{self.class} #{self}>"
97
+ end
98
+ end
99
+ end
100
+ end
data/lib/sashite/snn.rb CHANGED
@@ -1,59 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "snn/name"
3
+ require_relative "snn/constants"
4
+ require_relative "snn/errors"
5
+ require_relative "snn/parser"
6
+ require_relative "snn/style_name"
4
7
 
5
8
  module Sashite
6
- # SNN (Style Name Notation) implementation for Ruby
9
+ # SNN (Style Name Notation) implementation for Ruby.
7
10
  #
8
- # Provides a formal naming system for identifying styles in abstract strategy board games.
9
- # SNN uses canonical, human-readable ASCII names beginning with an uppercase letter.
10
- # It supports unlimited unique style identifiers with consistent, rule-agnostic semantics.
11
+ # SNN provides a human-readable naming system for game styles (Piece Styles)
12
+ # in abstract strategy board games. It uses PascalCase names with optional
13
+ # numeric suffixes to identify movement traditions or game variants.
11
14
  #
12
- # Format: <uppercase-letter>[<lowercase-letter | digit>]*
15
+ # @example Parsing
16
+ # snn = Sashite::Snn.parse("Chess")
17
+ # snn.name # => "Chess"
13
18
  #
14
- # Examples:
15
- # "Chess" - Standard Western chess
16
- # "Shogi" - Japanese chess
17
- # "Minishogi" - 5×5 compact shōgi variant
18
- # "Chess960" - Fischer random chess
19
+ # @example Validation
20
+ # Sashite::Snn.valid?("Chess960") # => true
21
+ # Sashite::Snn.valid?("chess") # => false
19
22
  #
20
- # See: https://sashite.dev/specs/snn/1.0.0/
23
+ # @see https://sashite.dev/specs/snn/1.0.0/
21
24
  module Snn
22
- # Check if a string is valid SNN notation
25
+ # Parses an SNN string into a StyleName.
23
26
  #
24
- # @param snn_string [String] the string to validate
25
- # @return [Boolean] true if valid SNN, false otherwise
27
+ # @param input [String] The SNN string to parse
28
+ # @return [StyleName] A new StyleName instance
29
+ # @raise [Errors::Argument] If the input is invalid
26
30
  #
27
- # @example Validate SNN strings
28
- # Sashite::Snn.valid?("Chess") # => true
29
- # Sashite::Snn.valid?("minishogi") # => false
30
- # Sashite::Snn.valid?("Go9x9") # => true
31
- def self.valid?(snn_string)
32
- Name.valid?(snn_string)
33
- end
34
-
35
- # Parse an SNN string into a Name object
36
- #
37
- # @param snn_string [String] the name string
38
- # @return [Snn::Name] a parsed name object
39
- # @raise [ArgumentError] if the name is invalid
31
+ # @example
32
+ # snn = Sashite::Snn.parse("Chess")
33
+ # snn.name # => "Chess"
40
34
  #
41
- # @example Parse valid SNN names
42
- # Sashite::Snn.parse("Shogi") # => #<Snn::Name value="Shogi">
43
- def self.parse(snn_string)
44
- Name.parse(snn_string)
35
+ # @example With numeric suffix
36
+ # snn = Sashite::Snn.parse("Chess960")
37
+ # snn.name # => "Chess960"
38
+ def self.parse(input)
39
+ StyleName.new(input)
45
40
  end
46
41
 
47
- # Create a new Name instance directly
42
+ # Reports whether the input is a valid SNN string.
48
43
  #
49
- # @param value [String, Symbol] style name to construct
50
- # @return [Snn::Name] new name instance
51
- # @raise [ArgumentError] if name format is invalid
44
+ # @param input [Object] The input to validate
45
+ # @return [Boolean] true if valid, false otherwise
52
46
  #
53
47
  # @example
54
- # Sashite::Snn.name("Xiangqi") # => #<Snn::Name value="Xiangqi">
55
- def self.name(value)
56
- Name.new(value)
48
+ # Sashite::Snn.valid?("Chess") # => true
49
+ # Sashite::Snn.valid?("Chess960") # => true
50
+ # Sashite::Snn.valid?("chess") # => false
51
+ # Sashite::Snn.valid?("") # => false
52
+ def self.valid?(input)
53
+ Parser.valid?(input)
57
54
  end
58
55
  end
59
56
  end
data/lib/sashite-snn.rb CHANGED
@@ -7,7 +7,7 @@ require_relative "sashite/snn"
7
7
  # Sashité provides a collection of libraries for representing and manipulating
8
8
  # board game concepts according to the Sashité Protocol specifications.
9
9
  #
10
- # @see https://sashite.dev/protocol/ Sashité Protocol
10
+ # @see https://sashite.dev/game-protocol/ Sashité Protocol
11
11
  # @see https://sashite.dev/specs/ Sashité Specifications
12
12
  # @author Sashité
13
13
  module Sashite
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashite-snn
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
@@ -9,32 +9,35 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: |
13
- SNN (Style Name Notation) provides a rule-agnostic, scalable naming system for identifying
14
- abstract strategy board game styles. This gem implements the SNN Specification v1.0.0 with
15
- a modern Ruby interface featuring immutable style name objects and functional programming
16
- principles. SNN uses canonical ASCII names (e.g., "Shogi", "Go9x9") to unambiguously refer
17
- to game styles across variants and traditions. Ideal for engines, protocols, and tools that
18
- need clear and extensible style identifiers.
12
+ description: SNN (Style Name Notation) implementation for Ruby. Provides a rule-agnostic
13
+ format for identifying game styles in abstract strategy board games with immutable
14
+ style name objects and functional programming principles.
19
15
  email: contact@cyril.email
20
16
  executables: []
21
17
  extensions: []
22
18
  extra_rdoc_files: []
23
19
  files:
24
- - LICENSE.md
20
+ - LICENSE
25
21
  - README.md
26
22
  - lib/sashite-snn.rb
27
23
  - lib/sashite/snn.rb
28
- - lib/sashite/snn/name.rb
24
+ - lib/sashite/snn/constants.rb
25
+ - lib/sashite/snn/errors.rb
26
+ - lib/sashite/snn/errors/argument.rb
27
+ - lib/sashite/snn/errors/argument/messages.rb
28
+ - lib/sashite/snn/parser.rb
29
+ - lib/sashite/snn/style_name.rb
29
30
  homepage: https://github.com/sashite/snn.rb
30
31
  licenses:
31
- - MIT
32
+ - Apache-2.0
32
33
  metadata:
33
34
  bug_tracker_uri: https://github.com/sashite/snn.rb/issues
34
35
  documentation_uri: https://rubydoc.info/github/sashite/snn.rb/main
35
36
  homepage_uri: https://github.com/sashite/snn.rb
36
37
  source_code_uri: https://github.com/sashite/snn.rb
37
38
  specification_uri: https://sashite.dev/specs/snn/1.0.0/
39
+ wiki_uri: https://sashite.dev/specs/snn/1.0.0/examples/
40
+ funding_uri: https://github.com/sponsors/sashite
38
41
  rubygems_mfa_required: 'true'
39
42
  rdoc_options: []
40
43
  require_paths:
@@ -50,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
53
  - !ruby/object:Gem::Version
51
54
  version: '0'
52
55
  requirements: []
53
- rubygems_version: 3.6.9
56
+ rubygems_version: 4.0.3
54
57
  specification_version: 4
55
58
  summary: SNN (Style Name Notation) implementation for Ruby with immutable style name
56
59
  objects
data/LICENSE.md DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2025 Cyril Kato
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sashite
4
- module Snn
5
- # Represents a style name in SNN (Style Name Notation) format.
6
- #
7
- # SNN provides a canonical naming system for abstract strategy game styles.
8
- # Each name must start with an uppercase ASCII letter, followed by zero or more
9
- # lowercase letters or digits.
10
- #
11
- # All instances are immutable.
12
- class Name
13
- # SNN validation pattern matching the specification
14
- SNN_PATTERN = /\A[A-Z][a-z0-9]*\z/
15
-
16
- # Error messages
17
- ERROR_INVALID_NAME = "Invalid SNN string: %s"
18
-
19
- # @return [String] the canonical style name
20
- attr_reader :value
21
-
22
- # Create a new style name instance
23
- #
24
- # @param name [String, Symbol] the style name (e.g., "Shogi", :Chess960)
25
- # @raise [ArgumentError] if the name does not match SNN pattern
26
- def initialize(name)
27
- string_value = name.to_s
28
- self.class.validate_format(string_value)
29
-
30
- @value = string_value.freeze
31
- freeze
32
- end
33
-
34
- # Parse an SNN string into a Name object
35
- #
36
- # @param string [String] the SNN-formatted style name
37
- # @return [Name] a new Name instance
38
- # @raise [ArgumentError] if the string is invalid
39
- #
40
- # @example
41
- # Sashite::Snn::Name.parse("Shogi") # => #<Snn::Name value="Shogi">
42
- def self.parse(string)
43
- new(string)
44
- end
45
-
46
- # Check whether the given string is a valid SNN name
47
- #
48
- # @param string [String] input string to validate
49
- # @return [Boolean] true if valid, false otherwise
50
- #
51
- # @example
52
- # Sashite::Snn::Name.valid?("Chess") # => true
53
- # Sashite::Snn::Name.valid?("chess") # => false
54
- def self.valid?(string)
55
- string.is_a?(::String) && string.match?(SNN_PATTERN)
56
- end
57
-
58
- # Returns the string representation of the name
59
- #
60
- # @return [String]
61
- def to_s
62
- value
63
- end
64
-
65
- # Equality based on normalized string value
66
- #
67
- # @param other [Object]
68
- # @return [Boolean]
69
- def ==(other)
70
- other.is_a?(self.class) && value == other.value
71
- end
72
-
73
- # Required for correct Set/hash behavior
74
- alias eql? ==
75
-
76
- # Hash based on class and value
77
- #
78
- # @return [Integer]
79
- def hash
80
- [self.class, value].hash
81
- end
82
-
83
- # Validate that the string is in proper SNN format
84
- #
85
- # @param str [String]
86
- # @raise [ArgumentError] if invalid
87
- def self.validate_format(str)
88
- raise ::ArgumentError, format(ERROR_INVALID_NAME, str.inspect) unless str.match?(SNN_PATTERN)
89
- end
90
- end
91
- end
92
- end