Module: Chess::Save
- Includes:
- FenCodeFromBoard, Serializer
- Included in:
- Game
- Defined in:
- lib/chess/save/save.rb,
lib/chess/save/serializer.rb,
lib/chess/save/fen_from_board.rb
Overview
create fen_code from board
Defined Under Namespace
Modules: FenCodeFromBoard, Serializer
Constant Summary
Constants included from Serializer
Instance Method Summary collapse
-
#read ⇒ Hash
reads and returns saves from the save file.
-
#save(name, data) ⇒ void
writes a save to the save file.
Methods included from FenCodeFromBoard
#fen_piece_placement, #fen_piece_placement_by_rank, #generate_fen_code, #letter_of
Methods included from Serializer
Instance Method Details
#read ⇒ Hash
reads and returns saves from the save file. Chess::Save::Serializer#unserialize is used to unserialize the data.
26 27 28 29 |
# File 'lib/chess/save/save.rb', line 26 def read contents = File.read(SAVE_PATH) unserialize(contents) end |
#save(name, data) ⇒ void
This method returns an undefined value.
writes a save to the save file
15 16 17 18 19 20 |
# File 'lib/chess/save/save.rb', line 15 def save(name, data) file_data = read file_data[name] = data new_data_serialized = serialize(file_data) File.write(SAVE_PATH, new_data_serialized) end |