metar-parser 1.2.1 → 1.3.0
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 +4 -4
- data/lib/metar/data/base.rb +15 -0
- data/lib/metar/data/density_altitude.rb +15 -0
- data/lib/metar/data/direction.rb +9 -0
- data/lib/metar/data/distance.rb +27 -0
- data/lib/metar/data/lightning.rb +61 -0
- data/lib/metar/data/observer.rb +24 -0
- data/lib/metar/data/pressure.rb +23 -0
- data/lib/metar/data/remark.rb +98 -0
- data/lib/metar/data/runway_visible_range.rb +85 -0
- data/lib/metar/data/sky_condition.rb +61 -0
- data/lib/metar/data/speed.rb +22 -0
- data/lib/metar/data/station_code.rb +7 -0
- data/lib/metar/data/temperature.rb +21 -0
- data/lib/metar/data/temperature_and_dew_point.rb +18 -0
- data/lib/metar/data/time.rb +54 -0
- data/lib/metar/data/variable_wind.rb +25 -0
- data/lib/metar/data/vertical_visibility.rb +26 -0
- data/lib/metar/data/visibility.rb +71 -0
- data/lib/metar/data/visibility_remark.rb +8 -0
- data/lib/metar/data/weather_phenomenon.rb +86 -0
- data/lib/metar/data/wind.rb +82 -0
- data/lib/metar/data.rb +22 -636
- data/lib/metar/i18n.rb +6 -0
- data/lib/metar/parser.rb +165 -120
- data/lib/metar/report.rb +1 -1
- data/lib/metar/version.rb +2 -2
- data/lib/metar.rb +7 -6
- data/locales/de.yml +1 -0
- data/locales/en.yml +1 -0
- data/locales/it.yml +2 -1
- data/locales/pt-BR.yml +1 -0
- data/spec/data/density_altitude_spec.rb +12 -0
- data/spec/{distance_spec.rb → data/distance_spec.rb} +1 -1
- data/spec/data/lightning_spec.rb +49 -0
- data/spec/data/pressure_spec.rb +22 -0
- data/spec/data/remark_spec.rb +99 -0
- data/spec/data/runway_visible_range_spec.rb +92 -0
- data/spec/{sky_condition_spec.rb → data/sky_condition_spec.rb} +10 -6
- data/spec/data/speed_spec.rb +45 -0
- data/spec/data/temperature_spec.rb +36 -0
- data/spec/{variable_wind_spec.rb → data/variable_wind_spec.rb} +6 -6
- data/spec/{vertical_visibility_spec.rb → data/vertical_visibility_spec.rb} +2 -2
- data/spec/{data_spec.rb → data/visibility_remark_spec.rb} +1 -11
- data/spec/{visibility_spec.rb → data/visibility_spec.rb} +9 -7
- data/spec/{weather_phenomenon_spec.rb → data/weather_phenomenon_spec.rb} +7 -3
- data/spec/{wind_spec.rb → data/wind_spec.rb} +10 -7
- data/spec/parser_spec.rb +107 -13
- data/spec/report_spec.rb +12 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/station_spec.rb +2 -1
- metadata +56 -31
- data/spec/pressure_spec.rb +0 -22
- data/spec/remark_spec.rb +0 -147
- data/spec/runway_visible_range_spec.rb +0 -81
- data/spec/speed_spec.rb +0 -45
- data/spec/temperature_spec.rb +0 -36
data/spec/parser_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Metar::Parser do
|
|
12
12
|
let(:station) { double(Metar::Station) }
|
13
13
|
let(:raw) { double(Metar::Raw::Noaa, metar: metar, time: time) }
|
14
14
|
let(:metar) { "XXXX 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000" }
|
15
|
-
let(:time) {
|
15
|
+
let(:time) { Time.gm(2010, 02, 06) }
|
16
16
|
|
17
17
|
before do
|
18
18
|
allow(Metar::Station).to receive(:new) { station }
|
@@ -98,37 +98,37 @@ describe Metar::Parser do
|
|
98
98
|
it 'real' do
|
99
99
|
parser = setup_parser("PAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
100
100
|
|
101
|
-
expect(parser.observer).to eq(:real)
|
101
|
+
expect(parser.observer.value).to eq(:real)
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'auto' do
|
105
105
|
parser = setup_parser("CYXS 151034Z AUTO 09003KT 1/8SM FZFG VV001 M03/M03 A3019 RMK SLP263 ICG")
|
106
106
|
|
107
|
-
expect(parser.observer).to eq(:auto)
|
107
|
+
expect(parser.observer.value).to eq(:auto)
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'corrected' do
|
111
111
|
parser = setup_parser("PAIL 061610Z COR 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
112
112
|
|
113
|
-
expect(parser.observer).to eq(:corrected)
|
113
|
+
expect(parser.observer.value).to eq(:corrected)
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'corrected (Canadian, first correction)' do
|
117
117
|
parser = setup_parser('CYZU 310100Z CCA 26004KT 15SM FEW009 BKN040TCU BKN100 OVC210 15/12 A2996 RETS RMK SF1TCU4AC2CI1 SLP149')
|
118
118
|
|
119
|
-
expect(parser.observer).to eq(:corrected)
|
119
|
+
expect(parser.observer.value).to eq(:corrected)
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'corrected (Canadian, second correction)' do
|
123
123
|
parser = setup_parser('CYCX 052000Z CCB 30014G27KT 15SM DRSN SCT035 M02/M09 A2992 RMK SC4 SLP133')
|
124
124
|
|
125
|
-
expect(parser.observer).to eq(:corrected)
|
125
|
+
expect(parser.observer.value).to eq(:corrected)
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'corrected (Canadian, rare third correction)' do
|
129
129
|
parser = setup_parser('CYEG 120000Z CCC 12005KT 15SM FEW110 BKN190 03/M01 A2980 RMK AC2AC3 SLP122')
|
130
130
|
|
131
|
-
expect(parser.observer).to eq(:corrected)
|
131
|
+
expect(parser.observer.value).to eq(:corrected)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -260,7 +260,7 @@ describe Metar::Parser do
|
|
260
260
|
|
261
261
|
it 'sea_level_pressure' do
|
262
262
|
parser = setup_parser("PAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
263
|
-
expect(parser.sea_level_pressure.to_inches_of_mercury).to eq(29.10)
|
263
|
+
expect(parser.sea_level_pressure.pressure.to_inches_of_mercury).to eq(29.10)
|
264
264
|
end
|
265
265
|
|
266
266
|
it 'recent weather' do
|
@@ -290,7 +290,7 @@ describe Metar::Parser do
|
|
290
290
|
it 'parses sea level pressure' do
|
291
291
|
parser = setup_parser('CYZT 052200Z 31010KT 20SM SKC 17/12 A3005 RMK SLP174 20046')
|
292
292
|
|
293
|
-
expect(parser.remarks[0]).to be_a(Metar::SeaLevelPressure)
|
293
|
+
expect(parser.remarks[0]).to be_a(Metar::Data::SeaLevelPressure)
|
294
294
|
end
|
295
295
|
|
296
296
|
it 'parses extreme temperature' do
|
@@ -302,7 +302,7 @@ describe Metar::Parser do
|
|
302
302
|
it 'parses density altitude' do
|
303
303
|
parser = setup_parser('CYBW 010000Z AUTO VRB04KT 9SM SCT070 13/M01 A3028 RMK DENSITY ALT 4100FT=')
|
304
304
|
|
305
|
-
expect(parser.remarks[0]).to be_a(Metar::DensityAltitude)
|
305
|
+
expect(parser.remarks[0]).to be_a(Metar::Data::DensityAltitude)
|
306
306
|
expect(parser.remarks[0].height.value).to be_within(0.001).of(1249.68)
|
307
307
|
end
|
308
308
|
end
|
@@ -328,11 +328,105 @@ describe Metar::Parser do
|
|
328
328
|
end
|
329
329
|
end
|
330
330
|
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "#raw_attributes" do
|
334
|
+
let(:parts) { [station_code, datetime] }
|
335
|
+
let(:metar) { parts.join(" ") }
|
336
|
+
let(:station_code) { "PAIL" }
|
337
|
+
let(:datetime) { "061610Z" }
|
338
|
+
let(:observer) { "COR" }
|
339
|
+
let(:wind) { "24006KT" }
|
340
|
+
let(:variable_wind) { "350V050" }
|
341
|
+
let(:visibility) { "1 3/4SM" }
|
342
|
+
let(:minimum_visibility) { "3/4SM" }
|
343
|
+
let(:runway_visible_range) { "R12/1000N R30/1500N" }
|
344
|
+
let(:present_weather) { "-SN" }
|
345
|
+
let(:sky_conditions) { "BKN016 OVC030" }
|
346
|
+
let(:vertical_visibility) { "VV001" }
|
347
|
+
let(:temperature_and_dew_point) { "33/22" }
|
348
|
+
let(:sea_level_pressure) { "A2910" }
|
349
|
+
let(:recent_weather) { "RETS" }
|
350
|
+
let(:remarks) { "RMK AO2 P0000" }
|
351
|
+
let(:result) { subject.raw_attributes }
|
352
|
+
|
353
|
+
subject { setup_parser(metar) }
|
354
|
+
|
355
|
+
it "returns a Hash" do
|
356
|
+
expect(subject.raw_attributes).to be_a(Hash)
|
357
|
+
end
|
358
|
+
|
359
|
+
[
|
360
|
+
[:metar, "is the raw METAR string"],
|
361
|
+
[:station_code, "the station code"],
|
362
|
+
[:datetime, "the date/time string"],
|
363
|
+
].each do |attr, description|
|
364
|
+
context "#{attr}" do
|
365
|
+
specify ":#{attr} is #{description}" do
|
366
|
+
expect(result).to include(attr)
|
367
|
+
expect(result[attr]).to eq(self.send(attr))
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
[
|
373
|
+
[:observer, "an observer"],
|
374
|
+
[:wind, "wind"],
|
375
|
+
[:variable_wind, "variable wind"],
|
376
|
+
[:visibility, "visibility"],
|
377
|
+
[:runway_visible_range, "runway visible range"],
|
378
|
+
[:present_weather, "present weather"],
|
379
|
+
[:sky_conditions, "sky conditions"] ,
|
380
|
+
[:vertical_visibility, "vertical visibility"],
|
381
|
+
[:temperature_and_dew_point, "temperature and dew point"],
|
382
|
+
[:sea_level_pressure, "sea-level pressure"],
|
383
|
+
[:recent_weather, "recent weather"],
|
384
|
+
].each do |attr, name|
|
385
|
+
context "with #{name}" do
|
386
|
+
let(:parts) { super() + [send(attr)] }
|
387
|
+
|
388
|
+
specify ":#{attr} is set" do
|
389
|
+
expect(result).to include(attr)
|
390
|
+
expect(result[attr]).to eq(send(attr))
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
331
394
|
|
332
|
-
|
333
|
-
|
334
|
-
|
395
|
+
context "with wind and minimum visibility" do
|
396
|
+
let(:parts) { super() + [visibility, minimum_visibility] }
|
397
|
+
|
398
|
+
specify ":minimum_visibility is set" do
|
399
|
+
expect(result).to include(:minimum_visibility)
|
400
|
+
expect(result[:minimum_visibility]).to eq(minimum_visibility)
|
401
|
+
end
|
335
402
|
end
|
403
|
+
|
404
|
+
context "with CAVOK" do
|
405
|
+
let(:parts) { super() + ["CAVOK"] }
|
406
|
+
|
407
|
+
specify ":cavok is set" do
|
408
|
+
expect(result).to include(:cavok)
|
409
|
+
expect(result[:cavok]).to eq("CAVOK")
|
410
|
+
end
|
411
|
+
|
412
|
+
%i(
|
413
|
+
visibility
|
414
|
+
minimum_visibility
|
415
|
+
runway_visible_range
|
416
|
+
present_weather
|
417
|
+
sky_conditions
|
418
|
+
).each do |attr|
|
419
|
+
specify "#{attr} is not set" do
|
420
|
+
puts "attr: #{attr}"
|
421
|
+
expect(result).to_not include(attr)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
def setup_parser(metar)
|
428
|
+
raw = Metar::Raw::Data.new(metar, Time.now)
|
429
|
+
Metar::Parser.new(raw)
|
336
430
|
end
|
337
431
|
end
|
338
432
|
|
data/spec/report_spec.rb
CHANGED
@@ -83,7 +83,6 @@ describe Metar::Report do
|
|
83
83
|
:vertical_visibility,
|
84
84
|
:temperature,
|
85
85
|
:dew_point,
|
86
|
-
:sea_level_pressure,
|
87
86
|
].each do |attribute|
|
88
87
|
example attribute do
|
89
88
|
allow(parser).to receive(attribute) { attribute.to_s }
|
@@ -92,6 +91,18 @@ describe Metar::Report do
|
|
92
91
|
end
|
93
92
|
end
|
94
93
|
|
94
|
+
context "sea_level_pressure" do
|
95
|
+
let(:sea_level_pressure) do
|
96
|
+
double(Metar::Data::SeaLevelPressure, value: "slp")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns the summary" do
|
100
|
+
allow(parser).to receive(:sea_level_pressure) { sea_level_pressure }
|
101
|
+
|
102
|
+
expect(subject.sea_level_pressure).to eq("slp")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
95
106
|
context "#sky_summary" do
|
96
107
|
let(:conditions1) { double(to_summary: "skies1") }
|
97
108
|
|
data/spec/spec_helper.rb
CHANGED
@@ -13,7 +13,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../lib/metar')
|
|
13
13
|
|
14
14
|
RSpec::Matchers.define :be_temperature_extreme do |extreme, value|
|
15
15
|
match do |remark|
|
16
|
-
if not remark.is_a?(Metar::TemperatureExtreme)
|
16
|
+
if not remark.is_a?(Metar::Data::TemperatureExtreme)
|
17
17
|
false
|
18
18
|
elsif remark.extreme != extreme
|
19
19
|
false
|
data/spec/station_spec.rb
CHANGED
@@ -185,7 +185,8 @@ describe Metar::Station do
|
|
185
185
|
let(:metar) do
|
186
186
|
"PAIL 061610Z 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910"
|
187
187
|
end
|
188
|
-
let(:
|
188
|
+
let(:time) { Date.new(2010, 02, 06) }
|
189
|
+
let(:raw) { double(Metar::Raw, metar: metar, time: time) }
|
189
190
|
|
190
191
|
before do
|
191
192
|
# TODO: hack - once parser returns station this can be removed
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metar-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -166,6 +166,28 @@ files:
|
|
166
166
|
- Rakefile
|
167
167
|
- lib/metar.rb
|
168
168
|
- lib/metar/data.rb
|
169
|
+
- lib/metar/data/base.rb
|
170
|
+
- lib/metar/data/density_altitude.rb
|
171
|
+
- lib/metar/data/direction.rb
|
172
|
+
- lib/metar/data/distance.rb
|
173
|
+
- lib/metar/data/lightning.rb
|
174
|
+
- lib/metar/data/observer.rb
|
175
|
+
- lib/metar/data/pressure.rb
|
176
|
+
- lib/metar/data/remark.rb
|
177
|
+
- lib/metar/data/runway_visible_range.rb
|
178
|
+
- lib/metar/data/sky_condition.rb
|
179
|
+
- lib/metar/data/speed.rb
|
180
|
+
- lib/metar/data/station_code.rb
|
181
|
+
- lib/metar/data/temperature.rb
|
182
|
+
- lib/metar/data/temperature_and_dew_point.rb
|
183
|
+
- lib/metar/data/time.rb
|
184
|
+
- lib/metar/data/variable_wind.rb
|
185
|
+
- lib/metar/data/vertical_visibility.rb
|
186
|
+
- lib/metar/data/visibility.rb
|
187
|
+
- lib/metar/data/visibility_remark.rb
|
188
|
+
- lib/metar/data/weather_phenomenon.rb
|
189
|
+
- lib/metar/data/wind.rb
|
190
|
+
- lib/metar/i18n.rb
|
169
191
|
- lib/metar/parser.rb
|
170
192
|
- lib/metar/raw.rb
|
171
193
|
- lib/metar/report.rb
|
@@ -175,26 +197,28 @@ files:
|
|
175
197
|
- locales/en.yml
|
176
198
|
- locales/it.yml
|
177
199
|
- locales/pt-BR.yml
|
178
|
-
- spec/
|
179
|
-
- spec/distance_spec.rb
|
200
|
+
- spec/data/density_altitude_spec.rb
|
201
|
+
- spec/data/distance_spec.rb
|
202
|
+
- spec/data/lightning_spec.rb
|
203
|
+
- spec/data/pressure_spec.rb
|
204
|
+
- spec/data/remark_spec.rb
|
205
|
+
- spec/data/runway_visible_range_spec.rb
|
206
|
+
- spec/data/sky_condition_spec.rb
|
207
|
+
- spec/data/speed_spec.rb
|
208
|
+
- spec/data/temperature_spec.rb
|
209
|
+
- spec/data/variable_wind_spec.rb
|
210
|
+
- spec/data/vertical_visibility_spec.rb
|
211
|
+
- spec/data/visibility_remark_spec.rb
|
212
|
+
- spec/data/visibility_spec.rb
|
213
|
+
- spec/data/weather_phenomenon_spec.rb
|
214
|
+
- spec/data/wind_spec.rb
|
180
215
|
- spec/i18n_spec.rb
|
181
216
|
- spec/parser_spec.rb
|
182
|
-
- spec/pressure_spec.rb
|
183
217
|
- spec/raw_spec.rb
|
184
|
-
- spec/remark_spec.rb
|
185
218
|
- spec/report_spec.rb
|
186
|
-
- spec/runway_visible_range_spec.rb
|
187
|
-
- spec/sky_condition_spec.rb
|
188
219
|
- spec/spec_helper.rb
|
189
|
-
- spec/speed_spec.rb
|
190
220
|
- spec/station_spec.rb
|
191
|
-
|
192
|
-
- spec/variable_wind_spec.rb
|
193
|
-
- spec/vertical_visibility_spec.rb
|
194
|
-
- spec/visibility_spec.rb
|
195
|
-
- spec/weather_phenomenon_spec.rb
|
196
|
-
- spec/wind_spec.rb
|
197
|
-
homepage: http://github.com/joeyates/metar-parser
|
221
|
+
homepage: https://github.com/joeyates/metar-parser
|
198
222
|
licenses: []
|
199
223
|
metadata: {}
|
200
224
|
post_install_message:
|
@@ -205,7 +229,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
229
|
requirements:
|
206
230
|
- - ">="
|
207
231
|
- !ruby/object:Gem::Version
|
208
|
-
version: 1.
|
232
|
+
version: 2.1.0
|
209
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
234
|
requirements:
|
211
235
|
- - ">="
|
@@ -218,22 +242,23 @@ signing_key:
|
|
218
242
|
specification_version: 4
|
219
243
|
summary: A Ruby gem for worldwide weather reports
|
220
244
|
test_files:
|
221
|
-
- spec/runway_visible_range_spec.rb
|
222
|
-
- spec/weather_phenomenon_spec.rb
|
223
|
-
- spec/temperature_spec.rb
|
224
245
|
- spec/i18n_spec.rb
|
225
|
-
- spec/pressure_spec.rb
|
226
|
-
- spec/remark_spec.rb
|
227
|
-
- spec/speed_spec.rb
|
228
|
-
- spec/vertical_visibility_spec.rb
|
229
246
|
- spec/parser_spec.rb
|
230
|
-
- spec/
|
231
|
-
- spec/
|
247
|
+
- spec/data/runway_visible_range_spec.rb
|
248
|
+
- spec/data/weather_phenomenon_spec.rb
|
249
|
+
- spec/data/temperature_spec.rb
|
250
|
+
- spec/data/pressure_spec.rb
|
251
|
+
- spec/data/remark_spec.rb
|
252
|
+
- spec/data/speed_spec.rb
|
253
|
+
- spec/data/vertical_visibility_spec.rb
|
254
|
+
- spec/data/visibility_remark_spec.rb
|
255
|
+
- spec/data/visibility_spec.rb
|
256
|
+
- spec/data/distance_spec.rb
|
257
|
+
- spec/data/wind_spec.rb
|
258
|
+
- spec/data/lightning_spec.rb
|
259
|
+
- spec/data/sky_condition_spec.rb
|
260
|
+
- spec/data/density_altitude_spec.rb
|
261
|
+
- spec/data/variable_wind_spec.rb
|
232
262
|
- spec/report_spec.rb
|
233
263
|
- spec/raw_spec.rb
|
234
|
-
- spec/distance_spec.rb
|
235
|
-
- spec/wind_spec.rb
|
236
|
-
- spec/sky_condition_spec.rb
|
237
264
|
- spec/station_spec.rb
|
238
|
-
- spec/variable_wind_spec.rb
|
239
|
-
has_rdoc:
|
data/spec/pressure_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Metar::Pressure do
|
4
|
-
context '.parse' do
|
5
|
-
it 'interprets the Q prefix as hectopascals' do
|
6
|
-
expect(Metar::Pressure.parse('Q1300').value).to be_within(0.01).of(1.3)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'interprets the A prefix as inches of mercury' do
|
10
|
-
expect(Metar::Pressure.parse('A1234').value).to be_within(0.01).of(0.42)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'require 4 digits' do
|
14
|
-
expect(Metar::Pressure.parse('Q12345')).to be_nil
|
15
|
-
expect(Metar::Pressure.parse('A123')).to be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns nil for nil' do
|
19
|
-
expect(Metar::Pressure.parse(nil)).to be_nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/remark_spec.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Metar::Remark do
|
4
|
-
context '.parse' do
|
5
|
-
it 'delegate to subclasses' do
|
6
|
-
expect(Metar::Remark.parse('21012')).to be_a(Metar::TemperatureExtreme)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns nil for unrecognised' do
|
10
|
-
expect(Metar::Remark.parse('FOO')).to be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
context '6-hour maximum or minimum' do
|
14
|
-
[
|
15
|
-
['positive maximum', '10046', [:maximum, 4.6]],
|
16
|
-
['negative maximum', '11012', [:maximum, -1.2]],
|
17
|
-
['positive minimum', '20046', [:minimum, 4.6]],
|
18
|
-
['negative minimum', '21012', [:minimum, -1.2]],
|
19
|
-
].each do |docstring, raw, expected|
|
20
|
-
example docstring do
|
21
|
-
expect(Metar::Remark.parse(raw)).to be_temperature_extreme(*expected)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context '24-hour maximum and minimum' do
|
27
|
-
it 'returns minimum and maximum' do
|
28
|
-
max, min = Metar::Remark.parse('400461006')
|
29
|
-
|
30
|
-
expect(max).to be_temperature_extreme(:maximum, 4.6)
|
31
|
-
expect(min).to be_temperature_extreme(:minimum, -0.6)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'pressure tendency' do
|
36
|
-
it 'steady_then_decreasing' do
|
37
|
-
pt = Metar::Remark.parse('58033')
|
38
|
-
|
39
|
-
expect(pt).to be_a(Metar::PressureTendency)
|
40
|
-
expect(pt.character).to eq(:steady_then_decreasing)
|
41
|
-
expect(pt.value).to eq(3.3)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context '3-hour and 6-hour precipitation' do
|
46
|
-
it '60009' do
|
47
|
-
pr = Metar::Remark.parse('60009')
|
48
|
-
|
49
|
-
expect(pr).to be_a(Metar::Precipitation)
|
50
|
-
expect(pr.period).to eq(3)
|
51
|
-
expect(pr.amount.value).to eq(0.002286)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context '24-hour precipitation' do
|
56
|
-
it '70015' do
|
57
|
-
pr = Metar::Remark.parse('70015')
|
58
|
-
|
59
|
-
expect(pr).to be_a(Metar::Precipitation)
|
60
|
-
expect(pr.period).to eq(24)
|
61
|
-
expect(pr.amount.value).to eq(0.003810)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'automated station' do
|
66
|
-
|
67
|
-
[
|
68
|
-
['with precipitation dicriminator', 'AO1', [Metar::AutomatedStationType, :with_precipitation_discriminator]],
|
69
|
-
['without precipitation dicriminator', 'AO2', [Metar::AutomatedStationType, :without_precipitation_discriminator]],
|
70
|
-
].each do |docstring, raw, expected|
|
71
|
-
example docstring do
|
72
|
-
aut = Metar::Remark.parse(raw)
|
73
|
-
|
74
|
-
expect(aut).to be_a(expected[0])
|
75
|
-
expect(aut.type).to eq(expected[1])
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'sea-level pressure' do
|
81
|
-
it 'SLP125' do
|
82
|
-
slp = Metar::Remark.parse('SLP125')
|
83
|
-
|
84
|
-
expect(slp).to be_a(Metar::SeaLevelPressure)
|
85
|
-
expect(slp.pressure.value).to eq(0.0125)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'hourly temperature and dew point' do
|
90
|
-
it 'T00640036' do
|
91
|
-
htm = Metar::Remark.parse('T00641036')
|
92
|
-
|
93
|
-
expect(htm).to be_a(Metar::HourlyTemperaturAndDewPoint)
|
94
|
-
expect(htm.temperature.value).to eq(6.4)
|
95
|
-
expect(htm.dew_point.value).to eq(-3.6)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe Metar::Lightning do
|
102
|
-
context '.parse_chunks' do
|
103
|
-
[
|
104
|
-
['direction', 'LTG SE', [:default, nil, ['SE']]],
|
105
|
-
['distance direction', 'LTG DSNT SE', [:default, 16093.44, ['SE']]],
|
106
|
-
['distance direction and direction', 'LTG DSNT NE AND W', [:default, 16093.44, ['NE', 'W']]],
|
107
|
-
['distance direction-direction', 'LTG DSNT SE-SW', [:default, 16093.44, ['SE', 'SW']]],
|
108
|
-
['distance all quandrants', 'LTG DSNT ALQDS', [:default, 16093.44, ['N', 'E', 'S', 'W']]],
|
109
|
-
].each do |docstring, section, expected|
|
110
|
-
example docstring do
|
111
|
-
chunks = section.split(' ')
|
112
|
-
r = Metar::Lightning.parse_chunks(chunks)
|
113
|
-
|
114
|
-
expect(r).to be_a(Metar::Lightning)
|
115
|
-
expect(r.type).to eq(expected[0])
|
116
|
-
if expected[1]
|
117
|
-
expect(r.distance.value).to eq(expected[1])
|
118
|
-
else
|
119
|
-
expect(r.distance).to be_nil
|
120
|
-
end
|
121
|
-
expect(r.directions).to eq(expected[2])
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'removes parsed chunks' do
|
126
|
-
chunks = ['LTG', 'DSNT', 'SE', 'FOO']
|
127
|
-
|
128
|
-
r = Metar::Lightning.parse_chunks(chunks)
|
129
|
-
|
130
|
-
expect(chunks).to eq(['FOO'])
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'fails if the first chunk is not LTGnnn' do
|
134
|
-
expect do
|
135
|
-
Metar::Lightning.parse_chunks(['FOO'])
|
136
|
-
end.to raise_error(RuntimeError, /not lightning/)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "doesn't not fail if all chunks are parsed" do
|
140
|
-
chunks = ['LTG', 'DSNT', 'SE']
|
141
|
-
|
142
|
-
r = Metar::Lightning.parse_chunks(chunks)
|
143
|
-
|
144
|
-
expect(chunks).to eq([])
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
RSpec::Matchers.define :be_runway_visible_range do |designator, visibility1, visibility2, tendency|
|
5
|
-
match do |rvr|
|
6
|
-
if rvr.nil? && designator.nil?
|
7
|
-
true
|
8
|
-
elsif rvr.nil? != designator.nil?
|
9
|
-
false
|
10
|
-
elsif rvr.visibility1.nil? != visibility1.nil?
|
11
|
-
false
|
12
|
-
elsif rvr.visibility2.nil? != visibility2.nil?
|
13
|
-
false
|
14
|
-
elsif rvr.tendency.nil? != tendency.nil?
|
15
|
-
false
|
16
|
-
elsif ! visibility1.nil? &&
|
17
|
-
((rvr.visibility1.distance.value - visibility1[0]).abs > 0.01 ||
|
18
|
-
rvr.visibility1.comparator != visibility1[ 2 ])
|
19
|
-
false
|
20
|
-
elsif ! visibility2.nil? &&
|
21
|
-
((rvr.visibility2.distance.value - visibility2[0]).abs > 0.02 ||
|
22
|
-
rvr.visibility2.comparator != visibility2[2])
|
23
|
-
false
|
24
|
-
elsif tendency != rvr.tendency
|
25
|
-
false
|
26
|
-
else
|
27
|
-
true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe Metar::RunwayVisibleRange do
|
33
|
-
context '.parse' do
|
34
|
-
[
|
35
|
-
['understands R + nn + / + nnnn', 'R12/3400', ['12', [3400.00, nil, nil], nil, nil]],
|
36
|
-
['understands runway positions: RLC', 'R12L/3400', ['12L', [3400.00, nil, nil], nil, nil]],
|
37
|
-
['understands comparators: PM', 'R12/P3400', ['12', [3400.00, nil, :more_than], nil, nil]],
|
38
|
-
['understands tendencies: NUD', 'R12/3400U', ['12', [3400.00, nil, nil], nil, :improving]],
|
39
|
-
['understands feet', 'R12/3400FT', ['12', [1036.32, nil, nil], nil, nil]],
|
40
|
-
['understands second visibilities (m)', 'R26/0750V1200U', ['12', [ 750.0, nil, nil], [1200.0, nil, nil], :improving]],
|
41
|
-
['understands second visibilities (ft)', 'R12/3400V1800FT', ['12', [1036.32, nil, nil], [548.64, nil, nil], nil]],
|
42
|
-
['returns nil for nil', nil, [nil, nil, nil, nil]],
|
43
|
-
].each do |docstring, raw, expected|
|
44
|
-
example docstring do
|
45
|
-
expect(Metar::RunwayVisibleRange.parse(raw)).to be_runway_visible_range(*expected)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context '#to_s' do
|
51
|
-
before :all do
|
52
|
-
@locale = I18n.locale
|
53
|
-
I18n.locale = :it
|
54
|
-
end
|
55
|
-
|
56
|
-
after :all do
|
57
|
-
I18n.locale = @locale
|
58
|
-
end
|
59
|
-
|
60
|
-
[
|
61
|
-
['v1', :en, [[3400.00, nil, nil], nil, nil], 'runway 14: 3400m'],
|
62
|
-
['v1 and v2', :en, [[3400.00, nil, nil], [1900.00, nil, nil], nil ], 'runway 14: from 3400m to 1900m'],
|
63
|
-
['v1 and tendency', :en, [[3400.00, nil, nil], nil, :improving ], 'runway 14: 3400m improving'],
|
64
|
-
].each do |docstring, locale, (visibility1, visibility2, tendency), expected|
|
65
|
-
d1 = Metar::Distance.new(visibility1[0])
|
66
|
-
v1 = Metar::Visibility.new(d1, visibility1[1], visibility1[2])
|
67
|
-
v2 =
|
68
|
-
if ! visibility2.nil?
|
69
|
-
d2 = Metar::Distance.new(visibility2[0])
|
70
|
-
Metar::Visibility.new(d2, visibility2[1], visibility2[2])
|
71
|
-
else
|
72
|
-
nil
|
73
|
-
end
|
74
|
-
|
75
|
-
example docstring + " (#{locale})" do
|
76
|
-
I18n.locale = locale
|
77
|
-
expect(Metar::RunwayVisibleRange.new('14', v1, v2, tendency).to_s).to eq(expected)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
data/spec/speed_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Metar::Speed do
|
4
|
-
context '.parse' do
|
5
|
-
it 'returns nil for nil' do
|
6
|
-
speed = Metar::Speed.parse(nil)
|
7
|
-
|
8
|
-
expect(speed).to be_nil
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'parses knots' do
|
12
|
-
speed = Metar::Speed.parse('5KT')
|
13
|
-
|
14
|
-
expect(speed).to be_a(Metar::Speed)
|
15
|
-
expect(speed.value).to be_within(0.01).of(2.57)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'parses meters per second' do
|
19
|
-
speed = Metar::Speed.parse('7MPS')
|
20
|
-
|
21
|
-
expect(speed).to be_a(Metar::Speed)
|
22
|
-
expect(speed.value).to be_within(0.01).of(7.00)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'parses kilometers per hour' do
|
26
|
-
speed = Metar::Speed.parse('14KMH')
|
27
|
-
|
28
|
-
expect(speed).to be_a(Metar::Speed)
|
29
|
-
expect(speed.value).to be_within(0.01).of(3.89)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'trates straight numbers as kilomters per hour' do
|
33
|
-
speed = Metar::Speed.parse('14')
|
34
|
-
|
35
|
-
expect(speed).to be_a(Metar::Speed)
|
36
|
-
expect(speed.value).to be_within(0.01).of(3.89)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns nil for other strings' do
|
40
|
-
speed = Metar::Speed.parse('')
|
41
|
-
|
42
|
-
expect(speed).to be_nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|