Module: FEEN::Dumper::InHand

Defined in:
lib/feen/dumper/in_hand.rb

Overview

The pieces in hand module.

Class Method Summary collapse

Class Method Details

.dump(piece_names) ⇒ String

Serialize pieces in hand lists into a string.

Examples:

Dump a list of pieces in hand

dump(["S", "b", "g", "g", "g", "g", "n", "n", "n", "n", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "r", "r", "s"])
# => "S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s"

Dump an empty list of pieces in hand

dump([])
# => "-"

Parameters:

  • piece_names (Array)

    A list of pieces in hand.

Returns:

  • (String)

    A string representing the pieces in hand.



20
21
22
23
24
# File 'lib/feen/dumper/in_hand.rb', line 20

def self.dump(piece_names)
  return "-" if piece_names.empty?

  piece_names.sort.join(",")
end