simple-trail 0.2.6 → 0.3.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
  SHA256:
3
- metadata.gz: d608b96acfb85c52f3fc307cd4e192323409b9751b0a9cc63a0186aba7e3e000
4
- data.tar.gz: 4e93f997eb2729fc3bcb39e0d554febb6414e794fd7c8f5ebdfc4f53769687cc
3
+ metadata.gz: 80b11153dae6617beaa321a66212e18b3d2f10aa986cbaccc07904faa15be4dd
4
+ data.tar.gz: a40a3b05bb2538c74f53185b5f2f5addc6932f14708e92d256be68ce26f21f7c
5
5
  SHA512:
6
- metadata.gz: 1f6d82618ceff0384f5b8238ab571831ba77ef69732a8761ad81e53050c02195349a400259bec1a86f6491a26e0d9ef33b01af5c991193e0956a56cdd10b9bc0
7
- data.tar.gz: 98789cedfb83d67f74c11646d021bc2087480ad26a9047f32b45aad271491ca8142cab1540a771ca1540f8905041d91fd722bb75e8dcb4c00f433dfee765dfdd
6
+ metadata.gz: 138f814cd98017dcd61aef761afc5c4a6ea1c21f426052ca56ed987928ce028e0d6da82e2aa13c2cdc03d41f93b9685fbfb0aa1dafc828b23357a758c8167bd0
7
+ data.tar.gz: c81fb032d0e916da5624407741055741e50bc955d146b69599ac7a5270787bb41f02c4b7642d966a4e6c1fde8a56defb6134283593b9dedfdfee7410df61e72e
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module Parser
3
+ class Base
4
+
5
+ private
6
+
7
+ def extract_points
8
+ points_reader = ExtractPoints.new(@parsed_file)
9
+ points_reader.read_points
10
+ @points = points_reader.points
11
+ @simplified_points = points_reader.simplified_points
12
+ end
13
+
14
+ def extract_pois
15
+ @points_of_interests = @parsed_file[:wpt]
16
+ end
17
+
18
+ def extract_data
19
+ metadata = @parsed_file[:metadata]
20
+ {
21
+ name: metadata[:name],
22
+ author: metadata[:author][:name]
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Parser
4
+ class ExtractPoints
5
+ attr_reader :simplified_points, :points
6
+
7
+ def initialize(parsed_file)
8
+ @parsed_file = parsed_file
9
+ end
10
+
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 } }
15
+ end
16
+ end
17
+ end
18
+
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parser
4
- class Gpx
4
+ class Gpx < Base
5
5
  attr_reader :simplified_points, :points, :points_of_interests, :parsed_file
6
6
 
7
7
  def initialize(filename)
@@ -19,25 +19,5 @@ module Parser
19
19
  def meta
20
20
  @meta ||= extract_data
21
21
  end
22
-
23
- private
24
-
25
- def extract_points
26
- segments = @parsed_file.dig(:trk, :trkseg)
27
- @points = segments.is_a?(Array) ? segments.map { |seg| seg[:trkpt] }.flatten : segments[:trkpt]
28
- @simplified_points = @points.map { |point| point.select { |key, _| [:lon, :lat].include? key } }
29
- end
30
-
31
- def extract_pois
32
- @points_of_interests = @parsed_file[:wpt]
33
- end
34
-
35
- def extract_data
36
- metadata = @parsed_file[:metadata]
37
- {
38
- name: metadata[:name],
39
- author: metadata[:author][:name]
40
- }
41
- end
42
22
  end
43
23
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Parser
3
+ class GpxString < Base
4
+ attr_reader :simplified_points, :points, :points_of_interests, :parsed_file
5
+
6
+ def initialize(file_content)
7
+ @file_content = file_content
8
+ end
9
+
10
+ def read
11
+ @parsed_file = XmlHasher.parse(@file_content)[:gpx]
12
+ fail unless @parsed_file
13
+ extract_points
14
+ extract_pois
15
+ end
16
+
17
+ def meta
18
+ @meta ||= extract_data
19
+ end
20
+ end
21
+ 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
@@ -3,7 +3,12 @@
3
3
  require 'geokit'
4
4
  require 'xmlhasher'
5
5
 
6
+ require File.expand_path('simple_trail/parser/base', __dir__)
6
7
  require File.expand_path('simple_trail/parser/gpx', __dir__)
8
+ require File.expand_path('simple_trail/parser/gpx_string', __dir__)
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__)
7
12
  require File.expand_path('simple_trail/manipulation/statistics', __dir__)
8
13
  require File.expand_path('simple_trail/manipulation/straightener', __dir__)
9
14
  require File.expand_path('simple_trail/manipulation/unifier', __dir__)
data/simple-trail.gemspec CHANGED
@@ -5,12 +5,13 @@ $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.2.6'
8
+ s.version = '0.3.1'
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'
12
12
  s.authors = ['Staszek Zawadzki']
13
13
  s.email = 'st.zawadzki@gmail.com'
14
+ s.homepage = 'https://github.com/PadawanBreslau/simple-trail'
14
15
 
15
16
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -0,0 +1,121 @@
1
+ <?xml version="1.0"?>
2
+ <catalog>
3
+ <book id="bk101">
4
+ <author>Gambardella, Matthew</author>
5
+ <title>XML Developer's Guide</title>
6
+ <genre>Computer</genre>
7
+ <price>44.95</price>
8
+ <publish_date>2000-10-01</publish_date>
9
+ <description>An in-depth look at creating applications
10
+ with XML.</description>
11
+ </book>
12
+ <book id="bk102">
13
+ <author>Ralls, Kim</author>
14
+ <title>Midnight Rain</title>
15
+ <genre>Fantasy</genre>
16
+ <price>5.95</price>
17
+ <publish_date>2000-12-16</publish_date>
18
+ <description>A former architect battles corporate zombies,
19
+ an evil sorceress, and her own childhood to become queen
20
+ of the world.</description>
21
+ </book>
22
+ <book id="bk103">
23
+ <author>Corets, Eva</author>
24
+ <title>Maeve Ascendant</title>
25
+ <genre>Fantasy</genre>
26
+ <price>5.95</price>
27
+ <publish_date>2000-11-17</publish_date>
28
+ <description>After the collapse of a nanotechnology
29
+ society in England, the young survivors lay the
30
+ foundation for a new society.</description>
31
+ </book>
32
+ <book id="bk104">
33
+ <author>Corets, Eva</author>
34
+ <title>Oberon's Legacy</title>
35
+ <genre>Fantasy</genre>
36
+ <price>5.95</price>
37
+ <publish_date>2001-03-10</publish_date>
38
+ <description>In post-apocalypse England, the mysterious
39
+ agent known only as Oberon helps to create a new life
40
+ for the inhabitants of London. Sequel to Maeve
41
+ Ascendant.</description>
42
+ </book>
43
+ <book id="bk105">
44
+ <author>Corets, Eva</author>
45
+ <title>The Sundered Grail</title>
46
+ <genre>Fantasy</genre>
47
+ <price>5.95</price>
48
+ <publish_date>2001-09-10</publish_date>
49
+ <description>The two daughters of Maeve, half-sisters,
50
+ battle one another for control of England. Sequel to
51
+ Oberon's Legacy.</description>
52
+ </book>
53
+ <book id="bk106">
54
+ <author>Randall, Cynthia</author>
55
+ <title>Lover Birds</title>
56
+ <genre>Romance</genre>
57
+ <price>4.95</price>
58
+ <publish_date>2000-09-02</publish_date>
59
+ <description>When Carla meets Paul at an ornithology
60
+ conference, tempers fly as feathers get ruffled.</description>
61
+ </book>
62
+ <book id="bk107">
63
+ <author>Thurman, Paula</author>
64
+ <title>Splish Splash</title>
65
+ <genre>Romance</genre>
66
+ <price>4.95</price>
67
+ <publish_date>2000-11-02</publish_date>
68
+ <description>A deep sea diver finds true love twenty
69
+ thousand leagues beneath the sea.</description>
70
+ </book>
71
+ <book id="bk108">
72
+ <author>Knorr, Stefan</author>
73
+ <title>Creepy Crawlies</title>
74
+ <genre>Horror</genre>
75
+ <price>4.95</price>
76
+ <publish_date>2000-12-06</publish_date>
77
+ <description>An anthology of horror stories about roaches,
78
+ centipedes, scorpions and other insects.</description>
79
+ </book>
80
+ <book id="bk109">
81
+ <author>Kress, Peter</author>
82
+ <title>Paradox Lost</title>
83
+ <genre>Science Fiction</genre>
84
+ <price>6.95</price>
85
+ <publish_date>2000-11-02</publish_date>
86
+ <description>After an inadvertant trip through a Heisenberg
87
+ Uncertainty Device, James Salway discovers the problems
88
+ of being quantum.</description>
89
+ </book>
90
+ <book id="bk110">
91
+ <author>O'Brien, Tim</author>
92
+ <title>Microsoft .NET: The Programming Bible</title>
93
+ <genre>Computer</genre>
94
+ <price>36.95</price>
95
+ <publish_date>2000-12-09</publish_date>
96
+ <description>Microsoft's .NET initiative is explored in
97
+ detail in this deep programmer's reference.</description>
98
+ </book>
99
+ <book id="bk111">
100
+ <author>O'Brien, Tim</author>
101
+ <title>MSXML3: A Comprehensive Guide</title>
102
+ <genre>Computer</genre>
103
+ <price>36.95</price>
104
+ <publish_date>2000-12-01</publish_date>
105
+ <description>The Microsoft MSXML3 parser is covered in
106
+ detail, with attention to XML DOM interfaces, XSLT processing,
107
+ SAX and more.</description>
108
+ </book>
109
+ <book id="bk112">
110
+ <author>Galos, Mike</author>
111
+ <title>Visual Studio 7: A Comprehensive Guide</title>
112
+ <genre>Computer</genre>
113
+ <price>49.95</price>
114
+ <publish_date>2001-04-16</publish_date>
115
+ <description>Microsoft Visual Studio 7 is explored in depth,
116
+ looking at how Visual Basic, Visual C++, C#, and ASP+ are
117
+ integrated into a comprehensive development
118
+ environment.</description>
119
+ </book>
120
+ </catalog>
121
+
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Parser::GpxString do
6
+ it 'reads the file' do
7
+ gpx_parser = described_class.new(File.new('./spec/examples/test_1.gpx').read)
8
+ expect { gpx_parser.read }.not_to raise_error
9
+ expect(gpx_parser.parsed_file).not_to be_nil
10
+ end
11
+
12
+ it 'reads metadata' do
13
+ gpx_parser = described_class.new(File.new('./spec/examples/test_1.gpx').read)
14
+ gpx_parser.read
15
+
16
+ expect(gpx_parser.meta[:author]).to eq 'choosen'
17
+ expect(gpx_parser.meta[:name]).to eq '06.06.2020 18:56'
18
+ end
19
+
20
+ it 'reads points simplified/all' do
21
+ gpx_parser = described_class.new(File.new('./spec/examples/test_1.gpx').read)
22
+ gpx_parser.read
23
+ expect(gpx_parser.points.size).to eq 190
24
+ expect(gpx_parser.points.size).to eq gpx_parser.simplified_points.size
25
+
26
+ random_index = rand(gpx_parser.points.size)
27
+ expect(gpx_parser.points[random_index][:lat]).to eq gpx_parser.simplified_points[random_index][:lat]
28
+ expect(gpx_parser.points[random_index][:lon]).to eq gpx_parser.simplified_points[random_index][:lon]
29
+ end
30
+
31
+ it 'reads file with segments' do
32
+ gpx_parser = described_class.new(File.new('./spec/examples/test_with_segments.gpx').read)
33
+ expect { gpx_parser.read }.not_to raise_error
34
+
35
+ expect(gpx_parser.points.size).to eq 355
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Parser::ValidateGpx do
6
+ it 'validates a proper file' do
7
+ gpx_validator = described_class.new('./spec/examples/test_1.gpx')
8
+ expect(gpx_validator.validate_basics?).to be(true)
9
+ end
10
+
11
+ it 'returns false if improper file' do
12
+ gpx_validator = described_class.new('./spec/examples/not_a_gpx.gpx')
13
+ expect(gpx_validator.validate_basics?).to be(false)
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Parser::ValidateGpxString do
6
+ it 'validates the string' do
7
+ gpx_validator = described_class.new(File.new('./spec/examples/test_1.gpx').read)
8
+ expect(gpx_validator.validate_basics?).to be(true)
9
+ end
10
+
11
+ it 'returns false if improper file' do
12
+ gpx_validator = described_class.new(File.new('./spec/examples/not_a_gpx.gpx').read)
13
+ expect(gpx_validator.validate_basics?).to be(false)
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Staszek Zawadzki
@@ -96,10 +96,16 @@ files:
96
96
  - lib/simple_trail/manipulation/statistics.rb
97
97
  - lib/simple_trail/manipulation/straightener.rb
98
98
  - lib/simple_trail/manipulation/unifier.rb
99
+ - lib/simple_trail/parser/base.rb
100
+ - lib/simple_trail/parser/extract_points.rb
99
101
  - lib/simple_trail/parser/gpx.rb
102
+ - lib/simple_trail/parser/gpx_string.rb
103
+ - lib/simple_trail/parser/validate_gpx.rb
104
+ - lib/simple_trail/parser/validate_gpx_string.rb
100
105
  - simple-trail.gemspec
101
106
  - spec/examples/gss20-full-official.gpx
102
107
  - spec/examples/kbl.gpx
108
+ - spec/examples/not_a_gpx.gpx
103
109
  - spec/examples/pois.gpx
104
110
  - spec/examples/test-xxl.gpx
105
111
  - spec/examples/test_1.gpx
@@ -124,8 +130,11 @@ files:
124
130
  - spec/manipulation/unifier_spec.rb
125
131
  - spec/parser/gpx_poi_spec.rb
126
132
  - spec/parser/gpx_spec.rb
133
+ - spec/parser/gpx_string_spec.rb
134
+ - spec/parser/validate_gpx_spec.rb
135
+ - spec/parser/validate_gpx_string_spec.rb
127
136
  - spec/spec_helper.rb
128
- homepage:
137
+ homepage: https://github.com/PadawanBreslau/simple-trail
129
138
  licenses:
130
139
  - MIT
131
140
  metadata: {}
@@ -151,6 +160,7 @@ summary: Readind and manipulating GPX and other trail representation file
151
160
  test_files:
152
161
  - spec/examples/gss20-full-official.gpx
153
162
  - spec/examples/kbl.gpx
163
+ - spec/examples/not_a_gpx.gpx
154
164
  - spec/examples/pois.gpx
155
165
  - spec/examples/test-xxl.gpx
156
166
  - spec/examples/test_1.gpx
@@ -175,4 +185,7 @@ test_files:
175
185
  - spec/manipulation/unifier_spec.rb
176
186
  - spec/parser/gpx_poi_spec.rb
177
187
  - spec/parser/gpx_spec.rb
188
+ - spec/parser/gpx_string_spec.rb
189
+ - spec/parser/validate_gpx_spec.rb
190
+ - spec/parser/validate_gpx_string_spec.rb
178
191
  - spec/spec_helper.rb