Class: Egd::FenToBoard
- Inherits:
-
Object
- Object
- Egd::FenToBoard
- Defined in:
- lib/egd/fen_to_board.rb
Constant Summary collapse
- LETTER_VALUES =
%w|_ a b c d e f g h|.freeze
Instance Attribute Summary collapse
-
#fen ⇒ Object
readonly
this service parses a FEN string into a hash-representation of a chess board and pieces So you can do board = Egd::FenToBoard.new(fen_string) board #=> “P” # as in white pawn.
Instance Method Summary collapse
Constructor Details
#initialize(fen) ⇒ FenToBoard
14 15 16 |
# File 'lib/egd/fen_to_board.rb', line 14 def initialize(fen) @fen = fen end |
Instance Attribute Details
#fen ⇒ Object (readonly)
this service parses a FEN string into a hash-representation of a chess board and pieces So you can do board = Egd::FenToBoard.new(fen_string) board #=> “P” # as in white pawn
8 9 10 |
# File 'lib/egd/fen_to_board.rb', line 8 def fen @fen end |
Instance Method Details
#[](square) ⇒ Object
18 19 20 |
# File 'lib/egd/fen_to_board.rb', line 18 def [](square) board_hash[square] end |
#boardline ⇒ Object
22 23 24 25 26 27 |
# File 'lib/egd/fen_to_board.rb', line 22 def boardline # this replaces numbers with corresponding amount of dashes @boardline ||= parsed_fen[:board].gsub(%r'\d') do |match| "-" * match.to_i end.gsub("/", "") end |