Class: Sashite::Pan::Action::Modify
- Inherits:
-
Object
- Object
- Sashite::Pan::Action::Modify
- Defined in:
- lib/sashite/pan/action/modify.rb
Overview
Modify action class
Handles in-place transformation actions where a piece changes its attributes without moving.
Format: <square>=<piece> Examples: “e4=+P”, “c3=k’”
Constant Summary collapse
- TYPE =
Action type
:modify- OPERATOR =
Operator constant
"="- ERROR_INVALID_MODIFY =
Error messages
"Invalid modify notation: %s"- ERROR_INVALID_SQUARE =
"Invalid square coordinate: %s"- ERROR_INVALID_PIECE =
"Invalid piece identifier: %s"
Instance Attribute Summary collapse
-
#destination ⇒ String
readonly
Destination CELL coordinate (square being modified).
-
#piece ⇒ String
readonly
EPIN piece identifier (final state).
Class Method Summary collapse
-
.parse(pan_string) ⇒ Modify
Parse a modify notation string into a Modify instance.
-
.valid?(pan_string) ⇒ Boolean
Check if a string represents a valid modify action.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Custom equality comparison.
-
#capture? ⇒ Boolean
Check if this is a capture action.
-
#drop? ⇒ Boolean
Check if this is a drop action.
-
#drop_action? ⇒ Boolean
Check if this is a drop action (drop or drop_capture).
-
#drop_capture? ⇒ Boolean
Check if this is a drop capture action.
-
#hash ⇒ Integer
Custom hash implementation for use in collections.
-
#initialize(square, piece) ⇒ Modify
constructor
Create a new modify action instance.
-
#modify? ⇒ Boolean
Check if this is a modify action.
-
#move? ⇒ Boolean
Check if this is a move action.
-
#movement? ⇒ Boolean
Check if this is a movement action.
-
#pass? ⇒ Boolean
Check if this is a pass action.
-
#source ⇒ nil
Get the source coordinate.
-
#special? ⇒ Boolean
Check if this is a special action.
-
#static_capture? ⇒ Boolean
Check if this is a static capture action.
-
#to_s ⇒ String
Convert the action to its PAN string representation.
-
#transformation ⇒ nil
Get the transformation piece.
-
#type ⇒ Symbol
Get the action type.
Constructor Details
#initialize(square, piece) ⇒ Modify
Create a new modify action instance
87 88 89 90 91 92 93 94 95 |
# File 'lib/sashite/pan/action/modify.rb', line 87 def initialize(square, piece) raise ::ArgumentError, format(ERROR_INVALID_SQUARE, square) unless ::Sashite::Cell.valid?(square) raise ::ArgumentError, format(ERROR_INVALID_PIECE, piece) unless ::Sashite::Epin.valid?(piece) @destination = square @piece = piece freeze end |
Instance Attribute Details
#destination ⇒ String (readonly)
Returns destination CELL coordinate (square being modified).
29 30 31 |
# File 'lib/sashite/pan/action/modify.rb', line 29 def destination @destination end |
#piece ⇒ String (readonly)
Returns EPIN piece identifier (final state).
32 33 34 |
# File 'lib/sashite/pan/action/modify.rb', line 32 def piece @piece end |
Class Method Details
.parse(pan_string) ⇒ Modify
Parse a modify notation string into a Modify instance
68 69 70 71 72 73 74 75 76 |
# File 'lib/sashite/pan/action/modify.rb', line 68 def self.parse(pan_string) raise ::ArgumentError, format(ERROR_INVALID_MODIFY, pan_string) unless valid?(pan_string) parts = pan_string.split(OPERATOR, 2) square = parts[0] piece = parts[1] new(square, piece) end |
.valid?(pan_string) ⇒ Boolean
Check if a string represents a valid modify action
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sashite/pan/action/modify.rb', line 43 def self.valid?(pan_string) return false unless pan_string.is_a?(::String) return false unless pan_string.include?(OPERATOR) parts = pan_string.split(OPERATOR, 2) return false if parts.size != 2 square_part = parts[0] piece_part = parts[1] return false unless ::Sashite::Cell.valid?(square_part) return false unless ::Sashite::Epin.valid?(piece_part) true end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Custom equality comparison
202 203 204 205 206 207 |
# File 'lib/sashite/pan/action/modify.rb', line 202 def ==(other) return false unless other.is_a?(self.class) destination == other.destination && piece == other.piece end |
#capture? ⇒ Boolean
Check if this is a capture action
145 146 147 |
# File 'lib/sashite/pan/action/modify.rb', line 145 def capture? false end |
#drop? ⇒ Boolean
Check if this is a drop action
166 167 168 |
# File 'lib/sashite/pan/action/modify.rb', line 166 def drop? false end |
#drop_action? ⇒ Boolean
Check if this is a drop action (drop or drop_capture)
194 195 196 |
# File 'lib/sashite/pan/action/modify.rb', line 194 def drop_action? false end |
#drop_capture? ⇒ Boolean
Check if this is a drop capture action
173 174 175 |
# File 'lib/sashite/pan/action/modify.rb', line 173 def drop_capture? false end |
#hash ⇒ Integer
Custom hash implementation for use in collections
215 216 217 |
# File 'lib/sashite/pan/action/modify.rb', line 215 def hash [self.class, destination, piece].hash end |
#modify? ⇒ Boolean
Check if this is a modify action
180 181 182 |
# File 'lib/sashite/pan/action/modify.rb', line 180 def modify? true end |
#move? ⇒ Boolean
Check if this is a move action
138 139 140 |
# File 'lib/sashite/pan/action/modify.rb', line 138 def move? false end |
#movement? ⇒ Boolean
Check if this is a movement action
187 188 189 |
# File 'lib/sashite/pan/action/modify.rb', line 187 def movement? false end |
#pass? ⇒ Boolean
Check if this is a pass action
131 132 133 |
# File 'lib/sashite/pan/action/modify.rb', line 131 def pass? false end |
#source ⇒ nil
Get the source coordinate
107 108 109 |
# File 'lib/sashite/pan/action/modify.rb', line 107 def source nil end |
#special? ⇒ Boolean
Check if this is a special action
152 153 154 |
# File 'lib/sashite/pan/action/modify.rb', line 152 def special? false end |
#static_capture? ⇒ Boolean
Check if this is a static capture action
159 160 161 |
# File 'lib/sashite/pan/action/modify.rb', line 159 def static_capture? false end |
#to_s ⇒ String
Convert the action to its PAN string representation
124 125 126 |
# File 'lib/sashite/pan/action/modify.rb', line 124 def to_s "#{destination}#{OPERATOR}#{piece}" end |
#transformation ⇒ nil
Get the transformation piece
114 115 116 |
# File 'lib/sashite/pan/action/modify.rb', line 114 def transformation nil end |
#type ⇒ Symbol
Get the action type
100 101 102 |
# File 'lib/sashite/pan/action/modify.rb', line 100 def type TYPE end |