Class: Sashite::Cgsn::Status
- Inherits:
-
Object
- Object
- Sashite::Cgsn::Status
- Defined in:
- lib/sashite/cgsn/status.rb
Overview
Represents a status value in CGSN (Chess Game Status Notation) format.
A status consists of a lowercase string with optional underscore separators. Each status represents an observable game state that can be recorded independently of competitive interpretation.
All instances are immutable.
Constant Summary collapse
- ERROR_INVALID_STATUS =
Error message for invalid status values
"Invalid CGSN status: %s"
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Custom equality comparison.
-
#explicit_only? ⇒ Boolean
Check if the status requires explicit declaration.
-
#hash ⇒ Integer
Custom hash implementation for use in collections.
-
#inferable? ⇒ Boolean
Check if the status can be inferred from position analysis.
-
#initialize(value) ⇒ Status
constructor
Create a new status instance.
-
#to_s ⇒ String
Convert the status to its string representation.
Constructor Details
#initialize(value) ⇒ Status
Create a new status instance
24 25 26 27 28 29 30 |
# File 'lib/sashite/cgsn/status.rb', line 24 def initialize(value) @value = String(value) raise ::ArgumentError, format(ERROR_INVALID_STATUS, @value) unless Cgsn::STATUSES.include?(@value) freeze end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Custom equality comparison
68 69 70 71 72 |
# File 'lib/sashite/cgsn/status.rb', line 68 def ==(other) return false unless other.is_a?(self.class) to_s == other.to_s end |
#explicit_only? ⇒ Boolean
Check if the status requires explicit declaration
50 51 52 |
# File 'lib/sashite/cgsn/status.rb', line 50 def explicit_only? Cgsn::EXPLICIT_ONLY_STATUSES.include?(@value) end |
#hash ⇒ Integer
Custom hash implementation for use in collections
80 81 82 |
# File 'lib/sashite/cgsn/status.rb', line 80 def hash [self.class, @value].hash end |
#inferable? ⇒ Boolean
Check if the status can be inferred from position analysis
39 40 41 |
# File 'lib/sashite/cgsn/status.rb', line 39 def inferable? Cgsn::INFERABLE_STATUSES.include?(@value) end |
#to_s ⇒ String
Convert the status to its string representation
60 61 62 |
# File 'lib/sashite/cgsn/status.rb', line 60 def to_s @value end |