+ def to_xml
+ doc = OSM::API.new.get_xml_doc
+ doc.root << to_xml_node()
+ return doc
+ end
+
+ def to_xml_node
+ el1 = XML::Node.new 'user'
+ el1['display_name'] = self.display_name.to_s
+ el1['account_created'] = self.creation_time.xmlschema
+ if self.home_lat and self.home_lon
+ home = XML::Node.new 'home'
+ home['lat'] = self.home_lat.to_s
+ home['lon'] = self.home_lon.to_s
+ home['zoom'] = self.home_zoom.to_s
+ el1 << home
+ end
+ return el1
+ end
+
+ def languages
+ attribute_present?(:languages) ? read_attribute(:languages).split(",") : []
+ end
+
+ def languages=(languages)
+ write_attribute(:languages, languages.join(","))
+ end
+
+ def preferred_language
+ languages.find { |l| Language.find(:first, :conditions => { :code => l }) }
+ end
+
+ def preferred_language_from(array)
+ (languages & array.collect { |i| i.to_s }).first
+ end
+
+ def nearby(radius = 50, num = 10)
+ if self.home_lon and self.home_lat
+ gc = OSM::GreatCircle.new(self.home_lat, self.home_lon)
+ bounds = gc.bounds(radius)
+ nearby = User.find(:all, :conditions => ["visible = ? and home_lat between #{bounds[:minlat]} and #{bounds[:maxlat]} and home_lon between #{bounds[:minlon]} and #{bounds[:maxlon]} and data_public = ? and id != #{self.id}", true, true])
+ nearby.delete_if { |u| gc.distance(u.home_lat, u.home_lon) > radius }
+ nearby.sort! { |u1,u2| gc.distance(u1.home_lat, u1.home_lon) <=> gc.distance(u2.home_lat, u2.home_lon) }
+ else
+ nearby = []