Class: Sashite::Cgsn::Status

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(value) ⇒ Status

Create a new status instance

Examples:

Status.new("checkmate")     # => #<Cgsn::Status value="checkmate">
Status.new("resignation")   # => #<Cgsn::Status value="resignation">

Parameters:

  • value (String)

    status value

Raises:

  • (ArgumentError)

    if the value is invalid



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

Parameters:

  • other (Object)

    object to compare with

Returns:

  • (Boolean)

    true if statuses are equal



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

Examples:

Status.new("resignation").explicit_only?  # => true
Status.new("checkmate").explicit_only?    # => false

Returns:

  • (Boolean)

    true if explicit-only



50
51
52
# File 'lib/sashite/cgsn/status.rb', line 50

def explicit_only?
  Cgsn::EXPLICIT_ONLY_STATUSES.include?(@value)
end

#hashInteger

Custom hash implementation for use in collections

Returns:

  • (Integer)

    hash value



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

Examples:

Status.new("checkmate").inferable?     # => true
Status.new("resignation").inferable?   # => false

Returns:

  • (Boolean)

    true if inferable



39
40
41
# File 'lib/sashite/cgsn/status.rb', line 39

def inferable?
  Cgsn::INFERABLE_STATUSES.include?(@value)
end

#to_sString

Convert the status to its string representation

Examples:

Status.new("checkmate").to_s  # => "checkmate"

Returns:

  • (String)

    status value



60
61
62
# File 'lib/sashite/cgsn/status.rb', line 60

def to_s
  @value
end