Class: FEEN::Parser::Square
- Inherits:
-
Object
- Object
- FEEN::Parser::Square
- Defined in:
- lib/feen/parser/square.rb
Overview
The square class.
Instance Method Summary collapse
-
#initialize(board) ⇒ Square
constructor
A new instance of Square.
-
#to_a ⇒ Array
The list of squares on the board.
-
#to_h ⇒ Hash
The index of each piece on the board.
Constructor Details
#initialize(board) ⇒ Square
Returns a new instance of Square.
32 33 34 |
# File 'lib/feen/parser/square.rb', line 32 def initialize(board) @board = board end |
Instance Method Details
#to_a ⇒ Array
Returns The list of squares on the board.
37 38 39 40 41 |
# File 'lib/feen/parser/square.rb', line 37 def to_a @board .split(%r{[/,]+}) .flat_map { |str| row(str) } end |
#to_h ⇒ Hash
Returns The index of each piece on the board.
44 45 46 47 48 49 50 51 52 |
# File 'lib/feen/parser/square.rb', line 44 def to_h to_a .each_with_index .inject({}) do |h, (v, i)| next h if v.nil? h.merge(i => v) end end |