class Sashite::GAN::Abbr
The piece's abbreviation.
Attributes
type[R]
The piece's type.
@!attribute [r] type
@return [String] The type of the piece.
Public Class Methods
new(type, is_promoted:, is_king:)
click to toggle source
# File lib/sashite/gan/abbr.rb, line 13 def initialize(type, is_promoted:, is_king:) @type = TypeString(type) @is_promoted = Boolean(is_promoted) @is_king = Boolean(is_king) freeze end
Public Instance Methods
==(other)
click to toggle source
# File lib/sashite/gan/abbr.rb, line 43 def ==(other) other.to_s == to_s end
eql?(other)
click to toggle source
# File lib/sashite/gan/abbr.rb, line 47 def eql?(other) self == other end
inspect()
click to toggle source
# File lib/sashite/gan/abbr.rb, line 39 def inspect to_s end
king?()
click to toggle source
@return [Boolean] Is the piece a king?
# File lib/sashite/gan/abbr.rb, line 22 def king? @is_king end
promoted?()
click to toggle source
@return [Boolean] Is the piece promoted?
# File lib/sashite/gan/abbr.rb, line 27 def promoted? @is_promoted end
to_s()
click to toggle source
@return [String] The abbreviation of the piece.
# File lib/sashite/gan/abbr.rb, line 32 def to_s str = type str = "-#{str}" if king? str = "+#{str}" if promoted? str end
Private Instance Methods
Boolean(arg)
click to toggle source
Ensures `arg` is a boolean, and returns it. Otherwise, raises a
`TypeError`.
# File lib/sashite/gan/abbr.rb, line 57 def Boolean(arg) raise ::TypeError, arg.class.inspect unless [false, true].include?(arg) arg end
TypeString(arg)
click to toggle source
Ensures `arg` is a type, and returns it. Otherwise, raises an error.
# File lib/sashite/gan/abbr.rb, line 64 def TypeString(arg) raise ::TypeError, arg.class.inspect unless arg.is_a?(::String) raise Error::Type, arg.inspect unless arg.match?(/\A[a-z]{1,2}\z/i) arg end