Module: Feen::Parser::PiecePlacement
- Defined in:
- lib/feen/parser/piece_placement.rb
Overview
Handles parsing of the piece placement section of a FEEN string
This module is responsible for converting the first field of a FEEN string (piece placement) into a hierarchical array structure representing the board. It supports arbitrary dimensions and handles both pieces (with optional PNN modifiers) and empty squares (represented by numbers).
Constant Summary collapse
- ERRORS =
Simplified error messages
{ invalid_type: "Piece placement must be a string, got %s", empty_string: "Piece placement string cannot be empty", invalid_format: "Invalid piece placement format" }.freeze
- DIMENSION_SEPARATOR =
Dimension separator character
"/"
Class Method Summary collapse
-
.parse(piece_placement_str) ⇒ Array
Parses the piece placement section of a FEEN string.
-
.validate_input(str) ⇒ void
Validates the input string for basic requirements.
Class Method Details
.parse(piece_placement_str) ⇒ Array
Parses the piece placement section of a FEEN string
Converts a FEEN piece placement string into a hierarchical array structure representing the board where empty squares are represented by empty strings and pieces are represented by strings containing their PNN identifier and optional modifiers.
99 100 101 102 |
# File 'lib/feen/parser/piece_placement.rb', line 99 def self.parse(piece_placement_str) validate_input(piece_placement_str) parse_structure(piece_placement_str) end |
.validate_input(str) ⇒ void
This method returns an undefined value.
Validates the input string for basic requirements
Ensures the input is a non-empty string containing only valid FEEN characters. Valid characters include: letters (a-z, A-Z), digits (0-9), and modifiers (+, -, ‘).
124 125 126 127 128 129 130 131 132 |
# File 'lib/feen/parser/piece_placement.rb', line 124 def self.validate_input(str) raise ArgumentError, format(ERRORS[:invalid_type], str.class) unless str.is_a?(String) raise ArgumentError, ERRORS[:empty_string] if str.empty? # Basic format validation return if str.match?(%r{\A[a-zA-Z0-9+\-'/]+\z}) raise ArgumentError, ERRORS[:invalid_format] end |