1 class OldNode < ActiveRecord::Base
6 validates_presence_of :user_id, :timestamp
7 validates_inclusion_of :visible, :in => [ true, false ]
8 validates_numericality_of :latitude, :longitude
9 validate :validate_position
14 errors.add_to_base("Node is not in the world") unless in_world?
17 def self.from_node(node)
18 old_node = OldNode.new
19 old_node.latitude = node.latitude
20 old_node.longitude = node.longitude
21 old_node.visible = node.visible
22 old_node.tags = node.tags
23 old_node.timestamp = node.timestamp
24 old_node.user_id = node.user_id
26 old_node.version = node.version
31 doc = OSM::API.new.get_xml_doc
32 doc.root << to_xml_node()
37 el1 = XML::Node.new 'node'
38 el1['id'] = self.id.to_s
39 el1['lat'] = self.lat.to_s
40 el1['lon'] = self.lon.to_s
41 el1['user'] = self.user.display_name if self.user.data_public?
43 self.tags.each do |k,v|
44 el2 = XML::Node.new('tag')
50 el1['visible'] = self.visible.to_s
51 el1['timestamp'] = self.timestamp.xmlschema
52 el1['version'] = self.version.to_s
56 def save_with_dependencies!
58 #not sure whats going on here
59 clear_aggregation_cache
60 clear_association_cache
62 @attributes.update(OldNode.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
64 self.tags.each do |k,v|
69 tag.version = self.version
77 OldNodeTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
81 @tags = Hash.new unless @tags
91 Tags.split(self.tags) do |k,v|
97 # Pretend we're not in any ways
102 # Pretend we're not in any relations
103 def containing_relation_members