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
16 errors.add_to_base("Node is not in the world") unless in_world?
20 return false if self.lat < -90 or self.lat > 90
21 return false if self.lon < -180 or self.lon > 180
25 def self.from_xml(xml, create=false)
33 doc.find('//osm/node').each do |pt|
34 node.lat = pt['lat'].to_f
35 node.lon = pt['lon'].to_f
37 return nil unless node.in_world?
41 node.id = pt['id'].to_i
45 node.visible = pt['visible'] and pt['visible'] == 'true'
48 node.timestamp = Time.now
51 node.timestamp = Time.parse(pt['timestamp'])
57 pt.find('tag').each do |tag|
58 tags << [tag['k'],tag['v']]
61 node.tags = Tags.join(tags)
70 def save_with_history!
72 self.timestamp = Time.now
74 old_node = OldNode.from_node(self)
80 doc = OSM::API.new.get_xml_doc
81 doc.root << to_xml_node()
85 def to_xml_node(user_display_name_cache = nil)
86 el1 = XML::Node.new 'node'
87 el1['id'] = self.id.to_s
88 el1['lat'] = self.lat.to_s
89 el1['lon'] = self.lon.to_s
91 user_display_name_cache = {} if user_display_name_cache.nil?
93 if user_display_name_cache and user_display_name_cache.key?(self.user_id)
94 # use the cache if available
95 elsif self.user.data_public?
96 user_display_name_cache[self.user_id] = self.user.display_name
98 user_display_name_cache[self.user_id] = nil
101 el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
103 Tags.split(self.tags) do |k,v|
104 el2 = XML::Node.new('tag')
110 el1['visible'] = self.visible.to_s
111 el1['timestamp'] = self.timestamp.xmlschema
117 Tags.split(self.tags) do |k,v|