Class: ColumbusCli::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/columbus_cli/track.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Track

Returns a new instance of Track.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/columbus_cli/track.rb', line 5

def initialize(file)
  @points = []
  CSV.foreach(file, headers: true) do |p|
    tag = p["TAG"]

    date = "20#{p['DATE'].scan(/../).join('-')}"
    time = "#{p['TIME'].length == 6 ? p['TIME'] : '0' + p['TIME']}".scan(/../).join(':')

    ts = Time.parse "#{date}T#{time}"
    lat = parse_lat p["LATITUDE N/S"]
    lon = parse_lon p["LONGITUDE E/W"]
    speed = p["SPEED"].to_i
    alt = p["HEIGHT"].to_i
    @points << { time: ts, lat: lat, lon: lon, speed: speed, elevation: alt, waypoint: (tag == 'C') }
  end
end

Instance Method Details

#to_gpxObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/columbus_cli/track.rb', line 22

def to_gpx
  segment = GPX::Segment.new
  @points.each do |p|
    point = GPX::TrackPoint.new(p)
    segment.append_point point
  end

  track = GPX::Track.new
  track.append_segment segment

  track
end