gpx 0.9.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +36 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop.yml +162 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +6 -5
  7. data/CHANGELOG.md +15 -0
  8. data/Gemfile +2 -0
  9. data/LICENSE.txt +1 -1
  10. data/README.md +20 -5
  11. data/Rakefile +22 -12
  12. data/bin/gpx_distance +5 -6
  13. data/bin/gpx_smooth +25 -26
  14. data/gpx.gemspec +13 -12
  15. data/lib/gpx/bounds.rb +13 -31
  16. data/lib/gpx/geo_json.rb +199 -0
  17. data/lib/gpx/gpx.rb +4 -26
  18. data/lib/gpx/gpx_file.rb +140 -134
  19. data/lib/gpx/magellan_track_log.rb +34 -66
  20. data/lib/gpx/point.rb +22 -35
  21. data/lib/gpx/route.rb +10 -31
  22. data/lib/gpx/segment.rb +63 -90
  23. data/lib/gpx/track.rb +38 -42
  24. data/lib/gpx/track_point.rb +32 -0
  25. data/lib/gpx/version.rb +3 -1
  26. data/lib/gpx/waypoint.rb +10 -34
  27. data/lib/gpx.rb +13 -34
  28. data/tests/geojson_files/combined_data.json +68 -0
  29. data/tests/geojson_files/line_string_data.json +83 -0
  30. data/tests/geojson_files/multi_line_string_data.json +74 -0
  31. data/tests/geojson_files/multi_point_data.json +14 -0
  32. data/tests/geojson_files/point_data.json +22 -0
  33. data/tests/geojson_test.rb +92 -0
  34. data/tests/gpx10_test.rb +7 -6
  35. data/tests/gpx_file_test.rb +31 -19
  36. data/tests/gpx_files/one_segment_mixed_times.gpx +884 -0
  37. data/tests/gpx_files/routes_without_names.gpx +29 -0
  38. data/tests/gpx_files/with_empty_tracks.gpx +72 -0
  39. data/tests/magellan_test.rb +12 -11
  40. data/tests/output_test.rb +93 -94
  41. data/tests/route_test.rb +75 -30
  42. data/tests/segment_test.rb +104 -93
  43. data/tests/track_file_test.rb +50 -70
  44. data/tests/track_point_test.rb +22 -11
  45. data/tests/track_test.rb +73 -61
  46. data/tests/waypoint_test.rb +46 -48
  47. metadata +47 -18
  48. data/lib/gpx/trackpoint.rb +0 -60
data/tests/gpx10_test.rb CHANGED
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  class GPX10Test < Minitest::Test
5
- GPX_FILE = File.join(File.dirname(__FILE__), "gpx_files/gpx10.gpx")
6
-
7
- def test_read
8
- # make sure we can read a GPX 1.0 file
9
- @gpx_file = GPX::GPXFile.new(:gpx_file => GPX_FILE)
10
- end
7
+ GPX_FILE = File.join(File.dirname(__FILE__), 'gpx_files/gpx10.gpx')
11
8
 
9
+ def test_read
10
+ # make sure we can read a GPX 1.0 file
11
+ @gpx_file = GPX::GPXFile.new(gpx_file: GPX_FILE)
12
+ end
12
13
  end
@@ -1,19 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  class GPXFileTest < Minitest::Test
5
-
6
- ONE_TRACK_FILE = File.join(File.dirname(__FILE__), "gpx_files/one_track.gpx")
7
- WITH_OR_WITHOUT_ELEV_FILE = File.join(File.dirname(__FILE__), "gpx_files/with_or_without_elev.gpx")
8
- BIG_FILE = File.join(File.dirname(__FILE__), "gpx_files/big.gpx")
7
+ ONE_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx')
8
+ WITH_OR_WITHOUT_ELEV_FILE = File.join(File.dirname(__FILE__), 'gpx_files/with_or_without_elev.gpx')
9
+ WITH_EMPTY_TRACKS = File.join(File.dirname(__FILE__), 'gpx_files/with_empty_tracks.gpx')
10
+ BIG_FILE = File.join(File.dirname(__FILE__), 'gpx_files/big.gpx')
9
11
 
10
12
  def test_load_data_from_string
11
- gpx_file = GPX::GPXFile.new(:gpx_data => open(ONE_TRACK_FILE).read)
13
+ gpx_file = GPX::GPXFile.new(gpx_data: File.open(ONE_TRACK_FILE).read)
12
14
  assert_equal(1, gpx_file.tracks.size)
13
15
  assert_equal(8, gpx_file.tracks.first.segments.size)
14
- assert_equal("ACTIVE LOG", gpx_file.tracks.first.name)
15
- assert_equal("active_log.gpx", gpx_file.name)
16
- assert_equal("2006-04-08T16:44:28Z", gpx_file.time.xmlschema)
16
+ assert_equal('ACTIVE LOG', gpx_file.tracks.first.name)
17
+ assert_equal('active_log.gpx', gpx_file.name)
18
+ assert_equal('2006-04-08T16:44:28Z', gpx_file.time.xmlschema)
17
19
  assert_equal(38.681488, gpx_file.bounds.min_lat)
18
20
  assert_equal(-109.606948, gpx_file.bounds.min_lon)
19
21
  assert_equal(38.791759, gpx_file.bounds.max_lat)
@@ -21,45 +23,55 @@ class GPXFileTest < Minitest::Test
21
23
  assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
22
24
  assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
23
25
  assert_equal(3.0724966849262554, gpx_file.distance)
24
- assert_equal(15237.0, gpx_file.duration)
26
+ assert_equal(15_237.0, gpx_file.duration)
25
27
  assert_equal(3036.0, gpx_file.moving_duration)
26
28
  assert_equal(3.6432767014935834, gpx_file.average_speed)
27
29
  end
28
30
 
29
31
  def test_load_data_from_file
30
- gpx_file = GPX::GPXFile.new(:gpx_file => ONE_TRACK_FILE)
32
+ gpx_file = GPX::GPXFile.new(gpx_file: ONE_TRACK_FILE)
31
33
  assert_equal(1, gpx_file.tracks.size)
32
34
  assert_equal(8, gpx_file.tracks.first.segments.size)
33
- assert_equal("ACTIVE LOG", gpx_file.tracks.first.name)
34
- assert_equal("active_log.gpx", gpx_file.name)
35
- assert_equal("2006-04-08T16:44:28Z", gpx_file.time.xmlschema)
35
+ assert_equal('ACTIVE LOG', gpx_file.tracks.first.name)
36
+ assert_equal('active_log.gpx', gpx_file.name)
37
+ assert_equal('2006-04-08T16:44:28Z', gpx_file.time.xmlschema)
36
38
  assert_equal(38.681488, gpx_file.bounds.min_lat)
37
39
  assert_equal(-109.606948, gpx_file.bounds.min_lon)
38
40
  assert_equal(38.791759, gpx_file.bounds.max_lat)
39
41
  assert_equal(-109.447045, gpx_file.bounds.max_lon)
40
42
  assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
41
43
  assert_equal(3.0724966849262554, gpx_file.distance)
42
- assert_equal(15237.0, gpx_file.duration)
44
+ assert_equal(15_237.0, gpx_file.duration)
43
45
  assert_equal(3036.0, gpx_file.moving_duration)
44
46
  assert_equal(3.6432767014935834, gpx_file.average_speed)
45
47
  end
46
48
 
47
49
  def test_big_file
48
- gpx_file = GPX::GPXFile.new(:gpx_file => BIG_FILE)
50
+ gpx_file = GPX::GPXFile.new(gpx_file: BIG_FILE)
49
51
  assert_equal(1, gpx_file.tracks.size)
50
52
  assert_equal(7968, gpx_file.tracks.first.points.size)
51
- assert_equal(105508.0, gpx_file.duration)
52
- assert_equal(57645.0, gpx_file.moving_duration)
53
+ assert_equal(105_508.0, gpx_file.duration)
54
+ assert_equal(57_645.0, gpx_file.moving_duration)
53
55
  assert_in_delta(99.60738958686505, gpx_file.average_speed, 1e-13)
54
56
  end
55
57
 
56
58
  def test_with_or_with_elev
57
- gpx_file = GPX::GPXFile.new(:gpx_file => WITH_OR_WITHOUT_ELEV_FILE)
59
+ gpx_file = GPX::GPXFile.new(gpx_file: WITH_OR_WITHOUT_ELEV_FILE)
58
60
  assert_equal(2, gpx_file.tracks.size)
59
61
  assert_equal(0, gpx_file.duration)
60
62
  assert_equal(0, gpx_file.moving_duration)
61
63
  assert(gpx_file.average_speed.nan?)
62
- #assert_equal(7968, gpx_file.tracks.first.points.size)
64
+ # assert_equal(7968, gpx_file.tracks.first.points.size)
63
65
  end
64
66
 
67
+ def test_with_empty_tracks
68
+ gpx_file = GPX::GPXFile.new(gpx_file: WITH_EMPTY_TRACKS)
69
+ # is read correctly
70
+ assert_equal(1, gpx_file.tracks.size)
71
+ # and ignores empty segments
72
+ assert_equal(1, gpx_file.tracks.first.segments.size)
73
+ assert_equal(21.0, gpx_file.duration)
74
+ assert_equal(21.0, gpx_file.moving_duration)
75
+ assert_equal(6.674040636626879, gpx_file.average_speed)
76
+ end
65
77
  end