1 class OldNode < GeoRecord
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
12 errors.add_to_base("Node is not in the world") unless in_world?
16 return false if self.lat < -90 or self.lat > 90
17 return false if self.lon < -180 or self.lon > 180
21 def self.from_node(node)
22 old_node = OldNode.new
23 old_node.latitude = node.latitude
24 old_node.longitude = node.longitude
25 old_node.visible = node.visible
26 old_node.tags = node.tags
27 old_node.timestamp = node.timestamp
28 old_node.user_id = node.user_id
30 old_node.version = node.version
35 doc = OSM::API.new.get_xml_doc
36 doc.root << to_xml_node()
41 el1 = XML::Node.new 'node'
42 el1['id'] = self.id.to_s
43 el1['lat'] = self.lat.to_s
44 el1['lon'] = self.lon.to_s
45 el1['user'] = self.user.display_name if self.user.data_public?
47 self.tags.each do |k,v|
48 el2 = XML::Node.new('tag')
54 el1['visible'] = self.visible.to_s
55 el1['timestamp'] = self.timestamp.xmlschema
56 el1['version'] = self.version.to_s
60 def save_with_dependencies!
62 #not sure whats going on here
63 clear_aggregation_cache
64 clear_association_cache
66 @attributes.update(OldNode.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
68 self.tags.each do |k,v|
73 tag.version = self.version
81 OldNodeTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
85 @tags = Hash.new unless @tags