Class: Broutes::Formats::GpxTrack
- Inherits:
-
Object
- Object
- Broutes::Formats::GpxTrack
- Defined in:
- lib/broutes/formats/gpx_track.rb
Instance Method Summary collapse
Instance Method Details
#load(file, route) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/broutes/formats/gpx_track.rb', line 6 def load(file, route) doc = Nokogiri::XML(file) Broutes.logger.info {"Loaded #{file} into #{doc.to_s.slice(0, 10)}"} i = 0 doc.css('trkpt').each do |node| p = route.add_point(lat: node['lat'].to_f, lon: node['lon'].to_f, elevation: point_elevation(node), time: point_time(node)) i += 1 end Broutes.logger.info {"Loaded #{i} data points"} end |
#point_elevation(node) ⇒ Object
18 19 20 21 22 |
# File 'lib/broutes/formats/gpx_track.rb', line 18 def point_elevation(node) if elevation_node = node.at_css('ele') elevation_node.inner_text.to_f end end |
#point_time(node) ⇒ Object
24 25 26 27 28 |
# File 'lib/broutes/formats/gpx_track.rb', line 24 def point_time(node) if time_node = node.at_css('time') DateTime.parse(time_node.inner_text).to_time end end |