X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/76df341f66b8ecdcb129d783245c8eabe37e2152..bce2c88336880c96b24b5ddd9e835528da27ddea:/app/models/trace.rb diff --git a/app/models/trace.rb b/app/models/trace.rb index 92cc39678..7097e0973 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -76,6 +76,32 @@ class Trace < ActiveRecord::Base return `file -bi #{trace_name}`.chomp end + def extension_name + filetype = `file -bz #{trace_name}`.chomp + gzipped = filetype =~ /gzip compressed/ + bzipped = filetype =~ /bzip2 compressed/ + zipped = filetype =~ /Zip archive/ + tarred = filetype =~ /tar archive/ + + if tarred and gzipped then + extension = ".tar.gz" + elsif tarred and bzipped then + extension = ".tar.bz2" + elsif tarred + extension = ".tar" + elsif gzipped + extension = ".gpx.gz" + elsif bzipped + extension = ".gpx.bz2" + elsif zipped + extension = ".zip" + else + extension = ".gpx" + end + + return extension + end + def to_xml doc = OSM::API.new.get_xml_doc doc.root << to_xml_node()