api06: Preliminary support for diff uploading. This will not return anything
[rails.git] / app / models / relation.rb
index ec8c92c927a6239a4c0cb4320915dec1ba286887..2c155e9e1f73772b397285cc19562c7f82f01411 100644 (file)
@@ -16,32 +16,38 @@ class Relation < ActiveRecord::Base
       p.string = xml
       doc = p.parse
 
-      relation = Relation.new
-
       doc.find('//osm/relation').each do |pt|
-        if !create and pt['id'] != '0'
-          relation.id = pt['id'].to_i
-        end
+       relation = Relation.from_xml_node pt, create
+      end
+    rescue
+      relation = nil
+    end
 
-        if create
-          relation.timestamp = Time.now
-          relation.visible = true
-        else
-          if pt['timestamp']
-            relation.timestamp = Time.parse(pt['timestamp'])
-          end
-        end
+    return relation
+  end
 
-        pt.find('tag').each do |tag|
-          relation.add_tag_keyval(tag['k'], tag['v'])
-        end
+  def self.from_xml_node(pt, create=false)
+    relation = Relation.new
 
-        pt.find('member').each do |member|
-          relation.add_member(member['type'], member['ref'], member['role'])
-        end
+    if !create and pt['id'] != '0'
+      relation.id = pt['id'].to_i
+    end
+
+    if create
+      relation.timestamp = Time.now
+      relation.visible = true
+    else
+      if pt['timestamp']
+       relation.timestamp = Time.parse(pt['timestamp'])
       end
-    rescue
-      relation = nil
+    end
+
+    pt.find('tag').each do |tag|
+      relation.add_tag_keyval(tag['k'], tag['v'])
+    end
+
+    pt.find('member').each do |member|
+      relation.add_member(member['type'], member['ref'], member['role'])
     end
 
     return relation