Module: ListDeserializer

Defined in:
lib/rubyslim/list_deserializer.rb

Defined Under Namespace

Classes: Deserializer, SyntaxError

Class Method Summary collapse

Class Method Details

.deserialize(string) ⇒ Object

De-serialize the given string, and return a Ruby-native list. Raises a SyntaxError if the string is empty or badly-formatted.

Raises:



9
10
11
12
13
14
15
# File 'lib/rubyslim/list_deserializer.rb', line 9

def self.deserialize(string)
  raise SyntaxError.new("Can't deserialize null") if string.nil?
  raise SyntaxError.new("Can't deserialize empty string") if string.empty?
  raise SyntaxError.new("Serialized list has no starting [") if string[0..0] != "["
  raise SyntaxError.new("Serialized list has no ending ]") if string[-1..-1] != "]"
  Deserializer.new(string).deserialize
end