gpx_track_generator 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f44774183c934f97efb98d4910bb2385086c1ecc
4
- data.tar.gz: b940a57bc8c2ab82b9fdd651f4835febdad04e1f
3
+ metadata.gz: f388ed4e3ed7f6da7a73c5565ef060601e90e95e
4
+ data.tar.gz: 0e0fb882167e13b291fb3519b1f0380e5163c83a
5
5
  SHA512:
6
- metadata.gz: 034cb1be0f7e552973be8c614da2c40d936a461391ca5d3a03165b84a166f914ddd41515ab5f255b2d5b7f24d2491a068b7466e55a7cc78d6bfde4d55c15bad3
7
- data.tar.gz: c1eba84912141b2485453c348eff409bbdbf79a6a8ee0fa8b38cc47959c012392df70dedec54eeb6d9dfbaf4a00f6a8d5b32d67b85b54d42b457722bbb3b48d9
6
+ metadata.gz: 82eb885c1a4d8836acd3f53aabd1cf8811936297d7144724f38bc599a81aa1b1a2ab3cc706000af20c7387528562b31f81e491cca2ebaa5514b6ac4a094f3866
7
+ data.tar.gz: 5633dbde493ade486f1c4029063310d9a373abdc98dbb8cfa3ab112f57066c57bb2b26ca9fa28de1dfee6bedc4815246e21c55b4d08ad039c30661bd2ab74f33
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gpx_track_generator (0.2.0)
4
+ gpx_track_generator (0.3.0)
5
5
  activesupport
6
6
  nokogiri
7
7
  nokogiri-pretty
data/README.md CHANGED
@@ -52,6 +52,20 @@ GpxTrackGenerator::Api.generate(
52
52
  output_file: output_file,
53
53
  reverse: true
54
54
  )
55
+
56
+ *Single segment per Track*
57
+
58
+ ```ruby
59
+ input_files = %w(track1.gpx route2.gpx)
60
+ track_name = 'Track ABC'
61
+ output_file = 'my_track.gpx'
62
+
63
+ GpxTrackGenerator::Api.generate(
64
+ input_files: input_files,
65
+ track_name: track_name,
66
+ output_file: output_file,
67
+ single_segment: true
68
+ )
55
69
  ```
56
70
 
57
71
  ### CLI
@@ -71,7 +85,13 @@ gpx_track --name "Track Name" *.gpx
71
85
  *Reverse track*
72
86
 
73
87
  ```
74
- gpx_track --name "Track Name" --reverse *.gpx
88
+ gpx_track --reverse *.gpx
89
+ ```
90
+
91
+ *Single Segment for the whole track*
92
+
93
+ ```
94
+ gpx_track --single-segment *.gpx
75
95
  ```
76
96
 
77
97
  ## Contributing
@@ -70,3 +70,57 @@ Feature: Create GPX Track File
70
70
  <ele>16.232316396783801</ele>
71
71
  </trkpt>
72
72
  """
73
+
74
+ Scenario: Single segment
75
+ Given a gpx file named "track1.gpx"
76
+ And a gpx file named "track2.gpx"
77
+ When I successfully run `gpx_track g --single-segment track1.gpx track2.gpx`
78
+ Then the gpx file "track.gpx" should contain:
79
+ """
80
+ <trkseg>
81
+ <trkpt lat="55.688634024660372" lon="-5.5744374090151107">
82
+ <name>WP 1</name>
83
+ <ele>15.232316396783801</ele>
84
+ </trkpt>
85
+ <trkpt lat="57.688634024660372" lon="-5.5744374090151107">
86
+ <name>WP 2</name>
87
+ <ele>15.232316396783801</ele>
88
+ </trkpt>
89
+ <trkpt lat="56.688634024660372" lon="-6.5744374090151107">
90
+ <name>WP 1</name>
91
+ <ele>16.232316396783801</ele>
92
+ </trkpt>
93
+ <trkpt lat="57.688634024660372" lon="-6.5744374090151107">
94
+ <name>WP 2</name>
95
+ <ele>16.232316396783801</ele>
96
+ </trkpt>
97
+ </trkseg>
98
+ """
99
+
100
+ Scenario: One segment per track file
101
+ Given a gpx file named "track1.gpx"
102
+ And a gpx file named "track2.gpx"
103
+ When I successfully run `gpx_track g --single-segment=false track1.gpx track2.gpx`
104
+ Then the gpx file "track.gpx" should contain:
105
+ """
106
+ <trkseg>
107
+ <trkpt lat="55.688634024660372" lon="-5.5744374090151107">
108
+ <name>WP 1</name>
109
+ <ele>15.232316396783801</ele>
110
+ </trkpt>
111
+ <trkpt lat="57.688634024660372" lon="-5.5744374090151107">
112
+ <name>WP 2</name>
113
+ <ele>15.232316396783801</ele>
114
+ </trkpt>
115
+ </trkseg>
116
+ <trkseg>
117
+ <trkpt lat="56.688634024660372" lon="-6.5744374090151107">
118
+ <name>WP 1</name>
119
+ <ele>16.232316396783801</ele>
120
+ </trkpt>
121
+ <trkpt lat="57.688634024660372" lon="-6.5744374090151107">
122
+ <name>WP 2</name>
123
+ <ele>16.232316396783801</ele>
124
+ </trkpt>
125
+ </trkseg>
126
+ """
@@ -2,9 +2,9 @@
2
2
  module GpxTrackGenerator
3
3
  # Main api
4
4
  module Api
5
- def self.generate(input_files:, track_name:, output_file:, reverse: false)
5
+ def self.generate(input_files:, track_name:, output_file:, reverse: false, single_segment: true)
6
6
  files = input_files.map { |f| GpxFile.new(File.expand_path(f)) }
7
- track = Track.new(files, name: track_name, reverse: reverse)
7
+ track = Track.new(files, name: track_name, reverse: reverse, single_segment: single_segment)
8
8
 
9
9
  File.write(output_file, track.to_s)
10
10
  end
@@ -4,12 +4,19 @@ module GpxTrackGenerator
4
4
  class Runner < Thor
5
5
  option :file, default: 'track.gpx', desc: 'GPX track file name'
6
6
  option :name, default: 'Track #1', required: true, desc: 'Name for track'
7
- option :reverse, type: :boolean, desc: 'Reverse track'
7
+ option :reverse, type: :boolean, default: false, desc: 'Reverse track (default: false)'
8
+ option :single_segment, type: :boolean, default: false, desc: 'Only one track segment for the whole track. Otherwise one segment for each input file (default: true)'
8
9
  argument :input_files, type: :array, desc: 'GPX track or route files'
9
10
 
10
11
  desc 'generate', 'Generate gpx track'
11
12
  def generate
12
- Api.generate(input_files: input_files, track_name: options[:name], output_file: options[:file], reverse: options[:reverse])
13
+ Api.generate(
14
+ input_files: input_files,
15
+ track_name: options[:name],
16
+ output_file: options[:file],
17
+ reverse: options[:reverse],
18
+ single_segment: options[:single_segment]
19
+ )
13
20
  end
14
21
 
15
22
  default_command :generate
@@ -4,14 +4,15 @@ module GpxTrackGenerator
4
4
  class Track
5
5
  private
6
6
 
7
- attr_reader :files, :name, :reverse
7
+ attr_reader :files, :name, :reverse, :single_segment
8
8
 
9
9
  public
10
10
 
11
- def initialize(files, name:, reverse:)
12
- @files = files
13
- @name = name
14
- @reverse = reverse
11
+ def initialize(files, name:, reverse:, single_segment:)
12
+ @files = files
13
+ @name = name
14
+ @reverse = reverse
15
+ @single_segment = single_segment
15
16
  end
16
17
 
17
18
  def to_s
@@ -35,10 +36,19 @@ module GpxTrackGenerator
35
36
  document.css('trk').first << document.create_element('name')
36
37
  document.css('name').first.content = name
37
38
 
38
- files.each_with_object(document.css('trk').first) do |e, a|
39
- a << "<!-- #{e.file_name} -->"
40
- a << document.create_element('trkseg')
41
- a.css('trkseg').last << (reverse ? e.nodes.reverse : e.nodes)
39
+ if single_segment
40
+ document.css('trk').first << document.create_element('trkseg')
41
+
42
+ files.each_with_object(document.css('trk').first) do |e, a|
43
+ a << "<!-- #{e.file_name} -->"
44
+ document.css('trkseg').last << (reverse ? e.nodes.reverse : e.nodes)
45
+ end
46
+ else
47
+ files.each_with_object(document.css('trk').first) do |e, a|
48
+ a << "<!-- #{e.file_name} -->"
49
+ a << document.create_element('trkseg')
50
+ a.css('trkseg').last << (reverse ? e.nodes.reverse : e.nodes)
51
+ end
42
52
  end
43
53
 
44
54
  document.human
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # GpxTrackGenerator
3
3
  module GpxTrackGenerator
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpx_track_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer