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 collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/natour/gpx_file.rb', line 14 def initialize(filename) @doc = Nokogiri.XML(File.read(filename, mode: 'r:utf-8')) @types = [] @types << :waypoint if @doc.at('/xmlns:gpx/xmlns:wpt', GPX_XMLNS) @types << :route if @doc.at('/xmlns:gpx/xmlns:rte', GPX_XMLNS) @types << :track if @doc.at('/xmlns:gpx/xmlns:trk', GPX_XMLNS) 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 Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
12 13 14 |
# File 'lib/natour/gpx_file.rb', line 12 def types @types end |
Instance Method Details
#to_gpx ⇒ Object
36 37 38 |
# File 'lib/natour/gpx_file.rb', line 36 def to_gpx @doc.to_xml end |