gpx_kml 0.1.0 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13f65ff6210343e36ea2ac9d4dba526063b52acb79e53e0b9041396e5c7f60e8
4
- data.tar.gz: 20812205cf5a53b658bf7a5d4ea4ec389c3d535bdb6ea0f27e0bd06b9865998e
3
+ metadata.gz: 4e4f90ca7411226710707068d7b42b5d5bb9502b7431c842ec28611854e56487
4
+ data.tar.gz: 9926bc276fa356b3af9697a88e5b10c84cb421e4ef786268c1121ffb8cc8a536
5
5
  SHA512:
6
- metadata.gz: 35887d6a1c43fb454ec18d06e02c7dc9de8b0586eaff513d6f18540b52b19768d5c52332cc5d4c7f94085e404c0253ec66618421d7379eeb624db83340163e36
7
- data.tar.gz: d6d731ba24b088f7f6c35f19a8668a6384c85cba46f486455182457d79dabffd1ac289aafd74bc2d2113ecefcc41b1d19a4a491d068fa5a8d00ba5e1e4f42cb0
6
+ metadata.gz: 58cc3fc0313d1e898ea57f4969e10618ebe6a0745b98933aa5e614ae18c49da3dae8c292613ec642b673a0f39fc3eb8bd9bdf72713a2d0072acc529567b8205f
7
+ data.tar.gz: 2b6e8dd1db1191146bcd25e467536bd5eb750a2739e3bc3912b2979339d05f4d15186b948d64b471f33727238e6efdfe2dded853f76c9203cfb9b61c6744a03b
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /.idea/
10
+ /coverage/
10
11
 
11
12
  # rspec failure tracking
12
13
  .rspec_status
data/CHANGELOG.md CHANGED
@@ -1,4 +1,19 @@
1
1
  ### V 0.1.x
2
+ - v 0.1.4:
3
+ - fixed kml files generation
4
+ - fixed bug that swapped latitude and longitude in certain conversions from gpx to kml
5
+ - added code coverage for development env
6
+ - v 0.1.3:
7
+ - changed usage & updated/fixed minor parts in documentation (README.md)
8
+ - added preconverted files and missing tests
9
+ - change in inputs for conversion functions: now they take in Gpx and Kml instances instead of file paths
10
+ - added new feature: now you can check whether a Gpx (or Kml) object imported an effective 'gpx' (or 'kml') file
11
+ - added new feature: now you can create Gpx and Kml objects from their respective files
12
+ - removed dependency factory_bot which ended up being unused
13
+ - v 0.1.2:
14
+ - fixed version tests, AGAIN
15
+ - v 0.1.1:
16
+ - fixed critical bug on output file, path was wrong
2
17
  - v 0.1.0:
3
18
  - fixed changelog link in rubygems.org
4
19
  - removed .idea directory in the project
data/Gemfile.lock CHANGED
@@ -1,29 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gpx_kml (0.1.0)
4
+ gpx_kml (0.1.4)
5
5
  nokogiri (~> 1.12.0)
6
6
  rake (~> 12.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.1.4.1)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 1.6, < 2)
14
- minitest (>= 5.1)
15
- tzinfo (~> 2.0)
16
- zeitwerk (~> 2.3)
17
- concurrent-ruby (1.1.9)
18
- diff-lcs (1.4.4)
19
- factory_bot (6.2.0)
20
- activesupport (>= 5.0.0)
21
- i18n (1.8.10)
22
- concurrent-ruby (~> 1.0)
23
- mini_portile2 (2.6.1)
24
- minitest (5.14.4)
25
- nokogiri (1.12.5)
26
- mini_portile2 (~> 2.6.1)
11
+ diff-lcs (1.5.0)
12
+ docile (1.4.0)
13
+ nokogiri (1.12.5-x86_64-linux)
27
14
  racc (~> 1.4)
28
15
  racc (1.6.0)
29
16
  rake (12.3.3)
@@ -33,24 +20,27 @@ GEM
33
20
  rspec-mocks (~> 3.10.0)
34
21
  rspec-core (3.10.1)
35
22
  rspec-support (~> 3.10.0)
36
- rspec-expectations (3.10.1)
23
+ rspec-expectations (3.10.2)
37
24
  diff-lcs (>= 1.2.0, < 2.0)
38
25
  rspec-support (~> 3.10.0)
39
26
  rspec-mocks (3.10.2)
40
27
  diff-lcs (>= 1.2.0, < 2.0)
41
28
  rspec-support (~> 3.10.0)
42
- rspec-support (3.10.2)
43
- tzinfo (2.0.4)
44
- concurrent-ruby (~> 1.0)
45
- zeitwerk (2.4.2)
29
+ rspec-support (3.10.3)
30
+ simplecov (0.21.2)
31
+ docile (~> 1.1)
32
+ simplecov-html (~> 0.11)
33
+ simplecov_json_formatter (~> 0.1)
34
+ simplecov-html (0.12.3)
35
+ simplecov_json_formatter (0.1.3)
46
36
 
47
37
  PLATFORMS
48
38
  ruby
49
39
 
50
40
  DEPENDENCIES
51
- factory_bot (~> 6.2)
52
41
  gpx_kml!
53
42
  rspec (~> 3.0)
43
+ simplecov (~> 0.21.0)
54
44
 
55
45
  BUNDLED WITH
56
- 2.1.4
46
+ 2.2.22
data/LICENSE.md ADDED
@@ -0,0 +1,157 @@
1
+ ### GNU LESSER GENERAL PUBLIC LICENSE
2
+
3
+ Version 3, 29 June 2007
4
+
5
+ Copyright (C) 2007 Free Software Foundation, Inc.
6
+ <https://fsf.org/>
7
+
8
+ Everyone is permitted to copy and distribute verbatim copies of this
9
+ license document, but changing it is not allowed.
10
+
11
+ This version of the GNU Lesser General Public License incorporates the
12
+ terms and conditions of version 3 of the GNU General Public License,
13
+ supplemented by the additional permissions listed below.
14
+
15
+ #### 0. Additional Definitions.
16
+
17
+ As used herein, "this License" refers to version 3 of the GNU Lesser
18
+ General Public License, and the "GNU GPL" refers to version 3 of the
19
+ GNU General Public License.
20
+
21
+ "The Library" refers to a covered work governed by this License, other
22
+ than an Application or a Combined Work as defined below.
23
+
24
+ An "Application" is any work that makes use of an interface provided
25
+ by the Library, but which is not otherwise based on the Library.
26
+ Defining a subclass of a class defined by the Library is deemed a mode
27
+ of using an interface provided by the Library.
28
+
29
+ A "Combined Work" is a work produced by combining or linking an
30
+ Application with the Library. The particular version of the Library
31
+ with which the Combined Work was made is also called the "Linked
32
+ Version".
33
+
34
+ The "Minimal Corresponding Source" for a Combined Work means the
35
+ Corresponding Source for the Combined Work, excluding any source code
36
+ for portions of the Combined Work that, considered in isolation, are
37
+ based on the Application, and not on the Linked Version.
38
+
39
+ The "Corresponding Application Code" for a Combined Work means the
40
+ object code and/or source code for the Application, including any data
41
+ and utility programs needed for reproducing the Combined Work from the
42
+ Application, but excluding the System Libraries of the Combined Work.
43
+
44
+ #### 1. Exception to Section 3 of the GNU GPL.
45
+
46
+ You may convey a covered work under sections 3 and 4 of this License
47
+ without being bound by section 3 of the GNU GPL.
48
+
49
+ #### 2. Conveying Modified Versions.
50
+
51
+ If you modify a copy of the Library, and, in your modifications, a
52
+ facility refers to a function or data to be supplied by an Application
53
+ that uses the facility (other than as an argument passed when the
54
+ facility is invoked), then you may convey a copy of the modified
55
+ version:
56
+
57
+ - a) under this License, provided that you make a good faith effort
58
+ to ensure that, in the event an Application does not supply the
59
+ function or data, the facility still operates, and performs
60
+ whatever part of its purpose remains meaningful, or
61
+ - b) under the GNU GPL, with none of the additional permissions of
62
+ this License applicable to that copy.
63
+
64
+ #### 3. Object Code Incorporating Material from Library Header Files.
65
+
66
+ The object code form of an Application may incorporate material from a
67
+ header file that is part of the Library. You may convey such object
68
+ code under terms of your choice, provided that, if the incorporated
69
+ material is not limited to numerical parameters, data structure
70
+ layouts and accessors, or small macros, inline functions and templates
71
+ (ten or fewer lines in length), you do both of the following:
72
+
73
+ - a) Give prominent notice with each copy of the object code that
74
+ the Library is used in it and that the Library and its use are
75
+ covered by this License.
76
+ - b) Accompany the object code with a copy of the GNU GPL and this
77
+ license document.
78
+
79
+ #### 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that, taken
82
+ together, effectively do not restrict modification of the portions of
83
+ the Library contained in the Combined Work and reverse engineering for
84
+ debugging such modifications, if you also do each of the following:
85
+
86
+ - a) Give prominent notice with each copy of the Combined Work that
87
+ the Library is used in it and that the Library and its use are
88
+ covered by this License.
89
+ - b) Accompany the Combined Work with a copy of the GNU GPL and this
90
+ license document.
91
+ - c) For a Combined Work that displays copyright notices during
92
+ execution, include the copyright notice for the Library among
93
+ these notices, as well as a reference directing the user to the
94
+ copies of the GNU GPL and this license document.
95
+ - d) Do one of the following:
96
+ - 0) Convey the Minimal Corresponding Source under the terms of
97
+ this License, and the Corresponding Application Code in a form
98
+ suitable for, and under terms that permit, the user to
99
+ recombine or relink the Application with a modified version of
100
+ the Linked Version to produce a modified Combined Work, in the
101
+ manner specified by section 6 of the GNU GPL for conveying
102
+ Corresponding Source.
103
+ - 1) Use a suitable shared library mechanism for linking with
104
+ the Library. A suitable mechanism is one that (a) uses at run
105
+ time a copy of the Library already present on the user's
106
+ computer system, and (b) will operate properly with a modified
107
+ version of the Library that is interface-compatible with the
108
+ Linked Version.
109
+ - e) Provide Installation Information, but only if you would
110
+ otherwise be required to provide such information under section 6
111
+ of the GNU GPL, and only to the extent that such information is
112
+ necessary to install and execute a modified version of the
113
+ Combined Work produced by recombining or relinking the Application
114
+ with a modified version of the Linked Version. (If you use option
115
+ 4d0, the Installation Information must accompany the Minimal
116
+ Corresponding Source and Corresponding Application Code. If you
117
+ use option 4d1, you must provide the Installation Information in
118
+ the manner specified by section 6 of the GNU GPL for conveying
119
+ Corresponding Source.)
120
+
121
+ #### 5. Combined Libraries.
122
+
123
+ You may place library facilities that are a work based on the Library
124
+ side by side in a single library together with other library
125
+ facilities that are not Applications and are not covered by this
126
+ License, and convey such a combined library under terms of your
127
+ choice, if you do both of the following:
128
+
129
+ - a) Accompany the combined library with a copy of the same work
130
+ based on the Library, uncombined with any other library
131
+ facilities, conveyed under the terms of this License.
132
+ - b) Give prominent notice with the combined library that part of it
133
+ is a work based on the Library, and explaining where to find the
134
+ accompanying uncombined form of the same work.
135
+
136
+ #### 6. Revised Versions of the GNU Lesser General Public License.
137
+
138
+ The Free Software Foundation may publish revised and/or new versions
139
+ of the GNU Lesser General Public License from time to time. Such new
140
+ versions will be similar in spirit to the present version, but may
141
+ differ in detail to address new problems or concerns.
142
+
143
+ Each version is given a distinguishing version number. If the Library
144
+ as you received it specifies that a certain numbered version of the
145
+ GNU Lesser General Public License "or any later version" applies to
146
+ it, you have the option of following the terms and conditions either
147
+ of that published version or of any later version published by the
148
+ Free Software Foundation. If the Library as you received it does not
149
+ specify a version number of the GNU Lesser General Public License, you
150
+ may choose any version of the GNU Lesser General Public License ever
151
+ published by the Free Software Foundation.
152
+
153
+ If the Library as you received it specifies that a proxy can decide
154
+ whether future versions of the GNU Lesser General Public License shall
155
+ apply, that proxy's public statement of acceptance of any version is
156
+ permanent authorization for you to choose that version for the
157
+ Library.
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # GpxKml
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gpx_kml`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](http://www.gnu.org/licenses/lgpl-3.0) [![Coverage: %](https://img.shields.io/badge/Code%20coverage-100%25-green.svg)](#coverage)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This gem adds the capability to convert GPS Exchange Format (GPX) files to Keyhole Markup Language (KML) files and viceversa
6
6
 
7
7
  ## Before using
8
8
 
9
9
  Please take note that this only converts essentials data for the gpx and kml files compatibility.
10
- However the gem doesn't just include the converter, it also transforms gpx files and kml files (only their track/route/point parts) into a Gpx/Kml file, which could be useful for a new fork or other uses.
11
- Just dig in deep, tests are present for everything you need, except the mere conversion.
10
+ However the gem doesn't just include the converter, it also transforms gpx files and kml files (only their track/route/point parts) into a Gpx/Kml instance, which could be useful for new forks or other uses.
11
+ Just dig in deep, tests are present for everything you need.
12
12
 
13
13
  ## Installation
14
14
 
@@ -28,12 +28,26 @@ Or install it yourself as:
28
28
 
29
29
  ## Usage
30
30
 
31
- To use it just ```require 'gpx_kml'``` in the script you need the converter and use either one of the following two functions:
31
+ To use it just ```require 'gpx_kml'``` in the script you need the converter and perform the following actions:
32
+ <br>
33
+ Create an instance of the file you want to convert as follows:
34
+ - ```gpx = GPXKML::GpxKml.new_gpx('file_path')``` for a gpx file
35
+ - ```kml = GPXKML::GpxKml.new_kml('file_path')``` for a kml file
36
+ <br><br>
32
37
 
33
- - ```GPXKML::GpxKml.kml_to_gpx('file_path', 'destination_path')```
34
- - ```GPXKML::GpxKml.gpx_to_kml('file_path', 'destination_path')```
38
+ Now: you may want to check if the file you imported is actually a gpx or a kml.<br>
39
+ You can do that by usign the ```gpx?``` & ```kml?``` functions on the instance you just created:
40
+ - ```GPXKML::GpxKml.gpx?(gpx)```
41
+ - ```GPXKML::GpxKml.kml?(kml)```
35
42
 
36
- Note: destination_path must be a directory
43
+ Note: this step is optional since the conversions method below do the same thing inside of themselves, but this method could turn out to be useful.
44
+ <br><br>
45
+ Now you can actually convert the instance to create the new file needed.<br>
46
+ The function will return the entire path to the file just created!
47
+ - ```path_of_the_new_file = GPXKML::GpxKml.kml_to_gpx('gpx', 'destination_path')```
48
+ - ```path_of_the_new_file = GPXKML::GpxKml.gpx_to_kml('kml', 'destination_path')```
49
+
50
+ IMPORTANT : ```destination_path``` must be a directory
37
51
 
38
52
  ## Development
39
53
 
@@ -45,6 +59,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
45
59
 
46
60
  Bug reports and pull requests are welcome on GitHub at https://github.com/Engim-eu/gpx_kml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/gpx_kml/blob/master/CODE_OF_CONDUCT.md).
47
61
 
62
+ ## Coverage
63
+
64
+ Coverage can be checked running `rake spec`. This command will generate the coverage files needed.
48
65
 
49
66
  ## Code of Conduct
50
67
 
data/gpx_kml.gemspec CHANGED
@@ -7,8 +7,9 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ['info@engim.eu']
8
8
 
9
9
  spec.summary = 'Gem to convert .gpx into .kml and back'
10
- spec.description = 'This gem adds the capability to convert GPS Exchange Format (GPX) to Keyhole Markup Language (KML) and viceversa'
10
+ spec.description = 'This gem adds the capability to convert GPS Exchange Format (GPX) files to Keyhole Markup Language (KML) files and viceversa'
11
11
  spec.homepage = 'https://www.github.com/engim-eu/gpx_kml'
12
+ spec.licenses = ['LGNU']
12
13
  spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
13
14
 
14
15
  spec.metadata['allowed_push_host'] = "https://rubygems.org"
@@ -33,6 +34,11 @@ Gem::Specification.new do |spec|
33
34
  spec.add_dependency 'nokogiri', '~>1.12.0'
34
35
 
35
36
  # Gem testing
36
- spec.add_development_dependency 'factory_bot', '~>6.2'
37
37
  spec.add_development_dependency 'rspec', '~>3.0'
38
+
39
+ # Test coverage
40
+ spec.add_development_dependency 'simplecov', '~>0.21.0'
41
+
42
+ # spec.add_development_dependency 'factory_bot', '~>6.2'
43
+ # factory_bot isn't really used
38
44
  end
data/lib/converter.rb CHANGED
@@ -3,13 +3,11 @@
3
3
  module CONVERTER
4
4
  # Docu
5
5
  class Converter
6
- def self.gpx_to_kml(gpx_path, output_path)
7
- return unless File.directory?(output_path)
6
+ def self.gpx_to_kml(gpx, output_path)
7
+ return unless File.directory?(output_path) && gpx.is_a?(GPX::Gpx)
8
+ return nil unless gpx.gpx?
8
9
 
9
10
  output_path = output_path[0..-2] if output_path[-1].eql?('/')
10
- gpx = GPXKML::Gpx.new(gpx_path)
11
- return nil if gpx.nil? || !gpx.valid?
12
-
13
11
  kml = Nokogiri::XML::Builder.new do |xml|
14
12
  xml.kml('xmlns': 'http://www.opengis.net/kml/2.2', 'xmlns:gx': 'http://www.google.com/kml/ext/2.2',
15
13
  'xmlns:atom': 'http://www.w3.org/Atom') do
@@ -33,20 +31,22 @@ module CONVERTER
33
31
  end
34
32
  end
35
33
  end
36
- name = "#{output_path}/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{gpx.file_name[0..-5]}.kml"
37
- f = File.open("#{output_path}/#{name}", 'w')
34
+ name = if gpx.file_name.end_with?('.gpx') || gpx.file_name.end_with?('.xml')
35
+ "#{output_path}/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{gpx.file_name[0..-5]}.kml"
36
+ else
37
+ "#{output_path}/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{gpx.file_name}.kml"
38
+ end
39
+ f = File.open(name.to_s, 'w')
38
40
  f.write(kml.to_xml)
39
41
  f.close
40
42
  name
41
43
  end
42
44
 
43
- def self.kml_to_gpx(kml_path, output_path)
44
- return unless File.directory?(output_path)
45
+ def self.kml_to_gpx(kml, output_path)
46
+ return nil unless File.directory?(output_path) && kml.is_a?(KML::Kml)
47
+ return nil unless kml.kml?
45
48
 
46
49
  output_path = output_path[0..-2] if output_path[-1].eql?('/')
47
- kml = GPXKML::Kml.new(kml_path)
48
- return nil if kml.nil? || !kml.valid?
49
-
50
50
  gpx = Nokogiri::XML::Builder.new do |xml|
51
51
  xml.gpx('version': '1.1', 'creator': 'https://www.github.com/engim-eu/gpx_kml',
52
52
  'xmlns': 'https://www.topografix.com/GPX/1/1', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance') do
@@ -58,31 +58,35 @@ module CONVERTER
58
58
  gpx_tracks(xml, kml)
59
59
  end
60
60
  end
61
- name = "#{output_path}/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{kml.file_name[0..-5]}.gpx"
62
- f = File.open("#{output_path}/#{name}", 'w')
61
+ name = if kml.file_name.end_with?('.kml') || kml.file_name.end_with?('.xml')
62
+ "#{output_path}/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{kml.file_name[0..-5]}.gpx"
63
+ else
64
+ "#{output_path}/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{kml.file_name}.gpx"
65
+ end
66
+ f = File.open(name.to_s, 'w')
63
67
  f.write(gpx.to_xml)
64
68
  f.close
65
69
  name
66
70
  end
67
71
 
68
- private
69
-
70
72
  def self.kml_routes(xml, gpx)
71
73
  if gpx.routes?
72
74
  gpx.routes.each do |r|
73
- xml.LinearRing do
74
- xml.extrude('0')
75
- xml.tassellate('0')
76
- xml.altitudeMode('clampToGroud')
77
- s = ''
78
- r.points.each do |p|
79
- s = if p.elevation.nil? || p.elevation.empty?
80
- s + "#{p.latitude},#{p.longitude} "
81
- else
82
- s + "#{p.latitude},#{p.longitude},#{p.elevation} "
83
- end
75
+ xml.Placemark do
76
+ xml.LinearRing do
77
+ xml.extrude('0')
78
+ xml.tassellate('0')
79
+ xml.altitudeMode('clampToGroud')
80
+ s = ''
81
+ r.points.each do |p|
82
+ s = if p.elevation.nil? || p.elevation.empty?
83
+ s + "#{p.longitude},#{p.latitude} "
84
+ else
85
+ s + "#{p.longitude},#{p.latitude},#{p.elevation} "
86
+ end
87
+ end
88
+ xml.coordinates(s[0..-2])
84
89
  end
85
- xml.coordinates(s[0..-2])
86
90
  end
87
91
  end
88
92
  end
@@ -91,27 +95,29 @@ module CONVERTER
91
95
  def self.kml_tracks(xml, gpx)
92
96
  if gpx.tracks?
93
97
  gpx.tracks.each do |t|
94
- xml.LineString do
95
- xml.extrude('0')
96
- xml.tassellate('0')
97
- xml.altitudeMode('clampToGroud')
98
- s = ''
99
- points = []
100
- t.segments.each do |sg|
101
- sg.points.each do |p|
102
- points = points << p
98
+ xml.Placemark do
99
+ xml.LineString do
100
+ xml.extrude('0')
101
+ xml.tassellate('0')
102
+ xml.altitudeMode('clampToGroud')
103
+ s = ''
104
+ points = []
105
+ t.segments.each do |sg|
106
+ sg.points.each do |p|
107
+ points = points << p
108
+ end
103
109
  end
104
- end
105
- points.each do |p|
106
- next if p.nil?
110
+ points.each do |p|
111
+ next if p.nil?
107
112
 
108
- s = if p.elevation.nil? || p.elevation.empty?
109
- s + "#{p.latitude},#{p.longitude} "
110
- else
111
- s + "#{p.latitude},#{p.longitude},#{p.elevation} "
112
- end
113
+ s = if p.elevation.nil? || p.elevation.empty?
114
+ s + "#{p.longitude},#{p.latitude} "
115
+ else
116
+ s + "#{p.longitude},#{p.latitude},#{p.elevation} "
117
+ end
118
+ end
119
+ xml.coordinates(s[0..-2])
113
120
  end
114
- xml.coordinates(s[0..-2])
115
121
  end
116
122
  end
117
123
  end
@@ -124,9 +130,9 @@ module CONVERTER
124
130
  xml.extrude('0')
125
131
  xml.altitudeMode('clampToGroud')
126
132
  if p.elevation.nil? || p.elevation.empty?
127
- xml.coordinates("#{p.latitude},#{p.longitude}")
133
+ xml.coordinates("#{p.longitude},#{p.latitude}")
128
134
  else
129
- xml.coordinates("#{p.latitude},#{p.longitude},#{p.elevation}")
135
+ xml.coordinates("#{p.longitude},#{p.latitude},#{p.elevation}")
130
136
  end
131
137
  end
132
138
  end
@@ -138,8 +144,8 @@ module CONVERTER
138
144
  kml.points.each do |p|
139
145
  next if p.nil?
140
146
 
141
- xml.wpt('lat': "#{p.latitude}", 'lon': "#{p.longitude}") do
142
- xml.ele("#{p.elevation}") unless p.elevation.nil? || p.elevation.empty?
147
+ xml.wpt('lat': p.latitude.to_s, 'lon': p.longitude.to_s) do
148
+ xml.ele(p.elevation.to_s) unless p.elevation.nil? || p.elevation.empty?
143
149
  xml.name(p.name) unless p.name.nil? || p.name.empty?
144
150
  xml.desc("author = #{p.author}") unless p.author.nil? || p.author.empty?
145
151
  xml.link('href': p.link) unless p.link.nil? || p.link.empty?
@@ -160,8 +166,8 @@ module CONVERTER
160
166
  r.points.each do |p|
161
167
  next if p.nil?
162
168
 
163
- xml.rtept('lat': "#{p.latitude}", 'lon': "#{p.longitude}") do
164
- xml.ele("#{p.elevation}") unless p.elevation.nil? || p.elevation.empty?
169
+ xml.rtept('lat': p.latitude.to_s, 'lon': p.longitude.to_s) do
170
+ xml.ele(p.elevation.to_s) unless p.elevation.nil? || p.elevation.empty?
165
171
  xml.desc("author = #{p.author}") unless p.author.nil? || p.author.empty?
166
172
  xml.link('href': p.link) unless p.link.nil? || p.link.empty?
167
173
  end
@@ -184,8 +190,8 @@ module CONVERTER
184
190
  t.points.each do |p|
185
191
  next if p.nil?
186
192
 
187
- xml.trkpt('lat': "#{p.latitude}", 'lon': "#{p.longitude}") do
188
- xml.ele("#{p.elevation}") unless p.elevation.nil? || p.elevation.empty?
193
+ xml.trkpt('lat': p.latitude.to_s, 'lon': p.longitude.to_s) do
194
+ xml.ele(p.elevation.to_s) unless p.elevation.nil? || p.elevation.empty?
189
195
  xml.desc("author = #{p.author}") unless p.author.nil? || p.author.empty?
190
196
  xml.link('href': p.link) unless p.link.nil? || p.link.empty?
191
197
  end
data/lib/gpx_kml/gpx.rb CHANGED
@@ -33,11 +33,13 @@ module GPX
33
33
  # access in readonly to the quantity of points/routes/tracks in the gpx
34
34
  attr_reader :points_length, :routes_length, :tracks_length
35
35
 
36
+ def gpx?
37
+ !@gpx.nil? && !@gpx.xpath('/xmlns:gpx').empty?
38
+ end
39
+
36
40
  # For a gpx file to be valid it must only have a waypoint, a route or a track
37
41
  def valid?
38
- return nil if @gpx.nil?
39
-
40
- !@gpx.xpath('/xmlns:gpx').empty? && (tracks? || routes? || points?)
42
+ gpx? && (tracks? || routes? || points?)
41
43
  end
42
44
 
43
45
  def routes?
@@ -16,8 +16,8 @@ module KML
16
16
 
17
17
  @father = father
18
18
  coord = coord.split(',')
19
- @latitude = coord[0]
20
- @longitude = coord[1]
19
+ @longitude = coord[0]
20
+ @latitude = coord[1]
21
21
  @elevation = coord[2] if coord.length == 3
22
22
  @node = node
23
23
  # Name is looked up in the ancestor of the node that compose this point
data/lib/gpx_kml/kml.rb CHANGED
@@ -29,10 +29,12 @@ module KML
29
29
  # access data of the kml in readonly
30
30
  attr_reader :points, :routes, :tracks
31
31
 
32
- def valid?
33
- return nil if @kml.nil?
32
+ def kml?
33
+ !@kml.nil? && !@kml.xpath('/xmlns:kml').empty?
34
+ end
34
35
 
35
- !@kml.xpath('/xmlns:kml').empty? && (tracks? || routes? || points?)
36
+ def valid?
37
+ kml? && (tracks? || routes? || points?)
36
38
  end
37
39
 
38
40
  def routes?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GPXKML
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.4'
5
5
  end
data/lib/gpx_kml.rb CHANGED
@@ -12,12 +12,28 @@ module GPXKML
12
12
  include CONVERTER
13
13
 
14
14
  class GpxKml
15
- def self.gpx_to_kml(file_path, destination_path)
16
- CONVERTER::Converter.gpx_to_kml(file_path, destination_path)
15
+ def self.gpx_to_kml(gpx, destination_path)
16
+ CONVERTER::Converter.gpx_to_kml(gpx, destination_path)
17
17
  end
18
18
 
19
- def self.kml_to_gpx(file_path, destination_path)
20
- CONVERTER::Converter.kml_to_gpx(file_path, destination_path)
19
+ def self.kml_to_gpx(kml, destination_path)
20
+ CONVERTER::Converter.kml_to_gpx(kml, destination_path)
21
+ end
22
+
23
+ def self.kml?(kml)
24
+ kml.is_a?(KML::Kml) && kml.kml?
25
+ end
26
+
27
+ def self.gpx?(gpx)
28
+ gpx.is_a?(GPX::Gpx) && gpx.gpx?
29
+ end
30
+
31
+ def self.new_kml(file_path)
32
+ KML::Kml.new(file_path)
33
+ end
34
+
35
+ def self.new_gpx(file_path)
36
+ GPX::Gpx.new(file_path)
21
37
  end
22
38
  end
23
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpx_kml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angelo Terzi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-28 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -39,35 +39,35 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.12.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: factory_bot
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '6.2'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '6.2'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: 0.21.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
69
- description: This gem adds the capability to convert GPS Exchange Format (GPX) to
70
- Keyhole Markup Language (KML) and viceversa
68
+ version: 0.21.0
69
+ description: This gem adds the capability to convert GPS Exchange Format (GPX) files
70
+ to Keyhole Markup Language (KML) files and viceversa
71
71
  email:
72
72
  - info@engim.eu
73
73
  executables: []
@@ -81,6 +81,7 @@ files:
81
81
  - CODE_OF_CONDUCT.md
82
82
  - Gemfile
83
83
  - Gemfile.lock
84
+ - LICENSE.md
84
85
  - README.md
85
86
  - Rakefile
86
87
  - bin/console
@@ -104,7 +105,8 @@ files:
104
105
  - lib/gpx_kml/templates/wpt.gpx
105
106
  - lib/gpx_kml/version.rb
106
107
  homepage: https://www.github.com/engim-eu/gpx_kml
107
- licenses: []
108
+ licenses:
109
+ - LGNU
108
110
  metadata:
109
111
  allowed_push_host: https://rubygems.org
110
112
  homepage_uri: https://www.github.com/engim-eu/gpx_kml
@@ -125,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
127
  - !ruby/object:Gem::Version
126
128
  version: '0'
127
129
  requirements: []
128
- rubygems_version: 3.1.4
130
+ rubygems_version: 3.2.22
129
131
  signing_key:
130
132
  specification_version: 4
131
133
  summary: Gem to convert .gpx into .kml and back