Module: Chess::UTF8Notation

Defined in:
lib/chess/utf8_notation.rb

Overview

Note:

To use this utility explicit require is needed: require 'chess/utf8_notation'

With this module is possible call the method #to_utf8 on a string. This method convert the chess piece identifier character into UTF8 chess character.

Examples:

:001 > require 'chess/utf8_notation'
=> true
:002 > 'Qf7#'.to_utf8
=> '♕f7#'

Constant Summary collapse

UTF8_MAP =

Map a piece identifier character with the corresponding UTF8 chess character

{
  'P' => '',
  'R' => '',
  'N' => '',
  'B' => '',
  'Q' => '',
  'K' => '',
  'p' => '',
  'r' => '',
  'n' => '',
  'b' => '',
  'q' => '',
  'k' => ''
}.freeze

Instance Method Summary collapse

Instance Method Details

#to_utf8String

Replace the piece identifier characters with UTF8 chess characters.

Returns:

  • (String)


33
34
35
# File 'lib/chess/utf8_notation.rb', line 33

def to_utf8
  self.gsub(/[PRNBQKprnbqk]/, UTF8_MAP)
end