]> git.openstreetmap.org Git - rails.git/blob - app/models/temp_old_node.rb
adds a temporary old_node object for use during migration
[rails.git] / app / models / temp_old_node.rb
1 class TempOldNode < ActiveRecord::Base
2   set_table_name 'temp_nodes'
3   
4   validates_presence_of :user_id, :timestamp
5   validates_inclusion_of :visible, :in => [ true, false ]
6   validates_numericality_of :latitude, :longitude
7   validate :validate_position
8
9   belongs_to :user
10  
11   def validate_position
12     errors.add_to_base("Node is not in the world") unless in_world?
13   end
14
15   def in_world?
16     return true
17   end
18
19   def self.from_node(node)
20     old_node = OldNode.new
21     old_node.latitude = node.latitude
22     old_node.longitude = node.longitude
23     old_node.visible = node.visible
24     old_node.tags = node.tags
25     old_node.timestamp = node.timestamp
26     old_node.user_id = node.user_id
27     old_node.id = node.id
28     return old_node
29   end
30
31   def to_xml_node
32     el1 = XML::Node.new 'node'
33     el1['id'] = self.id.to_s
34     el1['lat'] = self.lat.to_s
35     el1['lon'] = self.lon.to_s
36     el1['user'] = self.user.display_name if self.user.data_public?
37
38     Tags.split(self.tags) do |k,v|
39       el2 = XML::Node.new('tag')
40       el2['k'] = k.to_s
41       el2['v'] = v.to_s
42       el1 << el2
43     end
44
45     el1['visible'] = self.visible.to_s
46     el1['timestamp'] = self.timestamp.xmlschema
47     return el1
48   end
49
50 end