Class: Sashite::Feen::Position::PiecePlacement
- Inherits:
-
Object
- Object
- Sashite::Feen::Position::PiecePlacement
- Defined in:
- lib/sashite/feen/position/piece_placement.rb
Overview
Represents the Piece Placement field (Field 1).
Encapsulates board occupancy as segments of placement tokens with preserved separator groups for multi-dimensional boards.
Instance Attribute Summary collapse
-
#segments ⇒ Array<Array>
readonly
Segments containing Integer (empty count) or Epin::Identifier.
-
#separators ⇒ Array<String>
readonly
Separator strings between segments.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Checks equality with another PiecePlacement.
-
#each_segment {|segment| ... } ⇒ Enumerator, self
Iterates over each segment.
-
#hash ⇒ Integer
Returns a hash code.
-
#initialize(segments:, separators:) ⇒ PiecePlacement
constructor
Creates a new PiecePlacement instance.
-
#to_a ⇒ Array
Returns all tokens as a flat array.
-
#to_s ⇒ String
Returns the canonical string representation.
Constructor Details
#initialize(segments:, separators:) ⇒ PiecePlacement
Creates a new PiecePlacement instance.
30 31 32 33 34 35 |
# File 'lib/sashite/feen/position/piece_placement.rb', line 30 def initialize(segments:, separators:) @segments = segments @separators = separators freeze end |
Instance Attribute Details
#segments ⇒ Array<Array> (readonly)
Returns Segments containing Integer (empty count) or Epin::Identifier.
21 22 23 |
# File 'lib/sashite/feen/position/piece_placement.rb', line 21 def segments @segments end |
#separators ⇒ Array<String> (readonly)
Returns Separator strings between segments.
24 25 26 |
# File 'lib/sashite/feen/position/piece_placement.rb', line 24 def separators @separators end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Checks equality with another PiecePlacement.
70 71 72 73 74 |
# File 'lib/sashite/feen/position/piece_placement.rb', line 70 def ==(other) return false unless self.class === other segments == other.segments && separators == other.separators end |
#each_segment {|segment| ... } ⇒ Enumerator, self
Iterates over each segment.
41 42 43 44 45 46 |
# File 'lib/sashite/feen/position/piece_placement.rb', line 41 def each_segment(&block) return segments.each unless block segments.each(&block) self end |
#hash ⇒ Integer
Returns a hash code.
81 82 83 |
# File 'lib/sashite/feen/position/piece_placement.rb', line 81 def hash [segments, separators].hash end |
#to_a ⇒ Array
Returns all tokens as a flat array.
51 52 53 |
# File 'lib/sashite/feen/position/piece_placement.rb', line 51 def to_a segments.flatten end |
#to_s ⇒ String
Returns the canonical string representation.
58 59 60 61 62 63 64 |
# File 'lib/sashite/feen/position/piece_placement.rb', line 58 def to_s segments.map { |segment| segment_to_s(segment) } .zip(separators) .flatten .compact .join end |