Class: SymbolMatrix::Serialization

Inherits:
Object
  • Object
show all
Defined in:
lib/symbolmatrix/serialization.rb

Class Method Summary collapse

Class Method Details

.parse(serialization) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/symbolmatrix/serialization.rb', line 3

def self.parse serialization
  result = SymbolMatrix.new
  return result if serialization.length == 0
  
  if serialization.include? " "
    serialization.split(" ").each do |command|
      result = result.recursive_merge parse command
    end
  else
    parts = serialization.split ":"
    unless parts.first.include? "."          
      begin
        parts[1] = Integer parts.last
      rescue ArgumentError => e
      end
      result.merge! parts.first => parts.last
    else
      the_key = serialization[0..serialization.index(".") -1]
      result[the_key] = parse serialization[serialization.index(".")+1..-1]
    end
  end
  result
end