gpx_kml 0.1.2 → 0.1.3

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: ed620fe7482aa20af6f157999f63fde7b05020bf8f66f73c2a3923867eda3932
4
- data.tar.gz: cd97e906096ccbe17686fb22eeeee457e995b0adf8b99f5126a143286217bb1b
3
+ metadata.gz: c23ca7cf7f9d6dc903b41e82036593e7f9bb40b1ae5b17ecfd5faf39e2ca4bff
4
+ data.tar.gz: 01b06257fc564b886843e9127f3fce7a37106b49e045342aa1c318dd1c2169f0
5
5
  SHA512:
6
- metadata.gz: cc4026a80235b8fb680be82b28e90c14a4abe9b38a3c9366b7f32277a6948da24d32487f8bebe5240623473ebfdabe112fecccd0da98722b4b79b0af1526d7ee
7
- data.tar.gz: 00535dc2bf44c737b8f927d0d70288732117260034a7e00ae3ece46c189e6428d6e0260adff4fa0be20987ac268921567b5a9025b342b2ac6e337d8a4108aebd
6
+ metadata.gz: b185abea99664b9e60595dfa2782e9a712d3e3ce994e15daaa6c02dfc91ddaa478cc6e18b51b92a4aeacdd398336f2ba0ea7bfe3c8a0e4c5962939c0e83ad9c8
7
+ data.tar.gz: 2089d40444b18ec20b049c24a5df3f728bfaae7f4be81750f993264c818bf9920acd926a8be5c38de903c26bd3ab669a7c3db940000a30a74eca6ceebabdde3b
data/CHANGELOG.md CHANGED
@@ -1,8 +1,15 @@
1
1
  ### V 0.1.x
2
+ - v 0.1.3:
3
+ - changed usage & updated/fixed minor parts in documentation (README.md)
4
+ - added preconverted files and missing tests
5
+ - change in inputs for conversion functions: now they take in Gpx and Kml instances instead of file paths
6
+ - added new feature: now you can check whether a Gpx (or Kml) object imported an effective 'gpx' (or 'kml') file
7
+ - added new feature: now you can create Gpx and Kml objects from their respective files
8
+ - removed dependency factory_bot which ended up being unused
2
9
  - v 0.1.2:
3
10
  - fixed version tests, AGAIN
4
11
  - v 0.1.1:
5
- - fixed critical bug on output file
12
+ - fixed critical bug on output file, path was wrong
6
13
  - v 0.1.0:
7
14
  - fixed changelog link in rubygems.org
8
15
  - removed .idea directory in the project
data/Gemfile.lock CHANGED
@@ -1,27 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gpx_kml (0.1.2)
4
+ gpx_kml (0.1.3)
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
11
  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
- minitest (5.14.4)
24
- nokogiri (1.12.5-x86_64-linux)
12
+ mini_portile2 (2.6.1)
13
+ nokogiri (1.12.5)
14
+ mini_portile2 (~> 2.6.1)
25
15
  racc (~> 1.4)
26
16
  racc (1.6.0)
27
17
  rake (12.3.3)
@@ -38,15 +28,11 @@ GEM
38
28
  diff-lcs (>= 1.2.0, < 2.0)
39
29
  rspec-support (~> 3.10.0)
40
30
  rspec-support (3.10.2)
41
- tzinfo (2.0.4)
42
- concurrent-ruby (~> 1.0)
43
- zeitwerk (2.4.2)
44
31
 
45
32
  PLATFORMS
46
33
  ruby
47
34
 
48
35
  DEPENDENCIES
49
- factory_bot (~> 6.2)
50
36
  gpx_kml!
51
37
  rspec (~> 3.0)
52
38
 
data/README.md CHANGED
@@ -1,14 +1,12 @@
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.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This gem adds the capability to convert GPS Exchange Format (GPX) files to Keyhole Markup Language (KML) files and viceversa
6
4
 
7
5
  ## Before using
8
6
 
9
7
  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.
8
+ 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.
9
+ Just dig in deep, tests are present for everything you need.
12
10
 
13
11
  ## Installation
14
12
 
@@ -28,12 +26,26 @@ Or install it yourself as:
28
26
 
29
27
  ## Usage
30
28
 
31
- To use it just ```require 'gpx_kml'``` in the script you need the converter and use either one of the following two functions:
32
-
33
- - ```GPXKML::GpxKml.kml_to_gpx('file_path', 'destination_path')```
34
- - ```GPXKML::GpxKml.gpx_to_kml('file_path', 'destination_path')```
35
-
36
- Note: destination_path must be a directory
29
+ To use it just ```require 'gpx_kml'``` in the script you need the converter and perform the following actions:
30
+ <br>
31
+ Create an instance of the file you want to convert as follows:
32
+ - ```gpx = GPXKML::GpxKml.new_gpx('file_path')``` for a gpx file
33
+ - ```kml = GPXKML::GpxKml.new_kml('file_path')``` for a kml file
34
+ <br><br>
35
+
36
+ Now: you may want to check if the file you imported is actually a gpx or a kml.<br>
37
+ You can do that by usign the ```gpx?``` & ```kml?``` functions on the instance you just created:
38
+ - ```GPXKML::GpxKml.gpx?(gpx)```
39
+ - ```GPXKML::GpxKml.kml?(kml)```
40
+
41
+ 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.
42
+ <br><br>
43
+ Now you can actually convert the instance to create the new file needed.<br>
44
+ The function will return the entire path to the file just created!
45
+ - ```path_of_the_new_file = GPXKML::GpxKml.kml_to_gpx('gpx', 'destination_path')```
46
+ - ```path_of_the_new_file = GPXKML::GpxKml.gpx_to_kml('kml', 'destination_path')```
47
+
48
+ IMPORTANT : ```destination_path``` must be a directory
37
49
 
38
50
  ## Development
39
51
 
data/gpx_kml.gemspec CHANGED
@@ -7,7 +7,7 @@ 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
12
  spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
13
13
 
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'nokogiri', '~>1.12.0'
34
34
 
35
35
  # Gem testing
36
- spec.add_development_dependency 'factory_bot', '~>6.2'
37
36
  spec.add_development_dependency 'rspec', '~>3.0'
37
+
38
+ # spec.add_development_dependency 'factory_bot', '~>6.2'
39
+ # factory_bot isn't really used
38
40
  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"
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
37
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,15 +58,17 @@ 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"
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
62
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|
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?
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.2'
4
+ VERSION = '0.1.3'
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.2
4
+ version: 0.1.3
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: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.12.0
41
- - !ruby/object:Gem::Dependency
42
- name: factory_bot
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '6.2'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '6.2'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,8 +52,8 @@ dependencies:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
54
  version: '3.0'
69
- description: This gem adds the capability to convert GPS Exchange Format (GPX) to
70
- Keyhole Markup Language (KML) and viceversa
55
+ description: This gem adds the capability to convert GPS Exchange Format (GPX) files
56
+ to Keyhole Markup Language (KML) files and viceversa
71
57
  email:
72
58
  - info@engim.eu
73
59
  executables: []