Class: ComtecDR::GpxGenerator
- Inherits:
-
Object
- Object
- ComtecDR::GpxGenerator
- Defined in:
- lib/comtec-dr/gpx_generator.rb
Instance Method Summary collapse
- #add_track(csv = nil) ⇒ Object
- #add_trkseg(csv) ⇒ Object
-
#initialize(filename) ⇒ GpxGenerator
constructor
A new instance of GpxGenerator.
- #write ⇒ Object
Constructor Details
#initialize(filename) ⇒ GpxGenerator
Returns a new instance of GpxGenerator.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/comtec-dr/gpx_generator.rb', line 3 def initialize filename @filename = filename @doc = REXML::Document.new @gpx = REXML::Element.new('gpx') @gpx.add_attributes({ 'creator' => "comtec-dr-ruby/#{ComtecDR::VERSION}", 'version' => "1.1", 'xmlns' => 'http://www.topografix.com/GPX/1/1', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd' }) @doc.add_element(@gpx) end |
Instance Method Details
#add_track(csv = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/comtec-dr/gpx_generator.rb', line 18 def add_track csv = nil @trk = REXML::Element.new('trk') @gpx.add_element(@trk) add_trkseg csv if !csv.nil? end |
#add_trkseg(csv) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/comtec-dr/gpx_generator.rb', line 25 def add_trkseg csv trkseg = REXML::Element.new('trkseg') @trk.add_element(trkseg) csv.each do |line| trkpt = REXML::Element.new('trkpt') trkpt.add_attributes({'lat' => line[0], 'lon' => line[1]}) trkseg.add_element(trkpt) end end |
#write ⇒ Object
35 36 37 38 39 |
# File 'lib/comtec-dr/gpx_generator.rb', line 35 def write File.open(@filename, 'w') do |file| @doc.write(file, indent=2) end end |