Class: PGN::Parser

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

Overview

Parser is the public entry point for parsing PGN text into a list of game hashes. It delegates to a concrete backend parser (currently the stdlib Racc + StringScanner parser PgnParser).

The backend class attribute is retained so callers (tests, benchmarks) can substitute an alternative parser responding to new.parse(pgn_string).

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.backendClass

The backend parser class used by PGN.parse.

Returns:

  • (Class)


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

def backend
  @backend
end

Instance Method Details

#parse(input) ⇒ Array<Hash>

Returns one Hash per game, with keys :tags, :result, :moves, :pgn, :comment.

Parameters:

  • input (String)

    the raw PGN text (already force-encoded by the caller, e.g. via PGN.parse).

Returns:

  • (Array<Hash>)

    one Hash per game, with keys :tags, :result, :moves, :pgn, :comment.



24
25
26
# File 'lib/pgn/parser.rb', line 24

def parse(input)
  self.class.backend.new.parse(input)
end