sashite-pin 3.3.0 → 4.1.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: 629bf8b689b39a81e6b52ca9b1386f53c6c807f5f57ae608fb99449ceb08854e
4
- data.tar.gz: '0883b5de633e958ddbf72908ffd49832e999e0a1f99b615ce8aa5fa1222cd4f5'
3
+ metadata.gz: e00046935bd19fe218aed6188bc310389c9a93e5e36aad8b91890d36046c4165
4
+ data.tar.gz: e90e9430c444175c658262c486eddfe3c09a6e5da2c88b0b1365fb91f14616a0
5
5
  SHA512:
6
- metadata.gz: a64ac32e1afb6b84c388823f81022efe6eda1a469ce82920b4d8119f0e747e4f5a8788c92d397a48165b36fcfda45111df785dad8523f3e861e31acb55e6fd68
7
- data.tar.gz: 99a1e0e87304f2b1f525483cf952a4a0d9fdf0768297010894e6d429f4431b7c5476f287f94e3e85dd9c4c46669546ed094c2afc0fdd6296c9bccebcd8aa255b
6
+ metadata.gz: f716220c9d53ba9003712d64c3335f20b395c2174637b2432f43ca01c654dca7586b84f3057747126cf899003478afc071de31cd93e76ce0dc49dd7f7a9f99d5
7
+ data.tar.gz: 0aedbcd707733bbd81dd6fa48608a52f66016aec2e63162c5f841cbaf359959d3f902d8dddca2e08848d57dce1f3ccb31e3baeebb791812bea91c678a1f9fe0f
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-2026 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,17 +1,15 @@
1
- # Sashite::Pin
1
+ # pin.rb
2
2
 
3
3
  [![Version](https://img.shields.io/github/v/tag/sashite/pin.rb?label=Version&logo=github)](https://github.com/sashite/pin.rb/tags)
4
4
  [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/sashite/pin.rb/main)
5
- ![Ruby](https://github.com/sashite/pin.rb/actions/workflows/main.yml/badge.svg?branch=main)
6
- [![License](https://img.shields.io/github/license/sashite/pin.rb?label=License&logo=github)](https://github.com/sashite/pin.rb/raw/main/LICENSE.md)
5
+ [![CI](https://github.com/sashite/pin.rb/actions/workflows/ruby.yml/badge.svg?branch=main)](https://github.com/sashite/pin.rb/actions)
6
+ [![License](https://img.shields.io/github/license/sashite/pin.rb)](https://github.com/sashite/pin.rb/blob/main/LICENSE)
7
7
 
8
8
  > **PIN** (Piece Identifier Notation) implementation for Ruby.
9
9
 
10
- ## What is PIN?
10
+ ## Overview
11
11
 
12
- PIN (Piece Identifier Notation) provides an ASCII-based format for representing pieces in abstract strategy board games. PIN translates piece attributes from the [Game Protocol](https://sashite.dev/game-protocol/) into a compact, portable notation system.
13
-
14
- This gem implements the [PIN Specification v1.0.0](https://sashite.dev/specs/pin/1.0.0/).
12
+ This library implements the [PIN Specification v1.0.0](https://sashite.dev/specs/pin/1.0.0/).
15
13
 
16
14
  ## Installation
17
15
 
@@ -28,213 +26,263 @@ gem install sashite-pin
28
26
 
29
27
  ## Usage
30
28
 
29
+ ### Parsing (String → Identifier)
30
+
31
+ Convert a PIN string into an `Identifier` object.
32
+
31
33
  ```ruby
32
34
  require "sashite/pin"
33
35
 
34
- # Parse PIN strings
36
+ # Standard parsing (raises on error)
35
37
  pin = Sashite::Pin.parse("K")
36
- pin.type # => :K
37
- pin.side # => :first
38
- pin.state # => :normal
39
- pin.terminal # => false
38
+ pin.abbr # => :K
39
+ pin.side # => :first
40
+ pin.state # => :normal
41
+ pin.terminal? # => false
42
+
43
+ # With state modifier
44
+ pin = Sashite::Pin.parse("+R")
45
+ pin.state # => :enhanced
46
+
47
+ # With terminal marker
48
+ pin = Sashite::Pin.parse("K^")
49
+ pin.terminal? # => true
50
+
51
+ # Combined
52
+ pin = Sashite::Pin.parse("+K^")
53
+ pin.state # => :enhanced
54
+ pin.terminal? # => true
55
+
56
+ # Invalid input raises ArgumentError
57
+ Sashite::Pin.parse("invalid") # => raises ArgumentError
58
+ ```
59
+
60
+ ### Formatting (Identifier → String)
61
+
62
+ Convert an `Identifier` back to a PIN string.
40
63
 
64
+ ```ruby
65
+ # From Identifier object
66
+ pin = Sashite::Pin::Identifier.new(:K, :first)
41
67
  pin.to_s # => "K"
42
68
 
43
- # Parse with different attributes
44
- king = Sashite::Pin.parse("K^") # Terminal king
45
- rook = Sashite::Pin.parse("+R") # Enhanced rook
46
- pawn = Sashite::Pin.parse("-p") # Diminished second player pawn
69
+ # With attributes
70
+ pin = Sashite::Pin::Identifier.new(:R, :second, :enhanced)
71
+ pin.to_s # => "+r"
72
+
73
+ pin = Sashite::Pin::Identifier.new(:K, :first, :normal, terminal: true)
74
+ pin.to_s # => "K^"
75
+ ```
47
76
 
48
- # Create identifiers directly
49
- pin = Sashite::Pin.new(:K, :first)
50
- pin = Sashite::Pin.new(:R, :second, :enhanced)
51
- pin = Sashite::Pin.new(:K, :first, :normal, terminal: true)
77
+ ### Validation
52
78
 
53
- # Validation
79
+ ```ruby
80
+ # Boolean check
54
81
  Sashite::Pin.valid?("K") # => true
55
82
  Sashite::Pin.valid?("+R") # => true
56
83
  Sashite::Pin.valid?("K^") # => true
57
84
  Sashite::Pin.valid?("invalid") # => false
85
+ ```
58
86
 
59
- # State transformations (return new instances)
60
- enhanced = pin.enhance
61
- enhanced.to_s # => "+K"
87
+ ### Transformations
88
+
89
+ All transformations return new immutable instances.
62
90
 
63
- diminished = pin.diminish
64
- diminished.to_s # => "-K"
91
+ ```ruby
92
+ pin = Sashite::Pin.parse("K")
65
93
 
66
- normalized = enhanced.normalize
67
- normalized.to_s # => "K"
94
+ # State transformations
95
+ pin.enhance.to_s # => "+K"
96
+ pin.diminish.to_s # => "-K"
97
+ pin.normalize.to_s # => "K"
68
98
 
69
99
  # Side transformation
70
- flipped = pin.flip
71
- flipped.to_s # => "k"
100
+ pin.flip.to_s # => "k"
72
101
 
73
102
  # Terminal transformations
74
- terminal = pin.mark_terminal
75
- terminal.to_s # => "K^"
103
+ pin.terminal.to_s # => "K^"
104
+ pin.non_terminal.to_s # => "K"
76
105
 
77
- non_terminal = terminal.unmark_terminal
78
- non_terminal.to_s # => "K"
106
+ # Attribute changes
107
+ pin.with_abbr(:Q).to_s # => "Q"
108
+ pin.with_side(:second).to_s # => "k"
109
+ pin.with_state(:enhanced).to_s # => "+K"
110
+ pin.with_terminal(true).to_s # => "K^"
111
+ ```
79
112
 
80
- # Type transformation
81
- queen = pin.with_type(:Q)
82
- queen.to_s # => "Q"
113
+ ### Queries
114
+
115
+ ```ruby
116
+ pin = Sashite::Pin.parse("+K^")
83
117
 
84
118
  # State queries
85
- pin.normal? # => true
86
- enhanced.enhanced? # => true
87
- diminished.diminished? # => true
119
+ pin.normal? # => false
120
+ pin.enhanced? # => true
121
+ pin.diminished? # => false
88
122
 
89
123
  # Side queries
90
124
  pin.first_player? # => true
91
- flipped.second_player? # => true
125
+ pin.second_player? # => false
92
126
 
93
- # Terminal queries
94
- terminal.terminal? # => true
127
+ # Terminal query
128
+ pin.terminal? # => true
95
129
 
96
- # Comparison
97
- king1 = Sashite::Pin.parse("K")
98
- king2 = Sashite::Pin.parse("k")
99
-
100
- king1.same_type?(king2) # => true
101
- king1.same_side?(king2) # => false
130
+ # Comparison queries
131
+ other = Sashite::Pin.parse("k")
132
+ pin.same_abbr?(other) # => true
133
+ pin.same_side?(other) # => false
134
+ pin.same_state?(other) # => false
135
+ pin.same_terminal?(other) # => false
102
136
  ```
103
137
 
104
- ## Format Specification
138
+ ## API Reference
105
139
 
106
- ### Structure
140
+ ### Types
107
141
 
142
+ ```ruby
143
+ # Identifier represents a parsed PIN with all attributes.
144
+ class Sashite::Pin::Identifier
145
+ # Creates an Identifier from attributes.
146
+ # Raises ArgumentError if attributes are invalid.
147
+ #
148
+ # @param abbr [Symbol] Piece name abbreviation (:A to :Z)
149
+ # @param side [Symbol] Piece side (:first or :second)
150
+ # @param state [Symbol] Piece state (:normal, :enhanced, or :diminished)
151
+ # @param terminal [Boolean] Terminal status
152
+ # @return [Identifier]
153
+ def initialize(abbr, side, state = :normal, terminal: false)
154
+
155
+ # Returns the piece name abbreviation (always uppercase symbol).
156
+ #
157
+ # @return [Symbol]
158
+ def abbr
159
+
160
+ # Returns the piece side.
161
+ #
162
+ # @return [Symbol] :first or :second
163
+ def side
164
+
165
+ # Returns the piece state.
166
+ #
167
+ # @return [Symbol] :normal, :enhanced, or :diminished
168
+ def state
169
+
170
+ # Returns the terminal status.
171
+ #
172
+ # @return [Boolean]
173
+ def terminal?
174
+
175
+ # Returns the PIN string representation.
176
+ #
177
+ # @return [String]
178
+ def to_s
179
+ end
108
180
  ```
109
- [<state-modifier>]<letter>[<terminal-marker>]
110
- ```
111
-
112
- ### Components
113
-
114
- | Component | Values | Description |
115
- |-----------|--------|-------------|
116
- | Letter | `A-Z`, `a-z` | Piece type and side |
117
- | State Modifier | `+`, `-`, (none) | Enhanced, diminished, or normal |
118
- | Terminal Marker | `^`, (none) | Terminal piece or not |
119
-
120
- ### Side Convention
121
-
122
- - **Uppercase** (`A-Z`): First player
123
- - **Lowercase** (`a-z`): Second player
124
181
 
125
- ### Examples
126
-
127
- | PIN | Side | State | Terminal | Description |
128
- |-----|------|-------|----------|-------------|
129
- | `K` | First | Normal | No | Standard king |
130
- | `K^` | First | Normal | Yes | Terminal king |
131
- | `+R` | First | Enhanced | No | Promoted rook |
132
- | `-p` | Second | Diminished | No | Weakened pawn |
133
- | `+K^` | First | Enhanced | Yes | Enhanced terminal king |
134
-
135
- ## API Reference
136
-
137
- ### Parsing and Validation
182
+ ### Constants
138
183
 
139
184
  ```ruby
140
- Sashite::Pin.parse(pin_string) # => Sashite::Pin | raises ArgumentError
141
- Sashite::Pin.valid?(pin_string) # => boolean
185
+ Sashite::Pin::Constants::VALID_ABBRS # => [:A, :B, ..., :Z]
186
+ Sashite::Pin::Constants::VALID_SIDES # => [:first, :second]
187
+ Sashite::Pin::Constants::VALID_STATES # => [:normal, :enhanced, :diminished]
188
+ Sashite::Pin::Constants::MAX_STRING_LENGTH # => 3
142
189
  ```
143
190
 
144
- ### Creation
191
+ ### Parsing
145
192
 
146
193
  ```ruby
147
- Sashite::Pin.new(type, side)
148
- Sashite::Pin.new(type, side, state)
149
- Sashite::Pin.new(type, side, state, terminal: boolean)
194
+ # Parses a PIN string into an Identifier.
195
+ # Raises ArgumentError if the string is not valid.
196
+ #
197
+ # @param string [String] PIN string
198
+ # @return [Identifier]
199
+ # @raise [ArgumentError] if invalid
200
+ def Sashite::Pin.parse(string)
150
201
  ```
151
202
 
152
- ### Conversion
203
+ ### Validation
153
204
 
154
205
  ```ruby
155
- pin.to_s # => String
156
- pin.letter # => String (case determined by side)
157
- pin.prefix # => String ("+" | "-" | "")
158
- pin.suffix # => String ("^" | "")
206
+ # Reports whether string is a valid PIN.
207
+ #
208
+ # @param string [String] PIN string
209
+ # @return [Boolean]
210
+ def Sashite::Pin.valid?(string)
159
211
  ```
160
212
 
161
213
  ### Transformations
162
214
 
163
- All transformations return new `Sashite::Pin` instances:
215
+ All transformations return new `Sashite::Pin::Identifier` instances:
164
216
 
165
217
  ```ruby
166
- # State
167
- pin.enhance # => Sashite::Pin with :enhanced state
168
- pin.diminish # => Sashite::Pin with :diminished state
169
- pin.normalize # => Sashite::Pin with :normal state
218
+ # State transformations
219
+ def enhance # => Identifier with :enhanced state
220
+ def diminish # => Identifier with :diminished state
221
+ def normalize # => Identifier with :normal state
170
222
 
171
- # Side
172
- pin.flip # => Sashite::Pin with opposite side
223
+ # Side transformation
224
+ def flip # => Identifier with opposite side
173
225
 
174
- # Terminal
175
- pin.mark_terminal # => Sashite::Pin with terminal: true
176
- pin.unmark_terminal # => Sashite::Pin with terminal: false
226
+ # Terminal transformations
227
+ def terminal # => Identifier with terminal: true
228
+ def non_terminal # => Identifier with terminal: false
177
229
 
178
230
  # Attribute changes
179
- pin.with_type(new_type) # => Sashite::Pin with different type
180
- pin.with_side(new_side) # => Sashite::Pin with different side
181
- pin.with_state(new_state) # => Sashite::Pin with different state
182
- pin.with_terminal(boolean) # => Sashite::Pin with specified terminal status
231
+ def with_abbr(new_abbr) # => Identifier with different abbreviation
232
+ def with_side(new_side) # => Identifier with different side
233
+ def with_state(new_state) # => Identifier with different state
234
+ def with_terminal(new_terminal) # => Identifier with specified terminal status
183
235
  ```
184
236
 
185
237
  ### Queries
186
238
 
187
239
  ```ruby
188
- # State
189
- pin.normal?
190
- pin.enhanced?
191
- pin.diminished?
192
-
193
- # Side
194
- pin.first_player?
195
- pin.second_player?
196
-
197
- # Terminal
198
- pin.terminal?
199
-
200
- # Comparison
201
- pin.same_type?(other)
202
- pin.same_side?(other)
203
- pin.same_state?(other)
204
- pin.same_terminal?(other)
205
- ```
240
+ # State queries
241
+ def normal? # => Boolean
242
+ def enhanced? # => Boolean
243
+ def diminished? # => Boolean
206
244
 
207
- ## Data Structure
245
+ # Side queries
246
+ def first_player? # => Boolean
247
+ def second_player? # => Boolean
208
248
 
209
- ```ruby
210
- Sashite::Pin
211
- #type => :A..:Z # Piece type (always uppercase symbol)
212
- #side => :first | :second # Player side
213
- #state => :normal | :enhanced | :diminished
214
- #terminal => true | false
249
+ # Terminal query
250
+ def terminal? # => Boolean
251
+
252
+ # Comparison queries
253
+ def same_abbr?(other) # => Boolean
254
+ def same_side?(other) # => Boolean
255
+ def same_state?(other) # => Boolean
256
+ def same_terminal?(other) # => Boolean
215
257
  ```
216
258
 
217
- ## Protocol Mapping
259
+ ### Errors
260
+
261
+ All parsing and validation errors raise `ArgumentError` with descriptive messages:
262
+
263
+ | Message | Cause |
264
+ |---------|-------|
265
+ | `"empty input"` | String length is 0 |
266
+ | `"input exceeds 3 characters"` | String too long |
267
+ | `"must contain exactly one letter"` | Missing or multiple letters |
268
+ | `"invalid state modifier"` | Invalid prefix character |
269
+ | `"invalid terminal marker"` | Invalid suffix character |
218
270
 
219
- Following the [Game Protocol](https://sashite.dev/game-protocol/):
271
+ ## Design Principles
220
272
 
221
- | Protocol Attribute | PIN Encoding |
222
- |-------------------|--------------|
223
- | Piece Name | ASCII letter choice |
224
- | Piece Side | Letter case |
225
- | Piece State | Optional prefix (`+`/`-`) |
226
- | Terminal Status | Optional suffix (`^`) |
273
+ - **Bounded values**: Explicit validation of abbreviations, sides, and states
274
+ - **Object-oriented**: `Identifier` class enables methods and encapsulation
275
+ - **Ruby idioms**: `valid?` predicate, `to_s` conversion, `ArgumentError` for invalid input
276
+ - **Immutable identifiers**: Frozen instances prevent mutation
277
+ - **Transformation methods**: Return new instances for attribute changes
278
+ - **No dependencies**: Pure Ruby standard library only
227
279
 
228
280
  ## Related Specifications
229
281
 
230
282
  - [Game Protocol](https://sashite.dev/game-protocol/) — Conceptual foundation
231
- - [PNN](https://sashite.dev/specs/pnn/) — Piece Name Notation
232
283
  - [PIN Specification](https://sashite.dev/specs/pin/1.0.0/) — Official specification
284
+ - [PIN Examples](https://sashite.dev/specs/pin/1.0.0/examples/) — Usage examples
233
285
 
234
286
  ## License
235
287
 
236
- Available as open source under the [MIT License](https://opensource.org/licenses/MIT).
237
-
238
- ## About
239
-
240
- Maintained by [Sashité](https://sashite.com/) — promoting chess variants and sharing the beauty of board game cultures.
288
+ Available as open source under the [Apache License 2.0](https://opensource.org/licenses/Apache-2.0).
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sashite
4
+ module Pin
5
+ # Constants for PIN (Piece Identifier Notation).
6
+ #
7
+ # This module defines the valid values for PIN attributes.
8
+ module Constants
9
+ # Valid piece name abbreviations (uppercase symbols A-Z).
10
+ VALID_ABBRS = %i[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z].freeze
11
+
12
+ # Valid player sides.
13
+ VALID_SIDES = %i[first second].freeze
14
+
15
+ # Valid piece states.
16
+ VALID_STATES = %i[normal enhanced diminished].freeze
17
+
18
+ # Maximum length of a valid PIN string.
19
+ # Corresponds to "+K^" (state modifier + letter + terminal marker).
20
+ MAX_STRING_LENGTH = 3
21
+
22
+ # State modifier for enhanced state.
23
+ ENHANCED_PREFIX = "+"
24
+
25
+ # State modifier for diminished state.
26
+ DIMINISHED_PREFIX = "-"
27
+
28
+ # Empty string (no modifier).
29
+ EMPTY_STRING = ""
30
+
31
+ # Terminal marker suffix.
32
+ TERMINAL_SUFFIX = "^"
33
+ end
34
+ end
35
+ end