Class: Natour::GPXFile
Constant Summary collapse
- GPX_XMLNS =
{ 'xmlns' => 'http://www.topografix.com/GPX/1/1', 'xmlns:gpxtrkx' => 'http://www.garmin.com/xmlschemas/TrackStatsExtension/v1' }.freeze
Instance Attribute Summary
Attributes inherited from GPSTrack
#ascent, #date, #descent, #distance, #duration, #end_point, #path, #start_point
Instance Method Summary collapse
-
#initialize(filename) ⇒ GPXFile
constructor
A new instance of GPXFile.
- #to_gpx ⇒ Object
Methods inherited from GPSTrack
load_file, #round_effective_km!, #save_gpx
Constructor Details
#initialize(filename) ⇒ GPXFile
Returns a new instance of GPXFile.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/natour/gpx_file.rb', line 12 def initialize(filename) @doc = Nokogiri.XML(File.read(filename, mode: 'r:utf-8')) stats = @doc.at('/xmlns:gpx/xmlns:trk/xmlns:extensions/gpxtrkx:TrackStatsExtension', GPX_XMLNS) if stats ascent = stats.at('./gpxtrkx:Ascent', GPX_XMLNS).text.to_i descent = stats.at('./gpxtrkx:Descent', GPX_XMLNS).text.to_i distance = stats.at('./gpxtrkx:Distance', GPX_XMLNS).text.to_i duration = Duration.new(stats.at('./gpxtrkx:TotalElapsedTime', GPX_XMLNS).text.to_i) end start_point = to_track_point(@doc.at('/xmlns:gpx/xmlns:trk/xmlns:trkseg[1]/xmlns:trkpt[1]', GPX_XMLNS)) end_point = to_track_point(@doc.at('/xmlns:gpx/xmlns:trk/xmlns:trkseg[last()]/xmlns:trkpt[last()]', GPX_XMLNS)) super(filename, start_point.time&.to_date, ascent, descent, distance, duration, start_point, end_point) end |
Instance Method Details
#to_gpx ⇒ Object
29 30 31 |
# File 'lib/natour/gpx_file.rb', line 29 def to_gpx @doc.to_xml end |