metar-parser 1.5.0 → 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 +6 -48
- 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 -14
- 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 +105 -93
- data/lib/metar/data.rb +25 -23
- data/lib/metar/i18n.rb +5 -2
- data/lib/metar/parser.rb +46 -21
- 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 +3 -1
- 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 +192 -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 -42
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)
|