4 set_table_name 'current_nodes'
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
11 has_many :old_nodes, :foreign_key => :id
15 errors.add_to_base("Node is not in the world") unless in_world?
19 return false if self.lat < -90 or self.lat > 90
20 return false if self.lon < -180 or self.lon > 180
24 def self.from_xml(xml, create=false)
32 doc.find('//osm/node').each do |pt|
33 node.lat = pt['lat'].to_f
34 node.lon = pt['lon'].to_f
36 return nil unless node.in_world?
40 node.id = pt['id'].to_i
44 node.visible = pt['visible'] and pt['visible'] == 'true'
47 node.timestamp = Time.now
50 node.timestamp = Time.parse(pt['timestamp'])
56 pt.find('tag').each do |tag|
57 tags << [tag['k'],tag['v']]
60 node.tags = Tags.join(tags)
69 def save_with_history!
71 self.timestamp = Time.now
73 old_node = OldNode.from_node(self)
79 doc = OSM::API.new.get_xml_doc
80 doc.root << to_xml_node()
84 def to_xml_node(user_display_name_cache = nil)
85 el1 = XML::Node.new 'node'
86 el1['id'] = self.id.to_s
87 el1['lat'] = self.lat.to_s
88 el1['lon'] = self.lon.to_s
90 user_display_name_cache = {} if user_display_name_cache.nil?
92 if user_display_name_cache and user_display_name_cache.key?(self.user_id)
93 # use the cache if available
94 elsif self.user.data_public?
95 user_display_name_cache[self.user_id] = self.user.display_name
97 user_display_name_cache[self.user_id] = nil
100 el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
102 Tags.split(self.tags) do |k,v|
103 el2 = XML::Node.new('tag')
109 el1['visible'] = self.visible.to_s
110 el1['timestamp'] = self.timestamp.xmlschema
116 Tags.split(self.tags) do |k,v|