spektrum-log 0.0.17 → 0.0.18

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
  SHA1:
3
- metadata.gz: c6188ae32b6bdefbaa76994caba0d77b099583f6
4
- data.tar.gz: edbeefad5b51f3859e8e5f6de2facb66d83dd8d4
3
+ metadata.gz: fc976f15985bde7bbf197315c15bb995b1fe6694
4
+ data.tar.gz: 493abc0bf66f58f293728b3e0654cae30587ed81
5
5
  SHA512:
6
- metadata.gz: c39118bbb18b3199986e8f27bcf7a903416013009ec8eed2e56102fb25e52b9e5cf4501b40e70e6e38f52e44b3d963cea3dbf828752fabd9cb9096370f7394d0
7
- data.tar.gz: a3974ade56438c56911bd6bc6f2e53f7c23028815f4214753bf56edc948735be5dfe565d902733f506adf95f1cc09076d207f81acfa5aeb5f9c9c512135557e2
6
+ metadata.gz: d40599ff770aba1fb5ee39f322c3d61f3c76e495a03d366e98a64e8600f82914e46d58a5dd6e94ed70fbe9a07a2084d6bbcb809ddb52f5b1a4b9f087fac33e3a
7
+ data.tar.gz: ed4de0a1bf9877c27d3b6cba8e1bc1b195ec4488420ef0e6c0a7d8efd87c22008007b206ae93a1928a9b9c6172ddefd162ca9fd194610719de5fdf1b814985ca
@@ -79,6 +79,62 @@ module Spektrum
79
79
  @flights.map(&:duration).reduce(&:+)
80
80
  end
81
81
 
82
+ # Determines if KML methods can be called for this file.
83
+ #
84
+ # @return [Boolean] true if KML can be generated for this file, false otherwise
85
+ def to_kml?
86
+ @flights.any?(&:to_kml?)
87
+ end
88
+
89
+ # Converts the file into a KML document containing placemarks for each
90
+ # flight containing GPS data in this file.
91
+ #
92
+ # @param options [Hash] hash containing options for file
93
+ # @return [String] KML document for all applicable flights in the file
94
+ # @see #to_kml_file file options
95
+ def to_kml(options = {})
96
+ raise RuntimeError, 'No coordinates available for KML generation' unless to_kml?
97
+ to_kml_file(options).render
98
+ end
99
+
100
+ # Converts the flight into a KMLFile containing a placemark for this flight.
101
+ #
102
+ # @param options [Hash] hash containing options for file
103
+ # @option options [String] :name name option of KML::Document
104
+ # @option options [String] :description name option of KML::Document
105
+ # @return [KMLFile] file for the flight
106
+ def to_kml_file(options = {})
107
+ raise RuntimeError, 'No coordinates available for KML generation' unless to_kml?
108
+ options = apply_default_file_options(options)
109
+
110
+ style = 'kmlfile-style-id'
111
+ kml_flights = @flights.select(&:to_kml?)
112
+ marks = kml_flights.each_with_object({ :style_url => "##{style}" }).map(&:to_kml_placemark)
113
+
114
+ kml = KMLFile.new
115
+ kml.objects << KML::Document.new(
116
+ :name => options[:name],
117
+ :description => options[:description],
118
+ :styles => [
119
+ KML::Style.new(
120
+ :id => style,
121
+ :line_style => KML::LineStyle.new(:color => '7F00FFFF', :width => 4),
122
+ :poly_style => KML::PolyStyle.new(:color => '7F00FF00')
123
+ )
124
+ ],
125
+ :features => marks
126
+ )
127
+ kml
128
+ end
129
+
130
+ private
131
+
132
+ def apply_default_file_options options
133
+ options = { :name => 'Spektrum TLM GPS Path' }.merge(options)
134
+ options = { :description => 'Flight paths for GPS telemetry data' }.merge(options)
135
+ options
136
+ end
137
+
82
138
  end
83
139
 
84
140
  end
@@ -146,53 +146,105 @@ module Spektrum
146
146
  select_records SpeedRecord
147
147
  end
148
148
 
149
+ # Determines if KML methods can be called for this flight.
150
+ #
151
+ # @return [Boolean] true if KML can be generated for this flight, false otherwise
149
152
  def to_kml?
150
153
  gps1_records?
151
154
  end
152
155
 
153
- def to_kml
154
- unless to_kml?
155
- raise RuntimeError, 'No coordinates available for KML path generation'
156
- end
156
+ # Converts the flight into a KML document containing a placemark for this flight.
157
+ #
158
+ # @param file_options [Hash] hash containing options for file
159
+ # @param placemark_options [Hash] hash containing options for placemark
160
+ # @return [String] KML document for the flight
161
+ # @see #to_kml_file file options
162
+ # @see #to_kml_placemark placemark options
163
+ def to_kml(file_options = {}, placemark_options = {})
164
+ raise RuntimeError, 'No coordinates available for KML generation' unless to_kml?
165
+ to_kml_file(file_options, placemark_options).render
166
+ end
167
+
168
+ # Converts the flight into a KMLFile containing a placemark for this flight.
169
+ #
170
+ # @param file_options [Hash] hash containing options for file
171
+ # @option file_options [String] :name name option of KML::Document
172
+ # @option file_options [String] :description name option of KML::Document
173
+ # @option file_options [String] :style_id id option of KML::Style
174
+ # @param placemark_options [Hash] hash containing options for placemark
175
+ # @return [KMLFile] file for the flight
176
+ # @see #to_kml_placemark placemark options
177
+ def to_kml_file(file_options = {}, placemark_options = {})
178
+ raise RuntimeError, 'No coordinates available for KML generation' unless to_kml?
179
+ options = apply_default_file_options(file_options)
157
180
 
158
181
  kml = KMLFile.new
159
182
  kml.objects << KML::Document.new(
160
- :name => 'NAME HERE',
161
- :description => 'DESCRIPTION HERE',
183
+ :name => options[:name],
184
+ :description => options[:description],
162
185
  :styles => [
163
186
  KML::Style.new(
164
- :id => 'yellowLineGreenPoly',
165
- :line_style => KML::LineStyle.new(:color => '7f00ffff', :width => 4),
166
- :poly_style => KML::PolyStyle.new(:color => '7f00ff00')
187
+ :id => options[:style_id],
188
+ :line_style => KML::LineStyle.new(:color => '7F00FFFF', :width => 4),
189
+ :poly_style => KML::PolyStyle.new(:color => '7F00FF00')
167
190
  )
168
191
  ],
169
- :features => [
170
- KML::Placemark.new(
171
- :name => 'Absolute Extruded',
172
- :description => 'Transparent green wall with yellow outlines',
173
- :style_url => '#yellowLineGreenPoly',
174
- :geometry => KML::LineString.new(
175
- :extrude => true,
176
- :tessellate => true,
177
- :altitude_mode => 'absolute',
178
- :coordinates => gps1_records.map(&:coordinate).map { |c| c.join(',') }.join(' ')
179
- )
180
- )
181
- ]
192
+ :features => [ to_kml_placemark(placemark_options) ]
193
+ )
194
+ kml
195
+ end
196
+
197
+ # Converts the flight into a KML::Placemark containing GPS coordinates.
198
+ #
199
+ # @param options [Hash] hash containing options for placemark
200
+ # @option options [String] :altitude_mode altitude_mode option of KML::LineString
201
+ # @option options [Boolean] :extrude extrude option of KML::LineString
202
+ # @option options [String] :name name option of KML::Placemark
203
+ # @option options [String] :style_url style_url option of KML::Placemark
204
+ # @option options [Boolean] :tessellate tessellate option of KML::LineString
205
+ # @return [KML::Placemark] placemark for the flight
206
+ def to_kml_placemark(options = {})
207
+ raise RuntimeError, 'No coordinates available for KML generation' unless to_kml?
208
+ options = apply_default_placemark_options(options)
209
+
210
+ KML::Placemark.new(
211
+ :name => options[:name],
212
+ :style_url => options[:style_url],
213
+ :geometry => KML::LineString.new(
214
+ :altitude_mode => options[:altitude_mode],
215
+ :extrude => options[:extrude],
216
+ :tessellate => options[:tessellate],
217
+ :coordinates => gps1_records.map(&:coordinate).map { |c| c.join(',') }.join(' ')
218
+ )
182
219
  )
183
- kml.render
184
220
  end
185
221
 
186
222
  private
187
223
 
188
224
  # Determines if there are any records in this flight of the given type.
189
225
  #
190
- # @param type [Class] type of record to check for
226
+ # @param [Class] type type of record to check for
191
227
  # @return [Boolean] true if there are valid records, false otherwise
192
228
  def any_records?(type)
193
229
  @records.any? { |rec| rec.is_a?(type) && rec.valid? }
194
230
  end
195
231
 
232
+ def apply_default_file_options options
233
+ options = { :name => 'Spektrum TLM GPS Path' }.merge(options)
234
+ options = { :description => 'Flight paths for GPS telemetry data' }.merge(options)
235
+ options = { :style_id => 'default-poly-style' }.merge(options)
236
+ options
237
+ end
238
+
239
+ def apply_default_placemark_options options
240
+ options = { :altitude_mode => 'absolute' }.merge(options)
241
+ options = { :extrude => true }.merge(options)
242
+ options = { :name => "#{model_name} (#{duration.round(1)}s)" }.merge(options)
243
+ options = { :style_url => '#default-poly-style' }.merge(options)
244
+ options = { :tessellate => true }.merge(options)
245
+ options
246
+ end
247
+
196
248
  def derive_telemetry_unit
197
249
  return "None" unless basic_data_records? && flight_log_records?
198
250
  key = [basic_data_records.first.type, flight_log_records.first.type]
@@ -277,7 +277,11 @@ module Spektrum
277
277
  super timestamp, raw_data
278
278
  end
279
279
 
280
- # :knots, :mph, :kph
280
+ # Gets the speed, in desired unit.
281
+ #
282
+ # @param unit one of :knots, :mph, :kph to define desired unit
283
+ # @return [Float] speed in the desired unit
284
+ # @note This conversion has been verified via Spektrum STi
281
285
  def speed unit = :knots
282
286
  @speed ||= (hex_byte_field(3) * 100) + hex_byte_field(2)
283
287
  case unit
@@ -292,11 +296,19 @@ module Spektrum
292
296
  end
293
297
  end
294
298
 
299
+ # Gets the UTC 24-hour time. In the format: 'HH:MM:SS:CS' (CS=centiseconds).
300
+ #
301
+ # @return [String] UTC 24-hour time
302
+ # @note This conversion has been verified via Spektrum STi
295
303
  def time
296
304
  elements = 7.downto(4).map { |i| hex_byte_field(i) }
297
305
  @time ||= "%.2i:%.2i:%.2i.%.2i" % elements
298
306
  end
299
307
 
308
+ # Gets the number of satellites current visible and in-use.
309
+ #
310
+ # @return [Integer] number of active satellites
311
+ # @note This conversion has been verified via Spektrum STi
300
312
  def satellites
301
313
  @satellites ||= hex_byte_field(8)
302
314
  end
@@ -1,5 +1,5 @@
1
1
  module Spektrum
2
2
  module Log
3
- VERSION = "0.0.17"
3
+ VERSION = "0.0.18"
4
4
  end
5
5
  end
data/spec/file_spec.rb CHANGED
@@ -127,4 +127,57 @@ describe Spektrum::Log::File do
127
127
 
128
128
  end
129
129
 
130
+ describe '#to_kml' do
131
+
132
+ context 'with file with GPS data' do
133
+
134
+ subject { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
135
+
136
+ its(:to_kml?) { should be_true }
137
+
138
+ its(:to_kml) { should be_a(String) }
139
+
140
+ end
141
+
142
+ context 'with file without GPS data' do
143
+
144
+ subject { Spektrum::Log::File.new(data_file('3.TLM')) }
145
+
146
+ its(:to_kml?) { should be_false }
147
+
148
+ it 'should raise w/o kml data' do
149
+ expect { subject.to_kml }.to raise_error
150
+ end
151
+
152
+ end
153
+
154
+ end
155
+
156
+ describe '#to_kml_file' do
157
+
158
+ context 'with file with GPS data' do
159
+
160
+ subject { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
161
+
162
+ its(:to_kml_file) { should be_a(KMLFile) }
163
+
164
+ it 'should take options for file and placemark' do
165
+ kml = subject.to_kml_file({ :name => 'File Name' })
166
+ kml.objects[0].name.should eql('File Name')
167
+ end
168
+
169
+ end
170
+
171
+ context 'with file without GPS data' do
172
+
173
+ subject { Spektrum::Log::File.new(data_file('3.TLM')) }
174
+
175
+ it 'should raise w/o kml data' do
176
+ expect { subject.to_kml_file }.to raise_error
177
+ end
178
+
179
+ end
180
+
181
+ end
182
+
130
183
  end
data/spec/flight_spec.rb CHANGED
@@ -4,11 +4,11 @@ describe Spektrum::Log::Flight do
4
4
 
5
5
  context 'with data file 1.TLM' do
6
6
 
7
- let(:reader) { Spektrum::Log::File.new(data_file('1.TLM')) }
7
+ let(:file) { Spektrum::Log::File.new(data_file('1.TLM')) }
8
8
 
9
9
  context 'flight 1' do
10
10
 
11
- subject { reader.flights[0] }
11
+ subject { file.flights[0] }
12
12
 
13
13
  it { should have(4).headers }
14
14
 
@@ -34,7 +34,7 @@ describe Spektrum::Log::Flight do
34
34
 
35
35
  context 'flight 2' do
36
36
 
37
- subject { reader.flights[1] }
37
+ subject { file.flights[1] }
38
38
 
39
39
  it { should have(4).headers }
40
40
 
@@ -52,7 +52,7 @@ describe Spektrum::Log::Flight do
52
52
 
53
53
  context 'flight 3' do
54
54
 
55
- subject { reader.flights[2] }
55
+ subject { file.flights[2] }
56
56
 
57
57
  it { should have(4).headers }
58
58
 
@@ -72,11 +72,11 @@ describe Spektrum::Log::Flight do
72
72
 
73
73
  context 'with data file 2.TLM' do
74
74
 
75
- let(:reader) { Spektrum::Log::File.new(data_file('2.TLM')) }
75
+ let(:file) { Spektrum::Log::File.new(data_file('2.TLM')) }
76
76
 
77
77
  context 'flight 1' do
78
78
 
79
- subject { reader.flights[0] }
79
+ subject { file.flights[0] }
80
80
 
81
81
  it { should have(5).headers }
82
82
 
@@ -102,7 +102,7 @@ describe Spektrum::Log::Flight do
102
102
 
103
103
  context 'flight 305' do
104
104
 
105
- subject { reader.flights[304] }
105
+ subject { file.flights[304] }
106
106
 
107
107
  its(:model_name) { should eql('ERW|N XL ULTRALIGHT') }
108
108
 
@@ -114,7 +114,7 @@ describe Spektrum::Log::Flight do
114
114
 
115
115
  context 'flight 306' do
116
116
 
117
- subject { reader.flights[305] }
117
+ subject { file.flights[305] }
118
118
 
119
119
  its(:model_name) { should eql('ERW|N XL ULTRALIGHT') }
120
120
 
@@ -124,7 +124,7 @@ describe Spektrum::Log::Flight do
124
124
 
125
125
  context 'flight 308' do
126
126
 
127
- subject { reader.flights[307] }
127
+ subject { file.flights[307] }
128
128
 
129
129
  its(:model_name) { should eql('ERW|N XL ULTRALIGHT') }
130
130
 
@@ -134,7 +134,7 @@ describe Spektrum::Log::Flight do
134
134
 
135
135
  context 'flight 312' do
136
136
 
137
- subject { reader.flights[311] }
137
+ subject { file.flights[311] }
138
138
 
139
139
  its(:model_name) { should eql('ERW|N XL ULTRALIGHT') }
140
140
 
@@ -146,11 +146,11 @@ describe Spektrum::Log::Flight do
146
146
 
147
147
  context 'with data file 3.TLM' do
148
148
 
149
- let(:reader) { Spektrum::Log::File.new(data_file('3.TLM')) }
149
+ let(:file) { Spektrum::Log::File.new(data_file('3.TLM')) }
150
150
 
151
151
  context 'flight 1' do
152
152
 
153
- subject { reader.flights[0] }
153
+ subject { file.flights[0] }
154
154
 
155
155
  it { should have(5).headers }
156
156
 
@@ -166,7 +166,7 @@ describe Spektrum::Log::Flight do
166
166
 
167
167
  context 'flight 2' do
168
168
 
169
- subject { reader.flights[1] }
169
+ subject { file.flights[1] }
170
170
 
171
171
  it { should have(5).headers }
172
172
 
@@ -182,7 +182,7 @@ describe Spektrum::Log::Flight do
182
182
 
183
183
  context 'flight 3' do
184
184
 
185
- subject { reader.flights[2] }
185
+ subject { file.flights[2] }
186
186
 
187
187
  it { should have(5).headers }
188
188
 
@@ -198,7 +198,7 @@ describe Spektrum::Log::Flight do
198
198
 
199
199
  context 'flight 4' do
200
200
 
201
- subject { reader.flights[3] }
201
+ subject { file.flights[3] }
202
202
 
203
203
  it { should have(5).headers }
204
204
 
@@ -214,7 +214,7 @@ describe Spektrum::Log::Flight do
214
214
 
215
215
  context 'flight 5' do
216
216
 
217
- subject { reader.flights[4] }
217
+ subject { file.flights[4] }
218
218
 
219
219
  it { should have(5).headers }
220
220
 
@@ -230,7 +230,7 @@ describe Spektrum::Log::Flight do
230
230
 
231
231
  context 'flight 6' do
232
232
 
233
- subject { reader.flights[5] }
233
+ subject { file.flights[5] }
234
234
 
235
235
  it { should have(5).headers }
236
236
 
@@ -246,7 +246,7 @@ describe Spektrum::Log::Flight do
246
246
 
247
247
  context 'flight 7' do
248
248
 
249
- subject { reader.flights[6] }
249
+ subject { file.flights[6] }
250
250
 
251
251
  it { should have(5).headers }
252
252
 
@@ -262,7 +262,7 @@ describe Spektrum::Log::Flight do
262
262
 
263
263
  context 'flight 8' do
264
264
 
265
- subject { reader.flights[7] }
265
+ subject { file.flights[7] }
266
266
 
267
267
  it { should have(5).headers }
268
268
 
@@ -278,7 +278,7 @@ describe Spektrum::Log::Flight do
278
278
 
279
279
  context 'flight 9' do
280
280
 
281
- subject { reader.flights[8] }
281
+ subject { file.flights[8] }
282
282
 
283
283
  it { should have(5).headers }
284
284
 
@@ -296,11 +296,11 @@ describe Spektrum::Log::Flight do
296
296
 
297
297
  context 'with data file 4.TLM' do
298
298
 
299
- let(:reader) { Spektrum::Log::File.new(data_file('4.TLM')) }
299
+ let(:file) { Spektrum::Log::File.new(data_file('4.TLM')) }
300
300
 
301
301
  context 'flight 1' do
302
302
 
303
- subject { reader.flights[0] }
303
+ subject { file.flights[0] }
304
304
 
305
305
  it { should have(5).headers }
306
306
 
@@ -340,11 +340,11 @@ describe Spektrum::Log::Flight do
340
340
 
341
341
  context 'with data file GPS.TLM' do
342
342
 
343
- let(:reader) { Spektrum::Log::File.new(data_file('GPS.TLM')) }
343
+ let(:file) { Spektrum::Log::File.new(data_file('GPS.TLM')) }
344
344
 
345
345
  context 'flight 1' do
346
346
 
347
- subject { reader.flights[0] }
347
+ subject { file.flights[0] }
348
348
 
349
349
  its(:duration) { should be_within(1).of(697) }
350
350
 
@@ -364,7 +364,7 @@ describe Spektrum::Log::Flight do
364
364
 
365
365
  context 'flight 2' do
366
366
 
367
- subject { reader.flights[1] }
367
+ subject { file.flights[1] }
368
368
 
369
369
  its(:duration) { should be_within(1).of(733) }
370
370
 
@@ -386,11 +386,11 @@ describe Spektrum::Log::Flight do
386
386
 
387
387
  context 'with data file GPS2.TLM' do
388
388
 
389
- let(:reader) { Spektrum::Log::File.new(data_file('GPS2.TLM')) }
389
+ let(:file) { Spektrum::Log::File.new(data_file('GPS2.TLM')) }
390
390
 
391
391
  context 'flight 1' do
392
392
 
393
- subject { reader.flights[0] }
393
+ subject { file.flights[0] }
394
394
 
395
395
  its(:duration) { should be_within(1).of(503) }
396
396
 
@@ -410,7 +410,7 @@ describe Spektrum::Log::Flight do
410
410
 
411
411
  context 'flight 2' do
412
412
 
413
- subject { reader.flights[1] }
413
+ subject { file.flights[1] }
414
414
 
415
415
  its(:duration) { should be_within(1).of(347) }
416
416
 
@@ -430,11 +430,11 @@ describe Spektrum::Log::Flight do
430
430
 
431
431
  context 'with data file X5-G700.TLM' do
432
432
 
433
- let(:reader) { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
433
+ let(:file) { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
434
434
 
435
435
  context 'flight 1' do
436
436
 
437
- subject { reader.flights[0] }
437
+ subject { file.flights[0] }
438
438
 
439
439
  its(:duration) { should be_within(0.1).of(323.6) }
440
440
 
@@ -444,7 +444,7 @@ describe Spektrum::Log::Flight do
444
444
 
445
445
  context 'flight 2' do
446
446
 
447
- subject { reader.flights[1] }
447
+ subject { file.flights[1] }
448
448
 
449
449
  its(:duration) { should be_within(0.1).of(323.8) }
450
450
 
@@ -454,7 +454,7 @@ describe Spektrum::Log::Flight do
454
454
 
455
455
  context 'flight 3' do
456
456
 
457
- subject { reader.flights[2] }
457
+ subject { file.flights[2] }
458
458
 
459
459
  its(:duration) { should be_within(0.1).of(325.5) }
460
460
 
@@ -466,17 +466,17 @@ describe Spektrum::Log::Flight do
466
466
 
467
467
  context 'with data file X5-GPS1.TLM' do
468
468
 
469
- let(:reader) { Spektrum::Log::File.new(data_file('X5-GPS1.TLM')) }
469
+ let(:file) { Spektrum::Log::File.new(data_file('X5-GPS1.TLM')) }
470
470
 
471
471
  its 'flights should contain some gps coordinates' do
472
472
 
473
- reader.flights.select { |f| f.gps1_records? }.should have(4).flights
473
+ file.flights.select { |f| f.gps1_records? }.should have(4).flights
474
474
 
475
475
  end
476
476
 
477
477
  its 'longitudes should all be negative' do
478
478
 
479
- reader.flights.each do |flight|
479
+ file.flights.each do |flight|
480
480
 
481
481
  flight.gps1_records.each do |gps1|
482
482
  gps1.longitude.should be < 0.0
@@ -488,7 +488,7 @@ describe Spektrum::Log::Flight do
488
488
 
489
489
  context 'flight 1' do
490
490
 
491
- subject { reader.flights[0] }
491
+ subject { file.flights[0] }
492
492
 
493
493
  its(:duration) { should be_within(0.1).of(318.6) }
494
494
 
@@ -498,7 +498,7 @@ describe Spektrum::Log::Flight do
498
498
 
499
499
  context 'flight 2' do
500
500
 
501
- subject { reader.flights[1] }
501
+ subject { file.flights[1] }
502
502
 
503
503
  its(:duration) { should be_within(0.1).of(327.5) }
504
504
 
@@ -508,7 +508,7 @@ describe Spektrum::Log::Flight do
508
508
 
509
509
  context 'flight 3' do
510
510
 
511
- subject { reader.flights[2] }
511
+ subject { file.flights[2] }
512
512
 
513
513
  its(:duration) { should be_within(0.1).of(326.5) }
514
514
 
@@ -518,7 +518,7 @@ describe Spektrum::Log::Flight do
518
518
 
519
519
  context 'flight 4' do
520
520
 
521
- subject { reader.flights[3] }
521
+ subject { file.flights[3] }
522
522
 
523
523
  its(:duration) { should eql(0.0) }
524
524
 
@@ -528,7 +528,7 @@ describe Spektrum::Log::Flight do
528
528
 
529
529
  context 'flight 5' do
530
530
 
531
- subject { reader.flights[4] }
531
+ subject { file.flights[4] }
532
532
 
533
533
  its(:duration) { should be_within(0.1).of(332.6) }
534
534
 
@@ -540,17 +540,17 @@ describe Spektrum::Log::Flight do
540
540
 
541
541
  context 'with data file X5-GPS2.TLM' do
542
542
 
543
- let(:reader) { Spektrum::Log::File.new(data_file('X5-GPS2.TLM')) }
543
+ let(:file) { Spektrum::Log::File.new(data_file('X5-GPS2.TLM')) }
544
544
 
545
545
  its 'flights should contain some gps coordinates' do
546
546
 
547
- reader.flights.select { |f| f.gps1_records? }.should have(2).flights
547
+ file.flights.select { |f| f.gps1_records? }.should have(2).flights
548
548
 
549
549
  end
550
550
 
551
551
  its 'longitudes should all be negative' do
552
552
 
553
- reader.flights.each do |flight|
553
+ file.flights.each do |flight|
554
554
 
555
555
  flight.gps1_records.each do |gps1|
556
556
  gps1.longitude.should be < 0.0
@@ -562,17 +562,19 @@ describe Spektrum::Log::Flight do
562
562
 
563
563
  context 'flight 1' do
564
564
 
565
- subject { reader.flights[0] }
565
+ subject { file.flights[0] }
566
566
 
567
567
  its(:duration) { should be_within(0.1).of(328.6) }
568
568
 
569
569
  its(:telemetry_unit) { should == 'TM1000' }
570
570
 
571
+ its(:to_kml?) { should be_true }
572
+
571
573
  end
572
574
 
573
575
  context 'flight 2' do
574
576
 
575
- subject { reader.flights[1] }
577
+ subject { file.flights[1] }
576
578
 
577
579
  its(:duration) { should be_within(0.1).of(299.1) }
578
580
 
@@ -582,4 +584,112 @@ describe Spektrum::Log::Flight do
582
584
 
583
585
  end
584
586
 
587
+ describe '#to_kml' do
588
+
589
+ let(:file) { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
590
+
591
+ context 'with flight 1' do
592
+
593
+ subject { file.flights[0] }
594
+
595
+ its(:to_kml) { should be_a(String) }
596
+
597
+ it 'should take options for file and placemark' do
598
+ kml = subject.to_kml_file({ :name => 'File Name' }, { :name => 'Placemark Name' })
599
+ kml.objects[0].name.should eql('File Name')
600
+ kml.objects[0].features[0].name.should eql('Placemark Name')
601
+ end
602
+
603
+ end
604
+
605
+ context 'with flight 2' do
606
+
607
+ subject { file.flights[1] }
608
+
609
+ it 'should raise w/o kml data' do
610
+ expect { subject.to_kml }.to raise_error
611
+ end
612
+
613
+ end
614
+
615
+ context 'with flight 3' do
616
+
617
+ subject { file.flights[2] }
618
+
619
+ its(:to_kml) { should be_a(String) }
620
+
621
+ end
622
+
623
+ end
624
+
625
+ describe '#to_kml_file' do
626
+
627
+ let(:file) { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
628
+
629
+ context 'with flight 1' do
630
+
631
+ subject { file.flights[0] }
632
+
633
+ its(:to_kml_file) { should be_a(KMLFile) }
634
+
635
+ it 'should take options for file and placemark' do
636
+ kml = subject.to_kml_file({ :name => 'File Name' }, { :name => 'Placemark Name' })
637
+ kml.objects[0].name.should eql('File Name')
638
+ kml.objects[0].features[0].name.should eql('Placemark Name')
639
+ end
640
+
641
+ end
642
+
643
+ context 'with flight 2' do
644
+
645
+ subject { file.flights[1] }
646
+
647
+ it 'should raise w/o kml data' do
648
+ expect { subject.to_kml_file }.to raise_error
649
+ end
650
+
651
+ end
652
+
653
+ context 'with flight 3' do
654
+
655
+ subject { file.flights[2] }
656
+
657
+ its(:to_kml_file) { should be_a(KMLFile) }
658
+
659
+ end
660
+
661
+ end
662
+
663
+ describe '#to_kml_placemark' do
664
+
665
+ let(:file) { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
666
+
667
+ context 'with flight 1' do
668
+
669
+ subject { file.flights[0] }
670
+
671
+ its(:to_kml_placemark) { should be_a(KML::Placemark) }
672
+
673
+ end
674
+
675
+ context 'with flight 2' do
676
+
677
+ subject { file.flights[1] }
678
+
679
+ it 'should raise w/o kml data' do
680
+ expect { subject.to_kml_placemark }.to raise_error
681
+ end
682
+
683
+ end
684
+
685
+ context 'with flight 3' do
686
+
687
+ subject { file.flights[2] }
688
+
689
+ its(:to_kml_placemark) { should be_a(KML::Placemark) }
690
+
691
+ end
692
+
693
+ end
694
+
585
695
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spektrum-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Veys
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-13 00:00:00.000000000 Z
11
+ date: 2013-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print