Class: Sashite::GAN::Abbr
- Inherits:
-
Object
- Object
- Sashite::GAN::Abbr
- Defined in:
- lib/sashite/gan/abbr.rb
Overview
The piece’s abbreviation.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
The piece’s type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(type, is_promoted:, is_king:) ⇒ Abbr
constructor
A new instance of Abbr.
- #inspect ⇒ Object
-
#king? ⇒ Boolean
Is the piece a king?.
-
#promoted? ⇒ Boolean
Is the piece promoted?.
-
#to_s ⇒ String
The abbreviation of the piece.
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
#type ⇒ Object (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
47 48 49 |
# File 'lib/sashite/gan/abbr.rb', line 47 def eql?(other) self == other end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/sashite/gan/abbr.rb', line 39 def inspect to_s end |
#king? ⇒ Boolean
Returns 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?.
27 28 29 |
# File 'lib/sashite/gan/abbr.rb', line 27 def promoted? @is_promoted end |
#to_s ⇒ String
Returns 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 |