+
+ 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)
+ sql_for_distance = gc.sql_for_distance("home_lat", "home_lon")
+ nearby = User.find(:all,
+ :conditions => ["id != ? AND status IN (\'active\', \'confirmed\') AND data_public = ? AND #{sql_for_distance} <= ?", id, true, radius],
+ :order => sql_for_distance, :limit => num)
+ else
+ nearby = []