Skip to content

Commit 28ffaf7

Browse files
committed
Replace points method of trace file with read file method
1 parent c050029 commit 28ffaf7

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

app/models/trace.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def import
203203
logger.info("GPX Import importing #{name} (#{id}) from #{user.email}")
204204

205205
file.open do |file|
206-
gpx = GPX::File.new(file.path, :maximum_points => Settings.max_trace_size)
206+
gpx = GPX::File.new(:maximum_points => Settings.max_trace_size)
207207

208208
f_lat = 0
209209
f_lon = 0
@@ -212,7 +212,7 @@ def import
212212
# If there are any existing points for this trace then delete them
213213
Tracepoint.where(:trace => id).delete_all
214214

215-
gpx.points.each_slice(1_000) do |points|
215+
gpx.read(file.path).each_slice(1_000) do |points|
216216
# Gather the trace points together for a bulk import
217217
tracepoints = []
218218

lib/gpx.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ class File
66

77
attr_reader :possible_points, :actual_points, :tracksegs
88

9-
def initialize(file, options = {})
10-
@file = file
9+
def initialize(options = {})
1110
@maximum_points = options[:maximum_points] || Float::INFINITY
1211
@possible_points = 0
1312
@actual_points = 0
@@ -16,19 +15,19 @@ def initialize(file, options = {})
1615
@lons = []
1716
end
1817

19-
def points(&block)
20-
return enum_for(:points) unless block
18+
def read(file, &block)
19+
return enum_for(:read, file) unless block
2120

2221
begin
23-
Archive::Reader.open_filename(@file).each_entry_with_data do |entry, data|
22+
Archive::Reader.open_filename(file).each_entry_with_data do |entry, data|
2423
parse_file(XML::Reader.string(data), &block) if entry.regular?
2524
end
2625
rescue Archive::Error
27-
io = ::File.open(@file)
26+
io = ::File.open(file)
2827

2928
case Marcel::MimeType.for(io)
30-
when "application/gzip" then io = Zlib::GzipReader.open(@file)
31-
when "application/x-bzip" then io = Bzip2::FFI::Reader.open(@file)
29+
when "application/gzip" then io = Zlib::GzipReader.open(file)
30+
when "application/x-bzip" then io = Bzip2::FFI::Reader.open(file)
3231
end
3332

3433
parse_file(XML::Reader.io(io, :options => XML::Parser::Options::NOERROR), &block)

0 commit comments

Comments
 (0)