class Natour::GPSTrack
Attributes
ascent[R]
date[R]
descent[R]
distance[R]
duration[R]
end_point[R]
path[R]
start_point[R]
Public Class Methods
load_file(filename, format: :auto)
click to toggle source
# File lib/natour/gps_track.rb, line 28 def self.load_file(filename, format: :auto) format = Pathname(filename).extname.to_s.delete_prefix('.').to_sym if format == :auto case format when :gpx GPXFile.new(filename) when :fit FITFile.new(filename) end end
new(path, date, ascent, descent, distance, duration, start_point, end_point)
click to toggle source
# File lib/natour/gps_track.rb, line 17 def initialize(path, date, ascent, descent, distance, duration, start_point, end_point) @path = path @date = date @ascent = ascent @descent = descent @distance = distance @duration = duration @start_point = start_point @end_point = end_point end
Public Instance Methods
round_effective_km!()
click to toggle source
# File lib/natour/gps_track.rb, line 38 def round_effective_km! @ascent = @ascent&.round(-2) @descent = @descent&.round(-2) @distance = @distance&.round(-3) @duration = Duration.new(round_duration(@duration, minutes: 15)) if @duration @start_point = GPSTrackPoint.new( @start_point.latitude, @start_point.longitude, @start_point.elevation, round_time(@start_point.time, minutes: 5) ) @end_point = GPSTrackPoint.new( @end_point.latitude, @end_point.longitude, @end_point.elevation, round_time(@end_point.time, minutes: 5) ) self end
save_gpx(filename, overwrite: false)
click to toggle source
# File lib/natour/gps_track.rb, line 58 def save_gpx(filename, overwrite: false) FileUtils.mkdir_p(Pathname(filename).dirname) mode = File::WRONLY | File::CREAT | File::TRUNC mode |= File::EXCL unless overwrite File.open(filename, mode) do |file| file.write(to_gpx) end end
Private Instance Methods
round_duration(duration, hours: 0, minutes: 0, seconds: 0)
click to toggle source
# File lib/natour/gps_track.rb, line 73 def round_duration(duration, hours: 0, minutes: 0, seconds: 0) Duration.new(round_multiple_of(duration.to_i, (hours * 60 + minutes) * 60 + seconds)) end
round_multiple_of(number, multiple)
click to toggle source
# File lib/natour/gps_track.rb, line 69 def round_multiple_of(number, multiple) (number / multiple.to_f).round * multiple end
round_time(time, hours: 0, minutes: 0, seconds: 0)
click to toggle source
# File lib/natour/gps_track.rb, line 77 def round_time(time, hours: 0, minutes: 0, seconds: 0) Time.at(round_multiple_of(time.to_i, (hours * 60 + minutes) * 60 + seconds)) end