simple-trail 0.3.0 → 0.3.2

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
  SHA256:
3
- metadata.gz: 4ec7ad04579f7af6e5c6df0517ee1f8ef8ba986f8895ce92e7548fddec91dabe
4
- data.tar.gz: 694d57d1ec75c501e48e93acbdaad27d63dda944671323666d045c47031b4e77
3
+ metadata.gz: 01fc41a9ee4029834332f22d8cc513e8b12e2d8490e91b144cdd10c9b04f8bab
4
+ data.tar.gz: 841468837b2f944c7825751b6ddee2d174caa2d4bc4b1e4933664969ef7e5b79
5
5
  SHA512:
6
- metadata.gz: b18740f2f648846202cf58a00f9a1debdae27273cd769bb401b27752d6c6c5b6b6f514445573c57fc3da650fea96827bd75e2146ff5539e8c5c78ca1b4b0861e
7
- data.tar.gz: 0d1fe7392d9c8701da42433b52ed498e0a959371d405f3dcc8aa4d632af56df28a2cc305f6ef5c6aa9717ce0719b36cc73663e0635922a1e6ee7ccddf6973904
6
+ metadata.gz: 46b758ae075b90f1694c4ccb5a48926fefc835f274f0f62014e13f9c792f6c41e306e0fc39d36621f21f700f601f3b4d5652835bbac942891c7c9c1bfbef7406
7
+ data.tar.gz: e3dbb0f40a6f2b31b81f0e5be17762689ff4fcf08b57618bdcc1210c30d03df8fad70c278a94714551548123301c1ca6109756fce066296d2ba9ef7f1fa9a416
@@ -9,9 +9,34 @@ module Parser
9
9
  end
10
10
 
11
11
  def read_points
12
- segments = @parsed_file.dig(:trk, :trkseg)
13
- @points = segments.is_a?(Array) ? segments.map { |seg| seg[:trkpt] }.flatten : segments[:trkpt]
14
- @simplified_points = @points.map { |point| point.select { |key, _| [:lon, :lat].include? key } }
12
+
13
+ main_node = @parsed_file.fetch(:trk)
14
+
15
+ if main_node.is_a?(Array)
16
+ @simplified_points = []
17
+ @points = []
18
+
19
+ main_node.each do |segment|
20
+ @simplified_points << simplified_points_selection(segment)
21
+ @points << segment_points_selection(segment)
22
+ end
23
+
24
+ @simplified_points.flatten!
25
+ @points.flatten!
26
+ else
27
+ segments = main_node.fetch(:trkseg)
28
+ @points = segments.is_a?(Array) ? segments.map { |seg| seg[:trkpt] }.flatten : segments[:trkpt]
29
+ @simplified_points = @points.map { |point| point.select { |key, _| [:lon, :lat].include? key } }
30
+ end
31
+ end
32
+
33
+ def segment_points_selection(segment)
34
+ segments = segment.fetch(:trkseg)
35
+ segments.is_a?(Array) ? segments.map { |seg| seg[:trkpt] }.flatten : segments[:trkpt]
36
+ end
37
+
38
+ def simplified_points_selection(segment)
39
+ segment_points_selection(segment).map { |point| point.select { |key, _| [:lon, :lat].include? key } }
15
40
  end
16
41
  end
17
42
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Parser
4
+ class ValidateGpx < Base
5
+ def initialize(filename)
6
+ @filename = filename
7
+ end
8
+
9
+ def validate_basics?
10
+ file = File.new(@filename)
11
+ @parsed_file = XmlHasher.parse(file)[:gpx]
12
+
13
+ !@parsed_file.nil?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Parser
4
+ class ValidateGpxString < Base
5
+ def initialize(file_content)
6
+ @file_content = file_content
7
+ end
8
+
9
+ def validate_basics?
10
+ @parsed_file = XmlHasher.parse(@file_content)[:gpx]
11
+
12
+ !@parsed_file.nil?
13
+ end
14
+ end
15
+ end
data/lib/simple_trail.rb CHANGED
@@ -7,6 +7,8 @@ require File.expand_path('simple_trail/parser/base', __dir__)
7
7
  require File.expand_path('simple_trail/parser/gpx', __dir__)
8
8
  require File.expand_path('simple_trail/parser/gpx_string', __dir__)
9
9
  require File.expand_path('simple_trail/parser/extract_points', __dir__)
10
+ require File.expand_path('simple_trail/parser/validate_gpx', __dir__)
11
+ require File.expand_path('simple_trail/parser/validate_gpx_string', __dir__)
10
12
  require File.expand_path('simple_trail/manipulation/statistics', __dir__)
11
13
  require File.expand_path('simple_trail/manipulation/straightener', __dir__)
12
14
  require File.expand_path('simple_trail/manipulation/unifier', __dir__)
data/simple-trail.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'simple-trail'
8
- s.version = '0.3.0'
8
+ s.version = '0.3.2'
9
9
  s.date = '2020-08-03'
10
10
  s.summary = 'Readind and manipulating GPX and other trail representation file'
11
11
  s.description = 'Optimazing and manipulating GPX file data. For my private purposes mostly'