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(problem_data) ⇒ Solve::Problem
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/solve/solver/serializer.rb', line 45 def deserialize(problem_data) unless problem_data.is_a?(Hash) problem_data = JSON.parse(problem_data.to_s) end graph_spec = problem_data["graph"] demands_spec = problem_data["demands"] graph = load_graph(graph_spec) demands = load_demands(demands_spec) Solve::Problem.new(graph, demands) end |
#serialize(problem) ⇒ String
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/solve/solver/serializer.rb', line 31 def serialize(problem) graph = problem.graph demands = problem.demands graph_hash = format_graph(graph) demands_hash = format_demands(demands) problem_data = graph_hash.merge(demands_hash) problem_data.to_json end |