Sha256: b00b2ead1f6864fa11d5f416bc79cb477ea30713befbea9cce2837af9632dea3
Contents?: true
Size: 990 Bytes
Versions: 4
Compression:
Stored size: 990 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. # @example # :001 > require 'chess/utf8_notation' # => true # :002 > 'Qf7#'.to_utf8 # => '♕f7#' # # @note 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. # @return [String] 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.2.2 | lib/chess/utf8_notation.rb |
chess-0.2.1 | lib/chess/utf8_notation.rb |
chess-0.2.0 | lib/chess/utf8_notation.rb |
chess-0.1.4 | lib/chess/utf8_notation.rb |