gpx_track_generator 0.0.2 → 0.1.1

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: 50267039e5b2ceb53bdfe1e52ffa1df2ae385ebc
4
- data.tar.gz: 46e6f3efcae2a0e29354dea99d1a902c35ad09f5
3
+ metadata.gz: 309023d011ba9d800f4dcba6b64458504364733e
4
+ data.tar.gz: 19662c2f92a3d3808c75db32de8c3506923d0de7
5
5
  SHA512:
6
- metadata.gz: 141492a7b81a1bb2c01b0ae16ece91097bca70e4a88e0c05b8efae32aa07182b24ddcfe26eb961736a8f0d583970334bc14c50cf44cea93a514ad8fa0238c5f3
7
- data.tar.gz: 7aa28a6ff5ca795fb1624da4e6d11186704ceaaf7977ae0709fac1b416150dc9630c96acef469a7f1cf7f893ea8bb984ca13723807c7a6f8d36814c899da0b61
6
+ metadata.gz: aa441a132683f9182745f2f294d3e261bb6df16617343db75617dc89a4a1c4415fa9705c5e5b06dee7c1ddf38b9f1d977da8f9577141504a4ca93342916c283b
7
+ data.tar.gz: 0ba36bfc3b33f2f3aae5b4c3432a3e23afa7d523c0d81aac6e769e53183d3d80f37dd78a2fea1ccf274a89f16e00e423059cdfbc625afdbdb151e5537f39169b
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gpx_track_generator (0.0.2)
4
+ gpx_track_generator (0.1.1)
5
5
  activesupport
6
6
  nokogiri
7
+ nokogiri-pretty
7
8
  thor
8
9
 
9
10
  GEM
@@ -142,6 +143,8 @@ GEM
142
143
  netrc (0.7.7)
143
144
  nokogiri (1.6.3.1)
144
145
  mini_portile (= 0.6.0)
146
+ nokogiri-pretty (0.1.0)
147
+ nokogiri
145
148
  parallel (1.2.4)
146
149
  parser (2.2.0.pre.4)
147
150
  ast (>= 1.1, < 3.0)
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- # GpxTrackGenerator
1
+ # Gpx Track Generator
2
2
 
3
- TODO: Write a gem description
3
+ This gem creates a single gpx track from all given gpx-files. Those files can
4
+ contain route- or track-points. This might be handy if you've got single
5
+ gpx-files for each part of a long distance walk, but don't want to litter your
6
+ gps-device.
4
7
 
5
8
  ## Installation
6
9
 
@@ -18,6 +21,36 @@ Or install it yourself as:
18
21
 
19
22
  ## Usage
20
23
 
24
+ ### Ruby
25
+
26
+ Create your track file from ruby code. This can be helpful in your `Rakefile`.
27
+
28
+ ```ruby
29
+ input_files = %w(track1.gpx route2.gpx)
30
+ track_name = 'Track ABC'
31
+ output_file = 'my_track.gpx'
32
+
33
+ GpxTrackGenerator::Api.generate(
34
+ input_files: input_files,
35
+ track_name: track_name,
36
+ output_file: output_file
37
+ )
38
+ ```
39
+
40
+ ### CLI
41
+
42
+ *Create track file*
43
+
44
+ ```
45
+ gpx_track *.gpx
46
+ ```
47
+
48
+ *Define track name*
49
+
50
+ ```
51
+ gpx_track --name "Track Name" *.gpx
52
+ ```
53
+
21
54
  TODO: Write usage instructions here
22
55
 
23
56
  ## Contributing
@@ -7,4 +7,34 @@ Feature: Create GPX Track File
7
7
  Given a gpx file named "route1.gpx"
8
8
  And a gpx file named "route2.gpx"
9
9
  When I successfully run `gpx_track g route1.gpx route2.gpx`
10
- Then a gpx file named "track.gpx" should exist
10
+ Then a gpx file named "track.gpx" should exist with "4" track nodes
11
+
12
+ Scenario: Create from gpx track files
13
+ Given a gpx file named "track1.gpx"
14
+ And a gpx file named "track2.gpx"
15
+ When I successfully run `gpx_track g track1.gpx track2.gpx`
16
+ Then a gpx file named "track.gpx" should exist with "4" track nodes
17
+
18
+ Scenario: Change output file name
19
+ Given a gpx file named "track1.gpx"
20
+ And a gpx file named "track2.gpx"
21
+ When I successfully run `gpx_track g --file track123.gpx track1.gpx track2.gpx`
22
+ Then a gpx file named "track123.gpx" should exist
23
+
24
+ Scenario: Define name
25
+ Given a gpx file named "track1.gpx"
26
+ And a gpx file named "track2.gpx"
27
+ When I successfully run `gpx_track g --name "My Name" track1.gpx track2.gpx`
28
+ Then the gpx file "track.gpx" should contain:
29
+ """
30
+ <name>My Name</name>
31
+ """
32
+
33
+ Scenario: Default name
34
+ Given a gpx file named "track1.gpx"
35
+ And a gpx file named "track2.gpx"
36
+ When I successfully run `gpx_track g track1.gpx track2.gpx`
37
+ Then the gpx file "track.gpx" should contain:
38
+ """
39
+ <name>Track #1</name>
40
+ """
@@ -22,6 +22,17 @@ Given(/^a gpx file named "(.*?)"$/) do |file|
22
22
  end
23
23
  end
24
24
 
25
- Then(/^a gpx file named "(.*?)" should exist$/) do |file|
25
+ Then(/^the gpx file named "(.*?)" should have "(.*?)" track nodes$/) do |file, count|
26
+ in_current_dir do
27
+ expect(Nokogiri::XML(File.open(file)).css('trkpt').to_a.size).to eq count.to_i
28
+ end
29
+ end
30
+
31
+ Then(/^a gpx file named "(.*?)" should exist(?: with "(.*?)" track nodes)?$/) do |file, count|
26
32
  step %(a file named "#{file}" should exist)
33
+ step %(the gpx file named "#{file}" should have "#{count}" track nodes) if count
34
+ end
35
+
36
+ Then(/^the gpx file "(.*?)" should contain:$/) do |file, content|
37
+ step %(the file "#{file}" should contain:), content
27
38
  end
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0"?>
2
+ <gpx version="1.0" creator="Example.com"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xmlns="http://www.topografix.com/GPX/1/0"
5
+ xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
6
+ <trk>
7
+ <name>Track 1</name>
8
+ <trkseg>
9
+ <trkpt lat="55.688634024660372" lon="-5.5744374090151107">
10
+ <name>WPT 1</name>
11
+ <ele>15.232316396783801</ele>
12
+ </trkpt>
13
+ <trkpt lat="57.688634024660372" lon="-5.5744374090151107">
14
+ <name>WPT 1</name>
15
+ <ele>15.232316396783801</ele>
16
+ </trkpt>
17
+ </trkseg>
18
+ </trk>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0"?>
2
+ <gpx version="1.0" creator="Example.com"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xmlns="http://www.topografix.com/GPX/1/0"
5
+ xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
6
+ <trk>
7
+ <name>Track 2</name>
8
+ <trkseg>
9
+ <trkpt lat="56.688634024660372" lon="-6.5744374090151107">
10
+ <name>WPT 1</name>
11
+ <ele>16.232316396783801</ele>
12
+ </trkpt>
13
+ <trkpt lat="57.688634024660372" lon="-6.5744374090151107">
14
+ <name>WPT 1</name>
15
+ <ele>16.232316396783801</ele>
16
+ </trkpt>
17
+ </trkseg>
18
+ </trk>
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_runtime_dependency 'nokogiri'
21
+ spec.add_runtime_dependency 'nokogiri-pretty'
21
22
  spec.add_runtime_dependency 'thor'
22
23
  spec.add_runtime_dependency 'activesupport'
23
24
  end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ module GpxTrackGenerator
3
+ # Main api
4
+ module Api
5
+ def self.generate(input_files:, track_name:, output_file:)
6
+ files = input_files.map { |f| GpxFile.new(File.expand_path(f)) }
7
+ track = Track.new(files, name: track_name)
8
+
9
+ File.write(output_file, track.to_s)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ module GpxTrackGenerator
3
+ # A gpx file
4
+ class GpxFile
5
+ private
6
+
7
+ attr_reader :path
8
+
9
+ public
10
+
11
+ def initialize(path)
12
+ @path = path
13
+ end
14
+
15
+ # Return nodes
16
+ def nodes
17
+ document = Nokogiri::XML('')
18
+ node_set = Nokogiri::XML::NodeSet.new(document)
19
+
20
+ node_set += extract_route_nodes unless extract_route_nodes.empty?
21
+ node_set += extract_track_nodes unless extract_track_nodes.empty?
22
+
23
+ node_set.css('trkpt').each_with_index { |e, i| e.css('name').first.content = "WP #{i + 1}" }
24
+
25
+ node_set
26
+ end
27
+
28
+ # Return file name
29
+ def file_name
30
+ File.basename(path)
31
+ end
32
+
33
+ private
34
+
35
+ def extract_route_nodes
36
+ node_set = Nokogiri::XML(File.open(path)).remove_namespaces!.css('rtept')
37
+ node_set.each { |n| n.name = 'trkpt' }
38
+
39
+ node_set
40
+ end
41
+
42
+ def extract_track_nodes
43
+ node_set = Nokogiri::XML(File.open(path)).remove_namespaces!.css('trkpt')
44
+ node_set.each { |n| n.name = 'trkpt' }
45
+
46
+ node_set
47
+ end
48
+ end
49
+ end
@@ -3,12 +3,12 @@ module GpxTrackGenerator
3
3
  # Runner
4
4
  class Runner < Thor
5
5
  option :file, default: 'track.gpx', desc: 'GPX track file name'
6
+ option :name, default: 'Track #1', required: true, desc: 'Name for track'
7
+ argument :input_files, type: :array, desc: 'GPX track or route files'
8
+
6
9
  desc 'generate', 'Generate gpx track'
7
- argument :gpx_files, type: :array, desc: 'GPX track or route files'
8
10
  def generate
9
- track = Track.new(gpx_files.map { |f| File.expand_path f })
10
-
11
- File.write(options[:file], track.to_s)
11
+ Api.generate(input_files: input_files, track_name: options[:name], output_file: options[:file])
12
12
  end
13
13
 
14
14
  default_command :generate
@@ -4,12 +4,13 @@ module GpxTrackGenerator
4
4
  class Track
5
5
  private
6
6
 
7
- attr_reader :files
7
+ attr_reader :files, :name
8
8
 
9
9
  public
10
10
 
11
- def initialize(files)
11
+ def initialize(files, name:)
12
12
  @files = files
13
+ @name = name
13
14
  end
14
15
 
15
16
  def to_s
@@ -18,25 +19,34 @@ module GpxTrackGenerator
18
19
 
19
20
  private
20
21
 
22
+ def creator
23
+ 'gpx_track_generator'
24
+ end
25
+
26
+ def creator_url
27
+ 'https://github.com/maxmeyer/gpx_track_generator'
28
+ end
29
+
21
30
  def build_document
22
31
  document.child << metadata
32
+
23
33
  document.child << document.create_element('trk')
34
+ document.css('trk').first << document.create_element('name')
35
+ document.css('name').first.content = name
24
36
 
25
37
  files.each_with_object(document.css('trk').first) do |e, a|
38
+ a << "<!-- #{e.file_name} -->"
26
39
  a << document.create_element('trkseg')
27
- node_set = Nokogiri::XML(File.open(e)).remove_namespaces!.css('rtept')
28
- node_set.each { |n| n.name = 'trkpt' }
29
-
30
- a.css('trkseg').last << node_set
40
+ a.css('trkseg').last << e.nodes
31
41
  end
32
42
 
33
- document.to_s
43
+ document.human
34
44
  end
35
45
 
36
46
  def document
37
47
  @document ||= Nokogiri::XML(
38
48
  <<-EOS.strip_heredoc
39
- <gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.1" creator="Nokogiri" xmlns="http://www.topografix.com/GPX/1/1"></gpx>
49
+ <gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.1" creator="#{creator}" xmlns="http://www.topografix.com/GPX/1/1"></gpx>
40
50
  EOS
41
51
  )
42
52
  end
@@ -44,9 +54,9 @@ module GpxTrackGenerator
44
54
  def metadata
45
55
  @metadata ||= Nokogiri::XML::DocumentFragment.parse <<-EOS.strip_heredoc
46
56
  <metadata>
47
- <desc>GPX file generated nokogiri</desc>
48
- <link href="http://nokogiri.org/">
49
- <text>Nokogiri</text>
57
+ <desc>GPX file generated by #{creator}</desc>
58
+ <link href="#{creator_url}">
59
+ <text>#{creator}</text>
50
60
  </link>
51
61
  <time>#{Time.now}</time>
52
62
  </metadata>
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # GpxTrackGenerator
3
3
  module GpxTrackGenerator
4
- VERSION = '0.0.2'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -2,10 +2,13 @@ require 'thor'
2
2
  require 'nokogiri'
3
3
  require 'thor/actions'
4
4
  require 'active_support/core_ext/string/strip'
5
+ require 'nokogiri-pretty'
5
6
 
6
7
  require 'gpx_track_generator/version'
8
+ require 'gpx_track_generator/gpx_file'
7
9
  require 'gpx_track_generator/runner'
8
10
  require 'gpx_track_generator/track'
11
+ require 'gpx_track_generator/api'
9
12
 
10
13
  # Track generator
11
14
  module GpxTrackGenerator
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpx_track_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-28 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri-pretty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: thor
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -87,8 +101,12 @@ files:
87
101
  - features/support/reporting.rb
88
102
  - fixtures/route1.gpx
89
103
  - fixtures/route2.gpx
104
+ - fixtures/track1.gpx
105
+ - fixtures/track2.gpx
90
106
  - gpx_track_generator.gemspec
91
107
  - lib/gpx_track_generator.rb
108
+ - lib/gpx_track_generator/api.rb
109
+ - lib/gpx_track_generator/gpx_file.rb
92
110
  - lib/gpx_track_generator/runner.rb
93
111
  - lib/gpx_track_generator/track.rb
94
112
  - lib/gpx_track_generator/version.rb