sashite-pmn 1.0.0 → 1.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: c3ebaf0b731c5fa324e1515369a8a98bc3fc4a6a8094d67023728a04c650a963
4
- data.tar.gz: 6a4e1ba06a8afd9015ae8dcc89795fa9f28a7b573d4502b13e52d5ed380c3630
3
+ metadata.gz: a51482a92eec36293c9fe583574f7d4981bd953f36846459515ac1ba58a37dc6
4
+ data.tar.gz: 01a42bd2bc3ca44550d681573b96d821f67c58cacc2df0dd5b7bccc2a4f4801f
5
5
  SHA512:
6
- metadata.gz: c6624a7cb869903504622c7a7a34f9a5a73a3c63967ed6c7d0ff89e9e4fe8782e806b94742ea3156fd41b54159cc81c5921e59e5cd27c97bf076ca90482148d2
7
- data.tar.gz: 7d871f7cdc7509b9c8ec3ea77c0375652423940be53f157e60e4debebc604ed2a10558ecc7d0a9e6e7a892e9a771bbabab0151d2929127de87d81ee2ac5c332f
6
+ metadata.gz: 9b9775836efcc6db95dada230c631d78f6918c0efc3c9692f04c2d5a7d0c1041e90b390023d49fcb4e75ca6e166dc3af6f6821fa0563e54994a101e607f39e32
7
+ data.tar.gz: 7d46c954a1e4a1c696a6f9cd222dc80785b6c8a54b0c26210e0045c8ee8671562262e2074c2b14612e21fb24a359bd301d4422bceff73b8c80748c353b1fa6ba
@@ -30,8 +30,8 @@ module Sashite
30
30
  # @param source [String] CELL or "*"
31
31
  # @param destination [String] CELL or "*"
32
32
  # @param piece [String, nil] QPI string (optional)
33
- # @raise [InvalidLocationError] if source/destination are invalid
34
- # @raise [InvalidPieceError] if piece is provided but invalid
33
+ # @raise [Error::Location] if source/destination are invalid
34
+ # @raise [Error::Piece] if piece is provided but invalid
35
35
  def initialize(source, destination, piece = nil)
36
36
  validate_source!(source)
37
37
  validate_destination!(destination)
@@ -115,7 +115,7 @@ module Sashite
115
115
  end
116
116
 
117
117
  # @param other [Object]
118
- # @return [Boolean] equality by {source, destination, piece}
118
+ # @return [Boolean] equality by source, destination, piece
119
119
  def ==(other)
120
120
  return false unless other.is_a?(Action)
121
121
 
@@ -156,28 +156,28 @@ module Sashite
156
156
  # ---------- Internal validation helpers -------------------------------
157
157
 
158
158
  # @param src [String]
159
- # @raise [InvalidLocationError]
159
+ # @raise [Error::Location]
160
160
  def validate_source!(src)
161
161
  return if valid_location?(src)
162
162
 
163
- raise InvalidLocationError, "Invalid source location: #{src.inspect}"
163
+ raise Error::Location, "Invalid source location: #{src.inspect}"
164
164
  end
165
165
 
166
166
  # @param dst [String]
167
- # @raise [InvalidLocationError]
167
+ # @raise [Error::Location]
168
168
  def validate_destination!(dst)
169
169
  return if valid_location?(dst)
170
170
 
171
- raise InvalidLocationError, "Invalid destination location: #{dst.inspect}"
171
+ raise Error::Location, "Invalid destination location: #{dst.inspect}"
172
172
  end
173
173
 
174
174
  # @param qpi [String, nil]
175
- # @raise [InvalidPieceError]
175
+ # @raise [Error::Piece]
176
176
  def validate_piece!(qpi)
177
177
  return if qpi.nil?
178
178
  return if Qpi.valid?(qpi)
179
179
 
180
- raise InvalidPieceError, "Invalid piece QPI format: #{qpi.inspect}"
180
+ raise Error::Piece, "Invalid piece QPI format: #{qpi.inspect}"
181
181
  end
182
182
 
183
183
  # @param location [String]
@@ -2,19 +2,52 @@
2
2
 
3
3
  module Sashite
4
4
  module Pmn
5
- # Base class for all PMN-related errors
6
- class Error < StandardError; end
5
+ # Base error namespace for PMN.
6
+ #
7
+ # Usage patterns:
8
+ # rescue Sashite::Pmn::Error => e
9
+ # rescue Sashite::Pmn::Error::Move
10
+ # rescue Sashite::Pmn::Error::Location, Sashite::Pmn::Error::Piece
11
+ class Error < ::StandardError
12
+ # Raised when a PMN move (sequence) is malformed or invalid.
13
+ #
14
+ # @example
15
+ # begin
16
+ # Sashite::Pmn::Move.new("e2") # Incomplete action
17
+ # rescue Sashite::Pmn::Error::Move => e
18
+ # warn "Invalid move sequence: #{e.message}"
19
+ # end
20
+ class Move < Error; end
7
21
 
8
- # Raised when a PMN move (sequence) is malformed or invalid
9
- class InvalidMoveError < Error; end
22
+ # Raised when an atomic action is malformed or fails validation.
23
+ #
24
+ # @example
25
+ # begin
26
+ # Sashite::Pmn::Action.new("invalid", "e4", "C:P")
27
+ # rescue Sashite::Pmn::Error::Action => e
28
+ # warn "Invalid atomic action: #{e.message}"
29
+ # end
30
+ class Action < Error; end
10
31
 
11
- # Raised when an atomic action is malformed or fails validation
12
- class InvalidActionError < Error; end
32
+ # Raised when a location is neither a valid CELL coordinate nor HAND ("*").
33
+ #
34
+ # @example
35
+ # begin
36
+ # Sashite::Pmn::Action.new("ZZ99", "e4", "C:P")
37
+ # rescue Sashite::Pmn::Error::Location => e
38
+ # warn "Invalid location: #{e.message}"
39
+ # end
40
+ class Location < Action; end
13
41
 
14
- # Raised when a location is neither a valid CELL coordinate nor HAND ("*")
15
- class InvalidLocationError < InvalidActionError; end
16
-
17
- # Raised when a piece identifier is not valid QPI
18
- class InvalidPieceError < InvalidActionError; end
42
+ # Raised when a piece identifier is not valid QPI format.
43
+ #
44
+ # @example
45
+ # begin
46
+ # Sashite::Pmn::Action.new("e2", "e4", "NotQPI")
47
+ # rescue Sashite::Pmn::Error::Piece => e
48
+ # warn "Invalid piece QPI: #{e.message}"
49
+ # end
50
+ class Piece < Action; end
51
+ end
19
52
  end
20
53
  end
@@ -23,7 +23,7 @@ module Sashite
23
23
  # Create a Move from PMN elements (variadic only).
24
24
  #
25
25
  # @param pmn_elements [Array<String>] passed as individual args
26
- # @raise [InvalidMoveError] if called with a single Array or if invalid
26
+ # @raise [Error::Move] if called with a single Array or if invalid
27
27
  #
28
28
  # @example
29
29
  # Move.new("e2","e4","C:P")
@@ -31,7 +31,7 @@ module Sashite
31
31
  def initialize(*pmn_elements)
32
32
  # single-array form is intentionally not supported (entropy reduction)
33
33
  if pmn_elements.size == 1 && pmn_elements.first.is_a?(Array)
34
- raise InvalidMoveError,
34
+ raise Error::Move,
35
35
  'PMN must be passed as individual arguments, e.g. Move.new("e2","e4","C:P")'
36
36
  end
37
37
 
@@ -170,14 +170,14 @@ module Sashite
170
170
  # Validation ------------------------------------------------------------
171
171
 
172
172
  def validate_array!(array)
173
- raise InvalidMoveError, "PMN must be an array, got #{array.class}" unless array.is_a?(Array)
174
- raise InvalidMoveError, "PMN array cannot be empty" if array.empty?
173
+ raise Error::Move, "PMN must be an array, got #{array.class}" unless array.is_a?(Array)
174
+ raise Error::Move, "PMN array cannot be empty" if array.empty?
175
175
 
176
- raise InvalidMoveError, "All PMN elements must be strings" unless array.all?(String)
176
+ raise Error::Move, "All PMN elements must be strings" unless array.all?(String)
177
177
 
178
178
  return if valid_length?(array)
179
179
 
180
- raise InvalidMoveError, "Invalid PMN array length: #{array.size}"
180
+ raise Error::Move, "Invalid PMN array length: #{array.size}"
181
181
  end
182
182
 
183
183
  # Valid lengths: (size % 3 == 0) OR (size % 3 == 2), minimum 2.
@@ -204,21 +204,21 @@ module Sashite
204
204
  actions << Action.new(array[index], array[index + 1], array[index + 2])
205
205
  index += 3
206
206
  else
207
- raise InvalidMoveError, "Invalid action group at index #{index}"
207
+ raise Error::Move, "Invalid action group at index #{index}"
208
208
  end
209
209
  end
210
210
 
211
211
  actions
212
- rescue InvalidActionError => e
212
+ rescue Error::Action => e
213
213
  # Normalize action-level errors as move-level errors during parsing
214
- raise InvalidMoveError, "Invalid action while parsing move at index #{index}: #{e.message}"
214
+ raise Error::Move, "Invalid action while parsing move at index #{index}: #{e.message}"
215
215
  end
216
216
 
217
217
  def validate_actions!
218
218
  actions.each_with_index do |action, i|
219
219
  next if action.valid?
220
220
 
221
- raise InvalidMoveError, "Invalid action at position #{i}: #{action.inspect}"
221
+ raise Error::Move, "Invalid action at position #{i}: #{action.inspect}"
222
222
  end
223
223
  end
224
224
  end
data/lib/sashite/pmn.rb CHANGED
@@ -27,12 +27,12 @@ module Sashite
27
27
  #
28
28
  # @param pmn_array [Array<String>] flat array of PMN elements
29
29
  # @return [Sashite::Pmn::Move]
30
- # @raise [Sashite::Pmn::InvalidMoveError] if the array or any action is invalid
30
+ # @raise [Sashite::Pmn::Error::Move] if the array or any action is invalid
31
31
  #
32
32
  # @example
33
33
  # Sashite::Pmn.parse(["e2","e4","C:P"]).actions.size # => 1
34
34
  def self.parse(pmn_array)
35
- raise InvalidMoveError, "PMN must be an array, got #{pmn_array.class}" unless pmn_array.is_a?(Array)
35
+ raise Error::Move, "PMN must be an array, got #{pmn_array.class}" unless pmn_array.is_a?(Array)
36
36
 
37
37
  Move.new(*pmn_array)
38
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashite-pmn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato