Class: PGN::Serializer
- Inherits:
-
Object
- Object
- PGN::Serializer
- 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.
Instance Method Summary collapse
-
#initialize(game) ⇒ Serializer
constructor
A new instance of Serializer.
-
#to_s ⇒ String
A canonical PGN string ending with a trailing newline.
Constructor Details
#initialize(game) ⇒ Serializer
Returns a new instance of Serializer.
14 15 16 |
# File 'lib/pgn/serializer.rb', line 14 def initialize(game) @game = game end |
Instance Method Details
#to_s ⇒ String
Returns 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 |