class Opening
Class that represents a chess Opening
Attributes
eco_code[RW]
moves[RW]
name[RW]
Public Class Methods
new(name, eco_code, moves)
click to toggle source
# File lib/chess_openings/opening.rb, line 8 def initialize(name, eco_code, moves) @name = name @eco_code = eco_code @moves = moves.map! { |move| move.is_a?(String) ? move.to_sym : move } end
Public Instance Methods
==(other)
click to toggle source
Compares two Openings
@param [Opening] other Opening
to be compared @return [Boolean] True if both Openings have same values, false otherwise
# File lib/chess_openings/opening.rb, line 32 def ==(other) @name == other.name && @eco_code == other.eco_code && @moves == other.moves end
to_fen()
click to toggle source
to_h()
click to toggle source
to_pgn()
click to toggle source
Returns PGN formatted String of the Opening
@return [String] String that represents a game where Opening
was used
# File lib/chess_openings/opening.rb, line 39 def to_pgn result = '' index = 1 @moves.each do |move| result += index.odd? ? "#{(index / 2.0).ceil}.#{move}" : " #{move} " index += 1 end result.chop! end