Module: Chess::UTF8Notation

Defined in:
lib/chess/utf8_notation.rb

Overview

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, for example:

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

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

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' => ''
}

Instance Method Summary collapse

Instance Method Details

#to_utf8Object

Replace the piece identifier characters with UTF8 chess characters



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

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