Module: Sashite::GAN::Parser

Defined in:
lib/sashite/gan/parser.rb

Overview

The notation parser.

Class Method Summary collapse

Class Method Details

.call(arg) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sashite/gan/parser.rb', line 10

def self.call(arg)
  raise Error::String, "Invalid: #{arg.inspect}" unless valid?(arg)

  style, abbr = arg.split(SEPARATOR_CHAR)

  Piece.new(
    abbr.delete('-+'),
    is_king: abbr.include?('-'),
    is_promoted: abbr.include?('+'),
    is_topside: style.downcase.eql?(style),
    style: style
  )
end

.valid?(arg) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (::TypeError)


24
25
26
27
28
# File 'lib/sashite/gan/parser.rb', line 24

def self.valid?(arg)
  raise ::TypeError, arg.class.inspect unless arg.is_a?(::String)

  arg.match?(/\A([a-z_]+:\+?-?[a-z]{1,2}|[A-Z_]+:\+?-?[A-Z]{1,2})\z/)
end