Module: Save::Serializer
- Included in:
- Save
- Defined in:
- lib/chess/save/serializer.rb
Overview
Serializer for saving to file and reading from file.
Constant Summary collapse
- SERIALIZER =
Serializing format used for save and load
JSON
Instance Method Summary collapse
-
#serialize(name, code) ⇒ String
serializes with name as key and code as value for a hash.
-
#unserialize(string) ⇒ Hash
unserializes the given string and returns the Hash with save’s name as keys and FEN code as values.
Instance Method Details
#serialize(name, code) ⇒ String
serializes with name as key and code as value for a hash
13 14 15 16 17 |
# File 'lib/chess/save/serializer.rb', line 13 def serialize(name, code) hash = {} hash[name] = code SERIALIZER.dump hash end |
#unserialize(string) ⇒ Hash
unserializes the given string and returns the Hash with save’s name as keys and FEN code as values.
23 24 25 |
# File 'lib/chess/save/serializer.rb', line 23 def unserialize(string) SERIALIZER.parse string end |