raise OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
# Extract the arguments
- begin
- lon = Float(params[:lon])
- rescue
- raise OSM::APIBadUserInput.new("lon was not a number")
- end
- begin
- lat = Float(params[:lat])
- rescue
- raise OSM::APIBadUserInput.new("lat was not a number")
- end
+ lon = OSM.parse_float(params[:lon], OSM::APIBadUserInput, "lon was not a number")
+ lat = OSM.parse_float(params[:lat], OSM::APIBadUserInput, "lat was not a number")
comment = params[:text]
# Include in a transaction to ensure that there is always a note_comment for every note
raise OSM::APIBadXMLError.new("node", pt, "lat missing") if pt['lat'].nil?
raise OSM::APIBadXMLError.new("node", pt, "lon missing") if pt['lon'].nil?
- begin
- node.lat = Float(pt['lat'])
- rescue
- raise OSM::APIBadXMLError.new("node", pt, "lat not a number")
- end
- begin
- node.lon = Float(pt['lon'])
- rescue
- raise OSM::APIBadXMLError.new("node", pt, "lon not a number")
- end
+ node.lat = OSM.parse_float(pt['lat'], OSM::APIBadXMLError, "node", pt, "lat not a number")
+ node.lon = OSM.parse_float(pt['lon'], OSM::APIBadXMLError, "node", pt, "lon not a number")
raise OSM::APIBadXMLError.new("node", pt, "Changeset id is missing") if pt['changeset'].nil?
node.changeset_id = pt['changeset'].to_i
return nil
end
+ # Parse a float, raising a specified exception on failure
+ def self.parse_float(str, klass, *args)
+ Float(str)
+ rescue
+ raise klass.new(*args)
+ end
+
# Construct a random token of a given length
def self.make_token(length = 30)
chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'