diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-05-10 22:53:51 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-05-10 22:53:51 +0200 |
commit | 62cf22cd59f4933671e188fb8e550299617ba18e (patch) | |
tree | b34022505bf08a4845aa9af0eafc63cc45eb5026 /lib | |
parent | 4a0e3178b90450d2ee65e04b74f7f3f8f0e2830c (diff) | |
download | edoors-ruby-62cf22cd59f4933671e188fb8e550299617ba18e.zip edoors-ruby-62cf22cd59f4933671e188fb8e550299617ba18e.tar.gz |
Room: implement #to_json and #self.json_create
Diffstat (limited to 'lib')
-rw-r--r-- | lib/evendoors/room.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/evendoors/room.rb b/lib/evendoors/room.rb index ce53602..151cd8a 100644 --- a/lib/evendoors/room.rb +++ b/lib/evendoors/room.rb @@ -13,6 +13,29 @@ module EvenDoors @parent.add_spot self if @parent end # + def to_json *a + { + 'kls' => self.class.name, + 'name' => @name, + 'spots' => @spots, + 'links' => @links + }.to_json *a + end + # + def self.json_create o + raise EvenDoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name + room = self.new o['name'] + o['spots'].each do |name,spot| + room.add_spot eval( spot['kls'] ).json_create(spot) + end + o['links'].each do |src,links| + links.each do |link| + room.add_link EvenDoors::Link.json_create(link) + end + end + room + end + # def add_spot s raise EvenDoors::Exception.new "Spot #{s.name} already has #{s.parent.name} as parent" if not s.parent.nil? and s.parent!=self raise EvenDoors::Exception.new "Spot #{s.name} already exists in #{path}" if @spots.has_key? s.name |