Module: NotationParser

Defined in:
lib/helpers/notation_parser.rb

Class Method Summary collapse

Class Method Details

.encode_notation(coords) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/helpers/notation_parser.rb', line 13

def self.encode_notation(coords)
  row, col = coords

  return nil unless col >= 0 && col < 8 && row >= 0 && row < 8

  col = (col + 97).chr
  row = (8 - row).to_s
  col + row
end

.parse_notation(square) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/helpers/notation_parser.rb', line 4

def self.parse_notation(square)
  col = square[0].downcase.ord - 97
  row = 7 - (square[1].to_i - 1)

  return nil unless col >= 0 && col < 8 && row >= 0 && row < 8

  [row, col]
end