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?
18 return false if self.lat < -90 or self.lat > 90
19 return false if self.lon < -180 or self.lon > 180
23 def self.from_node(node)
24 old_node = OldNode.new
25 old_node.latitude = node.latitude
26 old_node.longitude = node.longitude
27 old_node.visible = node.visible
28 old_node.tags = node.tags
29 old_node.timestamp = node.timestamp
30 old_node.user_id = node.user_id
32 old_node.version = node.version
37 doc = OSM::API.new.get_xml_doc
38 doc.root << to_xml_node()
43 el1 = XML::Node.new 'node'
44 el1['id'] = self.id.to_s
45 el1['lat'] = self.lat.to_s
46 el1['lon'] = self.lon.to_s
47 el1['user'] = self.user.display_name if self.user.data_public?
49 self.tags.each do |k,v|
50 el2 = XML::Node.new('tag')
56 el1['visible'] = self.visible.to_s
57 el1['timestamp'] = self.timestamp.xmlschema
58 el1['version'] = self.version.to_s
62 def save_with_dependencies!
64 #not sure whats going on here
65 clear_aggregation_cache
66 clear_association_cache
68 @attributes.update(OldNode.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
70 self.tags.each do |k,v|
75 tag.version = self.version
83 OldNodeTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
87 @tags = Hash.new unless @tags
96 Tags.split(self.tags) do |k,v|
102 # Pretend we're not in any ways
107 # Pretend we're not in any relations
108 def containing_relation_members