Class: Egd::FenBuilder
- Inherits:
-
Object
- Object
- Egd::FenBuilder
- Defined in:
- lib/egd/fen_builder.rb
Constant Summary collapse
- NULL_FEN =
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1".freeze
Instance Attribute Summary collapse
-
#move ⇒ Object
readonly
This service takes in a FEN string and a chess move in algebraic notation.
-
#start_fen ⇒ Object
readonly
This service takes in a FEN string and a chess move in algebraic notation.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(start_fen: nil, move: nil) ⇒ FenBuilder
constructor
Egd::FenBuilder.new(start_fen: nil, move:).call.
Constructor Details
#initialize(start_fen: nil, move: nil) ⇒ FenBuilder
Egd::FenBuilder.new(start_fen: nil, move:).call
11 12 13 14 |
# File 'lib/egd/fen_builder.rb', line 11 def initialize(start_fen: nil, move: nil) @start_fen = start_fen || NULL_FEN @move = move.to_s.gsub(%r'\A\d+\.\s*\.*\s*', "") end |
Instance Attribute Details
#move ⇒ Object (readonly)
This service takes in a FEN string and a chess move in algebraic notation. Outputs the FEN of the resulting position
6 7 8 |
# File 'lib/egd/fen_builder.rb', line 6 def move @move end |
#start_fen ⇒ Object (readonly)
This service takes in a FEN string and a chess move in algebraic notation. Outputs the FEN of the resulting position
6 7 8 |
# File 'lib/egd/fen_builder.rb', line 6 def start_fen @start_fen end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/egd/fen_builder.rb', line 16 def call @fen ||= ( move != "" ? PGN::FEN.new(start_fen).to_position.move(move).to_fen.to_s : @start_fen ) end |