Class: Solve::Solver::Serializer
- Inherits:
-
Object
- Object
- Solve::Solver::Serializer
- Defined in:
- lib/solve/solver/serializer.rb
Instance Method Summary collapse
Instance Method Details
#deserialize(solver) ⇒ Solve::Solver
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/solve/solver/serializer.rb', line 21 def deserialize(solver) unless solver.is_a?(Hash) solver = JSON.parse(solver.to_s) end graph_spec = solver["graph"] demands_spec = solver["demands"] graph = load_graph(graph_spec) demands = load_demands(demands_spec) Solve::Solver.new(graph, demands) end |
#serialize(solver) ⇒ String
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/solve/solver/serializer.rb', line 7 def serialize(solver) graph = solver.graph demands = solver.demands graph_hash = format_graph(graph) demands_hash = format_demands(demands) problem = graph_hash.merge(demands_hash) problem.to_json end |