Module: Crucigrama::Crossword::Serializable
- Included in:
- Crucigrama::Crossword
- Defined in:
- lib/crucigrama/crossword/serializable.rb
Overview
This module provides methods to serialize a crossword
Instance Method Summary collapse
-
#attributes ⇒ Hash
A hash with the dimensions, grid and serialized definitions of a crossword.
-
#serialized_definitions ⇒ Hash
The definitions of a crossword in a JSON-compatible format.
-
#to_json ⇒ String
The attributes of the crossword as returned by #attributes in a JSON string.
Instance Method Details
#attributes ⇒ Hash
Returns a hash with the dimensions, grid and serialized definitions of a crossword.
7 8 9 10 11 12 13 |
# File 'lib/crucigrama/crossword/serializable.rb', line 7 def attributes { :dimensions => dimensions, :grid => grid, :definitions => serialized_definitions } end |
#serialized_definitions ⇒ Hash
Returns the definitions of a crossword in a JSON-compatible format.
16 17 18 19 20 21 22 23 24 |
# File 'lib/crucigrama/crossword/serializable.rb', line 16 def serialized_definitions Hash[definitions.collect do |direction, defs| [direction, Hash[defs.collect do |line_number, line_defs| [line_number.to_s, Hash[line_defs.collect do |pos_number, definition| [pos_number.to_s, definition] end]] end]] end] end |
#to_json ⇒ String
Returns the attributes of the crossword as returned by #attributes in a JSON string.
27 28 29 |
# File 'lib/crucigrama/crossword/serializable.rb', line 27 def to_json MultiJson.encode(attributes) end |