Extract common code for parsing floats

This commit is contained in:
Tom Hughes 2013-06-24 22:44:17 +01:00
parent 9d2fed811f
commit f03c8637f7
3 changed files with 11 additions and 20 deletions

View file

@ -550,6 +550,13 @@ module OSM
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'