sashite-pin 2.0.1 → 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 +4 -4
- data/README.md +2 -1
- data/lib/sashite/pin/piece.rb +19 -2
- data/lib/sashite/pin.rb +3 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70bbc211cb1dd38efa9f0c39b2d0e1b0fd09c2dcf2d7ac3773719ce11786a5ac
|
4
|
+
data.tar.gz: cd6831f22ee3e9fd8ce559f5535bbcbb1d9ca13ba9083a9d9c1fe66d41e2eef9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0808aac8a46423256ec3546a4eb71d5882d3535b4a74929680cd31f84294ffd406716565f53ef072ff35c5c1131bb2612ab93398001d3d80772bb34a3dc3d07
|
7
|
+
data.tar.gz: ba7ecb1765c03c801f014bdbb9792fcae5dacd8d119890b0c73f0e550a345a8fc307cb39a82b803c986ef7fa50f76ad5fff39c6a7bffc5fe39e1b06bebe6b809
|
data/README.md
CHANGED
@@ -204,6 +204,7 @@ crossed_soldier.to_s # => "+P"
|
|
204
204
|
#### Creation and Parsing
|
205
205
|
- `Sashite::Pin::Piece.new(type, side, state = :normal)` - Create piece instance
|
206
206
|
- `Sashite::Pin::Piece.parse(pin_string)` - Parse PIN string (same as module method)
|
207
|
+
- `Sashite::Pin::Piece.valid?(pin_string)` - Validate PIN string (class method)
|
207
208
|
|
208
209
|
#### Attribute Access
|
209
210
|
- `#type` - Get piece type (symbol :A to :Z, always uppercase)
|
@@ -258,7 +259,7 @@ piece2.letter # => "k" (lowercase display)
|
|
258
259
|
- `#==(other)` - Full equality comparison
|
259
260
|
|
260
261
|
### Constants
|
261
|
-
- `Sashite::Pin::
|
262
|
+
- `Sashite::Pin::Piece::PIN_PATTERN` - Regular expression for PIN validation (internal use)
|
262
263
|
|
263
264
|
## Advanced Usage
|
264
265
|
|
data/lib/sashite/pin/piece.rb
CHANGED
@@ -106,6 +106,23 @@ module Sashite
|
|
106
106
|
new(piece_type, piece_side, piece_state)
|
107
107
|
end
|
108
108
|
|
109
|
+
# Check if a string is a valid PIN notation
|
110
|
+
#
|
111
|
+
# @param pin_string [String] The string to validate
|
112
|
+
# @return [Boolean] true if valid PIN, false otherwise
|
113
|
+
#
|
114
|
+
# @example
|
115
|
+
# Sashite::Pin::Piece.valid?("K") # => true
|
116
|
+
# Sashite::Pin::Piece.valid?("+R") # => true
|
117
|
+
# Sashite::Pin::Piece.valid?("-p") # => true
|
118
|
+
# Sashite::Pin::Piece.valid?("KK") # => false
|
119
|
+
# Sashite::Pin::Piece.valid?("++K") # => false
|
120
|
+
def self.valid?(pin_string)
|
121
|
+
return false unless pin_string.is_a?(::String)
|
122
|
+
|
123
|
+
pin_string.match?(PIN_PATTERN)
|
124
|
+
end
|
125
|
+
|
109
126
|
# Convert the piece to its PIN string representation
|
110
127
|
#
|
111
128
|
# @return [String] PIN notation string
|
@@ -190,9 +207,9 @@ module Sashite
|
|
190
207
|
self.class.new(type, side, NORMAL_STATE)
|
191
208
|
end
|
192
209
|
|
193
|
-
# Create a new piece with opposite
|
210
|
+
# Create a new piece with opposite side
|
194
211
|
#
|
195
|
-
# @return [Piece] new piece instance with
|
212
|
+
# @return [Piece] new piece instance with opposite side
|
196
213
|
# @example
|
197
214
|
# piece.flip # (:K, :first, :normal) => (:K, :second, :normal)
|
198
215
|
def flip
|
data/lib/sashite/pin.rb
CHANGED
@@ -20,13 +20,9 @@ module Sashite
|
|
20
20
|
#
|
21
21
|
# See: https://sashite.dev/specs/pin/1.0.0/
|
22
22
|
module Pin
|
23
|
-
# Regular expression for PIN validation
|
24
|
-
# Matches: optional state modifier followed by a single letter
|
25
|
-
PIN_REGEX = /\A[-+]?[A-Za-z]\z/
|
26
|
-
|
27
23
|
# Check if a string is a valid PIN notation
|
28
24
|
#
|
29
|
-
# @param
|
25
|
+
# @param pin_string [String] The string to validate
|
30
26
|
# @return [Boolean] true if valid PIN, false otherwise
|
31
27
|
#
|
32
28
|
# @example
|
@@ -35,10 +31,8 @@ module Sashite
|
|
35
31
|
# Sashite::Pin.valid?("-p") # => true
|
36
32
|
# Sashite::Pin.valid?("KK") # => false
|
37
33
|
# Sashite::Pin.valid?("++K") # => false
|
38
|
-
def self.valid?(
|
39
|
-
|
40
|
-
|
41
|
-
pin.match?(PIN_REGEX)
|
34
|
+
def self.valid?(pin_string)
|
35
|
+
Piece.valid?(pin_string)
|
42
36
|
end
|
43
37
|
|
44
38
|
# Parse a PIN string into a Piece object
|