Class: Sashite::GAN::Abbr

Inherits:
Object
  • Object
show all
Defined in:
lib/sashite/gan/abbr.rb

Overview

The piece’s abbreviation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, is_promoted:, is_king:) ⇒ Abbr

Returns a new instance of Abbr.



13
14
15
16
17
18
19
# 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

Instance Attribute Details

#typeObject (readonly)

The piece’s type.



11
12
13
# File 'lib/sashite/gan/abbr.rb', line 11

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/sashite/gan/abbr.rb', line 43

def ==(other)
  other.to_s == to_s
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/sashite/gan/abbr.rb', line 47

def eql?(other)
  self == other
end

#inspectObject



39
40
41
# File 'lib/sashite/gan/abbr.rb', line 39

def inspect
  to_s
end

#king?Boolean

Returns Is the piece a king?.

Returns:

  • (Boolean)

    Is the piece a king?



22
23
24
# File 'lib/sashite/gan/abbr.rb', line 22

def king?
  @is_king
end

#promoted?Boolean

Returns Is the piece promoted?.

Returns:

  • (Boolean)

    Is the piece promoted?



27
28
29
# File 'lib/sashite/gan/abbr.rb', line 27

def promoted?
  @is_promoted
end

#to_sString

Returns The abbreviation of the piece.

Returns:

  • (String)

    The abbreviation of the piece.



32
33
34
35
36
37
# File 'lib/sashite/gan/abbr.rb', line 32

def to_s
  str = type
  str = "-#{str}" if king?
  str = "+#{str}" if promoted?
  str
end