metar-parser 1.4.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -49
- data/Rakefile +2 -1
- data/lib/metar/data/base.rb +16 -10
- data/lib/metar/data/density_altitude.rb +16 -10
- data/lib/metar/data/direction.rb +10 -4
- data/lib/metar/data/distance.rb +27 -20
- data/lib/metar/data/lightning.rb +69 -60
- data/lib/metar/data/observer.rb +26 -20
- data/lib/metar/data/pressure.rb +28 -22
- data/lib/metar/data/remark.rb +146 -130
- data/lib/metar/data/runway_visible_range.rb +98 -78
- data/lib/metar/data/sky_condition.rb +68 -57
- data/lib/metar/data/speed.rb +21 -14
- data/lib/metar/data/station_code.rb +8 -4
- data/lib/metar/data/temperature.rb +21 -13
- data/lib/metar/data/temperature_and_dew_point.rb +22 -16
- data/lib/metar/data/time.rb +57 -47
- data/lib/metar/data/variable_wind.rb +30 -19
- data/lib/metar/data/vertical_visibility.rb +27 -21
- data/lib/metar/data/visibility.rb +91 -79
- data/lib/metar/data/visibility_remark.rb +16 -5
- data/lib/metar/data/weather_phenomenon.rb +92 -74
- data/lib/metar/data/wind.rb +106 -87
- data/lib/metar/data.rb +25 -23
- data/lib/metar/i18n.rb +5 -2
- data/lib/metar/parser.rb +47 -22
- data/lib/metar/raw.rb +32 -44
- data/lib/metar/report.rb +31 -20
- data/lib/metar/station.rb +28 -19
- data/lib/metar/version.rb +4 -2
- data/lib/metar.rb +2 -1
- data/locales/de.yml +1 -0
- data/locales/en.yml +1 -0
- data/locales/it.yml +1 -0
- data/locales/pt-BR.yml +1 -0
- data/spec/data/density_altitude_spec.rb +2 -1
- data/spec/data/distance_spec.rb +2 -1
- data/spec/data/lightning_spec.rb +26 -9
- data/spec/data/pressure_spec.rb +2 -0
- data/spec/data/remark_spec.rb +26 -9
- data/spec/data/runway_visible_range_spec.rb +71 -35
- data/spec/data/sky_condition_spec.rb +63 -19
- data/spec/data/speed_spec.rb +2 -0
- data/spec/data/temperature_spec.rb +2 -1
- data/spec/data/variable_wind_spec.rb +2 -0
- data/spec/data/vertical_visibility_spec.rb +4 -4
- data/spec/data/visibility_remark_spec.rb +2 -1
- data/spec/data/visibility_spec.rb +46 -25
- data/spec/data/weather_phenomenon_spec.rb +79 -24
- data/spec/data/wind_spec.rb +156 -38
- data/spec/i18n_spec.rb +2 -0
- data/spec/parser_spec.rb +224 -64
- data/spec/raw_spec.rb +40 -68
- data/spec/report_spec.rb +27 -25
- data/spec/spec_helper.rb +5 -6
- data/spec/station_spec.rb +43 -44
- metadata +56 -43
@@ -1,20 +1,21 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "spec_helper"
|
3
4
|
|
4
|
-
RSpec::Matchers.define :be_weather_phenomenon do |
|
5
|
+
RSpec::Matchers.define :be_weather_phenomenon do |mod, desc, phen, recent|
|
5
6
|
match do |wp|
|
6
|
-
if wp.nil? &&
|
7
|
+
if wp.nil? && phen.nil?
|
7
8
|
true
|
8
|
-
elsif wp.nil?
|
9
|
+
elsif wp.nil? != phen.nil?
|
9
10
|
false
|
10
|
-
elsif wp.phenomenon !=
|
11
|
+
elsif wp.phenomenon != phen
|
11
12
|
false
|
12
|
-
elsif wp.modifier
|
13
|
+
elsif wp.modifier != mod
|
13
14
|
false
|
14
|
-
elsif wp.descriptor !=
|
15
|
+
elsif wp.descriptor != desc
|
15
16
|
false
|
16
17
|
else
|
17
|
-
|
18
|
+
wp.recent == recent
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -22,15 +23,46 @@ end
|
|
22
23
|
describe Metar::Data::WeatherPhenomenon do
|
23
24
|
context '.parse' do
|
24
25
|
[
|
25
|
-
[
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
[
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
[
|
26
|
+
[
|
27
|
+
'simple phenomenon', 'BR',
|
28
|
+
[nil, nil, 'mist', false]
|
29
|
+
],
|
30
|
+
[
|
31
|
+
'descriptor + phenomenon', 'BCFG',
|
32
|
+
[nil, 'patches of', 'fog', false]
|
33
|
+
],
|
34
|
+
[
|
35
|
+
'thunderstorm and rain', 'TSRA',
|
36
|
+
[nil, 'thunderstorm and', 'rain', false]
|
37
|
+
],
|
38
|
+
[
|
39
|
+
'intensity + phenomenon', '+RA',
|
40
|
+
['heavy', nil, 'rain', false]
|
41
|
+
],
|
42
|
+
[
|
43
|
+
'intensity + proximity + phenomenon', '-VCTSRA',
|
44
|
+
['nearby light', 'thunderstorm and', 'rain', false]
|
45
|
+
],
|
46
|
+
[
|
47
|
+
'2 phenomena: SN RA', 'SNRA',
|
48
|
+
[nil, nil, 'snow and rain', false]
|
49
|
+
],
|
50
|
+
[
|
51
|
+
'2 phenomena: RA DZ', 'RADZ',
|
52
|
+
[nil, nil, 'rain and drizzle', false]
|
53
|
+
],
|
54
|
+
[
|
55
|
+
'modifier + descriptor + phenomenon', 'VCDRFG',
|
56
|
+
['nearby', 'low drifting', 'fog', false]
|
57
|
+
],
|
58
|
+
[
|
59
|
+
'recent', 'RESN',
|
60
|
+
[nil, nil, 'snow', true]
|
61
|
+
],
|
62
|
+
[
|
63
|
+
'returns nil for unmatched', 'FUBAR',
|
64
|
+
[nil, nil, nil, false]
|
65
|
+
]
|
34
66
|
].each do |docstring, raw, expected|
|
35
67
|
example docstring do
|
36
68
|
expect(described_class.parse(raw)).to be_weather_phenomenon(*expected)
|
@@ -49,12 +81,36 @@ describe Metar::Data::WeatherPhenomenon do
|
|
49
81
|
end
|
50
82
|
|
51
83
|
[
|
52
|
-
[
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
[
|
84
|
+
[
|
85
|
+
'simple phenomenon', :en,
|
86
|
+
[nil, nil, 'mist'],
|
87
|
+
'mist'
|
88
|
+
],
|
89
|
+
[
|
90
|
+
'simple phenomenon', :it,
|
91
|
+
[nil, nil, 'mist'],
|
92
|
+
'foschia'
|
93
|
+
],
|
94
|
+
[
|
95
|
+
'descriptor + phenomenon', :en,
|
96
|
+
[nil, 'patches of', 'fog'],
|
97
|
+
'patches of fog'
|
98
|
+
],
|
99
|
+
[
|
100
|
+
'thunderstorm and rain', :en,
|
101
|
+
[nil, 'thunderstorm and', 'rain'],
|
102
|
+
'thunderstorm and rain'
|
103
|
+
],
|
104
|
+
[
|
105
|
+
'modifier + phenomenon', :en,
|
106
|
+
['heavy', nil, 'drizzle'],
|
107
|
+
'heavy drizzle'
|
108
|
+
],
|
109
|
+
[
|
110
|
+
'modifier + descriptor + phenomenon', :en,
|
111
|
+
%w(heavy freezing drizzle),
|
112
|
+
'heavy freezing drizzle'
|
113
|
+
]
|
58
114
|
].each do |docstring, locale, (modifier, descriptor, phenomenon), expected|
|
59
115
|
example docstring + " (#{locale})" do
|
60
116
|
I18n.locale = locale
|
@@ -67,4 +123,3 @@ describe Metar::Data::WeatherPhenomenon do
|
|
67
123
|
end
|
68
124
|
end
|
69
125
|
end
|
70
|
-
|
data/spec/data/wind_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "spec_helper"
|
3
4
|
|
4
5
|
RSpec::Matchers.define :be_wind do |direction, speed, gusts|
|
@@ -15,11 +16,13 @@ RSpec::Matchers.define :be_wind do |direction, speed, gusts|
|
|
15
16
|
false
|
16
17
|
elsif direction.is_a?(Symbol) && wind.direction != direction
|
17
18
|
false
|
18
|
-
elsif direction.is_a?(M9t::Direction) &&
|
19
|
+
elsif direction.is_a?(M9t::Direction) &&
|
20
|
+
(wind.direction.value - direction).abs > 0.01
|
19
21
|
false
|
20
22
|
elsif speed.is_a?(Symbol) && wind.speed != speed
|
21
23
|
false
|
22
|
-
elsif speed.is_a?(Metar::Data::Speed) &&
|
24
|
+
elsif speed.is_a?(Metar::Data::Speed) &&
|
25
|
+
(wind.speed.value - speed).abs > 0.01
|
23
26
|
false
|
24
27
|
elsif !wind.gusts.nil? && (wind.gusts.value - gusts).abs > 0.01
|
25
28
|
false
|
@@ -33,37 +36,112 @@ describe Metar::Data::Wind do
|
|
33
36
|
context '.parse' do
|
34
37
|
[
|
35
38
|
# Direction and speed
|
36
|
-
[
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
[
|
41
|
-
|
39
|
+
[
|
40
|
+
'treats 5 digits as degrees and kilometers per hour', '12345',
|
41
|
+
[123.0, 12.50, nil]
|
42
|
+
],
|
43
|
+
[
|
44
|
+
'understands 5 digits + KMH', '12345KMH',
|
45
|
+
[123.0, 12.50, nil]
|
46
|
+
],
|
47
|
+
[
|
48
|
+
'understands 5 digits + MPS', '12345MPS',
|
49
|
+
[123.0, 45.00, nil]
|
50
|
+
],
|
51
|
+
[
|
52
|
+
'understands 5 digits + KT', '12345KT',
|
53
|
+
[123.0, 23.15, nil]
|
54
|
+
],
|
55
|
+
[
|
56
|
+
'rounds 360 down to 0', '36045KT',
|
57
|
+
[0.0, 23.15, nil]
|
58
|
+
],
|
59
|
+
[
|
60
|
+
'returns nil for directions outside 0 to 360', '88845KT',
|
61
|
+
[nil, nil, nil]
|
62
|
+
],
|
42
63
|
# +gusts
|
43
|
-
[
|
44
|
-
|
45
|
-
|
46
|
-
|
64
|
+
[
|
65
|
+
'understands 5 digits + G + 2 digits', '12345G67',
|
66
|
+
[123.0, 12.50, 18.61]
|
67
|
+
],
|
68
|
+
[
|
69
|
+
'understands 5 digits + G + 2 digits + KMH', '12345G67KMH',
|
70
|
+
[123.0, 12.50, 18.61]
|
71
|
+
],
|
72
|
+
[
|
73
|
+
'understands 5 digits + G + 2 digits + MPS', '12345G67MPS',
|
74
|
+
[123.0, 45.00, 67.00]
|
75
|
+
],
|
76
|
+
[
|
77
|
+
'understands 5 digits + G + 2 digits + KT', '12345G67KT',
|
78
|
+
[123.0, 23.15, 34.47]
|
79
|
+
],
|
47
80
|
# Variable direction
|
48
|
-
[
|
49
|
-
|
50
|
-
|
51
|
-
|
81
|
+
[
|
82
|
+
'understands VRB + 2 digits', 'VRB12',
|
83
|
+
[:variable_direction, 3.33, nil]
|
84
|
+
],
|
85
|
+
[
|
86
|
+
'understands VRB + 2 digits + KMH', 'VRB12KMH',
|
87
|
+
[:variable_direction, 3.33, nil]
|
88
|
+
],
|
89
|
+
[
|
90
|
+
'understands VRB + 2 digits + MPS', 'VRB12MPS',
|
91
|
+
[:variable_direction, 12.00, nil]
|
92
|
+
],
|
93
|
+
[
|
94
|
+
'understands VRB + 2 digits + KT', 'VRB12KT',
|
95
|
+
[:variable_direction, 6.17, nil]
|
96
|
+
],
|
52
97
|
# + gusts
|
53
|
-
[
|
54
|
-
|
55
|
-
|
56
|
-
|
98
|
+
[
|
99
|
+
'understands VRB + 2 digits + G + 2 digits', 'VRB45G67',
|
100
|
+
[:variable_direction, 12.50, 18.61]
|
101
|
+
],
|
102
|
+
[
|
103
|
+
'understands VRB + 2 digits + G + 2 digits + KMH', 'VRB45G67KMH',
|
104
|
+
[:variable_direction, 12.50, 18.61]
|
105
|
+
],
|
106
|
+
[
|
107
|
+
'understands VRB + 2 digits + G + 2 digits + MPS', 'VRB45G67MPS',
|
108
|
+
[:variable_direction, 45.00, 67.00]
|
109
|
+
],
|
110
|
+
[
|
111
|
+
'understands VRB + 2 digits + G + 2 digits + KT', 'VRB45G67KT',
|
112
|
+
[:variable_direction, 23.15, 34.47]
|
113
|
+
],
|
57
114
|
# Unknown direction
|
58
|
-
[
|
59
|
-
|
60
|
-
|
61
|
-
|
115
|
+
[
|
116
|
+
'understands /// + 2 digits', '///12',
|
117
|
+
[:unknown_direction, 3.33, nil]
|
118
|
+
],
|
119
|
+
[
|
120
|
+
'understands /// + 2 digits + KMH', '///12KMH',
|
121
|
+
[:unknown_direction, 3.33, nil]
|
122
|
+
],
|
123
|
+
[
|
124
|
+
'understands /// + 2 digits + MPS', '///12MPS',
|
125
|
+
[:unknown_direction, 12.00, nil]
|
126
|
+
],
|
127
|
+
[
|
128
|
+
'understands /// + 2 digits + KT', '///12KT',
|
129
|
+
[:unknown_direction, 6.17, nil]
|
130
|
+
],
|
62
131
|
# Unknown direction and speed
|
63
|
-
[
|
132
|
+
[
|
133
|
+
'understands /////', '/////',
|
134
|
+
[:unknown_direction, :unknown_speed, nil]
|
135
|
+
],
|
64
136
|
# Bad data
|
65
|
-
[
|
66
|
-
|
137
|
+
[
|
138
|
+
'returns nil for badly formatted values', 'XYZ12KT',
|
139
|
+
[nil, nil, nil]
|
140
|
+
],
|
141
|
+
[
|
142
|
+
'returns nil for nil', nil,
|
143
|
+
[nil, nil, nil]
|
144
|
+
]
|
67
145
|
].each do |docstring, raw, expected|
|
68
146
|
example docstring do
|
69
147
|
expect(described_class.parse(raw)).to be_wind(*expected)
|
@@ -82,16 +160,56 @@ describe Metar::Data::Wind do
|
|
82
160
|
end
|
83
161
|
|
84
162
|
[
|
85
|
-
[
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
[
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
163
|
+
[
|
164
|
+
'formats speed and direction',
|
165
|
+
:en, [nil, nil, nil],
|
166
|
+
'443km/h ESE'
|
167
|
+
],
|
168
|
+
[
|
169
|
+
'handles variable_direction',
|
170
|
+
:en, [:variable_direction, nil, nil],
|
171
|
+
'443km/h variable direction'
|
172
|
+
],
|
173
|
+
[
|
174
|
+
'handles unknown_direction',
|
175
|
+
:en, [:unknown_direction, nil, nil],
|
176
|
+
'443km/h unknown direction'
|
177
|
+
],
|
178
|
+
[
|
179
|
+
'handles unknown_speed',
|
180
|
+
:en, [nil, :unknown_speed, nil],
|
181
|
+
'unknown speed ESE'
|
182
|
+
],
|
183
|
+
[
|
184
|
+
'includes gusts',
|
185
|
+
:en, [nil, nil, Metar::Data::Speed.new(123)],
|
186
|
+
'443km/h ESE gusts 443km/h'
|
187
|
+
],
|
188
|
+
[
|
189
|
+
'formats speed and direction',
|
190
|
+
:it, [nil, nil, nil],
|
191
|
+
'443km/h ESE'
|
192
|
+
],
|
193
|
+
[
|
194
|
+
'handles variable_direction',
|
195
|
+
:it, [:variable_direction, nil, nil],
|
196
|
+
'443km/h direzione variabile'
|
197
|
+
],
|
198
|
+
[
|
199
|
+
'handles unknown_direction',
|
200
|
+
:it, [:unknown_direction, nil, nil],
|
201
|
+
'443km/h direzione sconosciuta'
|
202
|
+
],
|
203
|
+
[
|
204
|
+
'handles unknown_speed',
|
205
|
+
:it, [nil, :unknown_speed, nil],
|
206
|
+
'velocità sconosciuta ESE'
|
207
|
+
],
|
208
|
+
[
|
209
|
+
'includes gusts',
|
210
|
+
:it, [nil, nil, Metar::Data::Speed.new(123)],
|
211
|
+
'443km/h ESE folate di 443km/h'
|
212
|
+
]
|
95
213
|
].each do |docstring, locale, (direction, speed, gusts), expected|
|
96
214
|
direction ||= M9t::Direction.new(123)
|
97
215
|
speed ||= Metar::Data::Speed.new(123)
|