Class: PGN::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/pgn/serializer.rb

Overview

Serializer converts a Game into a canonical PGN string.

Serialization is purely structural: it reads tags, moves, comments, annotations, variations, and result from the game and emits valid PGN without replaying any moves on a board. Move numbering state is seeded from game.starting_position so games starting from a FEN tag (e.g. with black to move) are numbered correctly.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(game) ⇒ Serializer

Returns a new instance of Serializer.

Parameters:



14
15
16
# File 'lib/pgn/serializer.rb', line 14

def initialize(game)
  @game = game
end

Instance Method Details

#to_sString

Returns a canonical PGN string ending with a trailing newline.

Returns:

  • (String)

    a canonical PGN string ending with a trailing newline



19
20
21
# File 'lib/pgn/serializer.rb', line 19

def to_s
  tag_section + "\n\n" + movetext_section + "\n"
end