Sha256: 6414fad6b384863e118e44a63d2899f1c387b7a8d56bad17794e1121633c753a
Contents?: true
Size: 967 Bytes
Versions: 4
Compression:
Stored size: 967 Bytes
Contents
module Chess # 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: # <tt>require 'chess/utf8_notation'</tt> module UTF8Notation # Map a piece identifier character with the corresponding UTF8 chess # character UTF8_MAP = { 'P' => '♙', 'R' => '♖', 'N' => '♘', 'B' => '♗', 'Q' => '♕', 'K' => '♔', 'p' => '♟', 'r' => '♜', 'n' => '♞', 'b' => '♝', 'q' => '♛', 'k' => '♚' } # Replace the piece identifier characters with UTF8 chess characters def to_utf8 self.gsub(/[PRNBQKprnbqk]/, UTF8_MAP) end end end String.prepend(Chess::UTF8Notation)
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
chess-0.1.3 | lib/chess/utf8_notation.rb |
chess-0.1.2 | lib/chess/utf8_notation.rb |
chess-0.1.1 | lib/chess/utf8_notation.rb |
chess-0.1.0 | lib/chess/utf8_notation.rb |