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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -49
  3. data/Rakefile +2 -1
  4. data/lib/metar/data/base.rb +16 -10
  5. data/lib/metar/data/density_altitude.rb +16 -10
  6. data/lib/metar/data/direction.rb +10 -4
  7. data/lib/metar/data/distance.rb +27 -20
  8. data/lib/metar/data/lightning.rb +69 -60
  9. data/lib/metar/data/observer.rb +26 -20
  10. data/lib/metar/data/pressure.rb +28 -22
  11. data/lib/metar/data/remark.rb +146 -130
  12. data/lib/metar/data/runway_visible_range.rb +98 -78
  13. data/lib/metar/data/sky_condition.rb +68 -57
  14. data/lib/metar/data/speed.rb +21 -14
  15. data/lib/metar/data/station_code.rb +8 -4
  16. data/lib/metar/data/temperature.rb +21 -13
  17. data/lib/metar/data/temperature_and_dew_point.rb +22 -16
  18. data/lib/metar/data/time.rb +57 -47
  19. data/lib/metar/data/variable_wind.rb +30 -19
  20. data/lib/metar/data/vertical_visibility.rb +27 -21
  21. data/lib/metar/data/visibility.rb +91 -79
  22. data/lib/metar/data/visibility_remark.rb +16 -5
  23. data/lib/metar/data/weather_phenomenon.rb +92 -74
  24. data/lib/metar/data/wind.rb +106 -87
  25. data/lib/metar/data.rb +25 -23
  26. data/lib/metar/i18n.rb +5 -2
  27. data/lib/metar/parser.rb +47 -22
  28. data/lib/metar/raw.rb +32 -44
  29. data/lib/metar/report.rb +31 -20
  30. data/lib/metar/station.rb +28 -19
  31. data/lib/metar/version.rb +4 -2
  32. data/lib/metar.rb +2 -1
  33. data/locales/de.yml +1 -0
  34. data/locales/en.yml +1 -0
  35. data/locales/it.yml +1 -0
  36. data/locales/pt-BR.yml +1 -0
  37. data/spec/data/density_altitude_spec.rb +2 -1
  38. data/spec/data/distance_spec.rb +2 -1
  39. data/spec/data/lightning_spec.rb +26 -9
  40. data/spec/data/pressure_spec.rb +2 -0
  41. data/spec/data/remark_spec.rb +26 -9
  42. data/spec/data/runway_visible_range_spec.rb +71 -35
  43. data/spec/data/sky_condition_spec.rb +63 -19
  44. data/spec/data/speed_spec.rb +2 -0
  45. data/spec/data/temperature_spec.rb +2 -1
  46. data/spec/data/variable_wind_spec.rb +2 -0
  47. data/spec/data/vertical_visibility_spec.rb +4 -4
  48. data/spec/data/visibility_remark_spec.rb +2 -1
  49. data/spec/data/visibility_spec.rb +46 -25
  50. data/spec/data/weather_phenomenon_spec.rb +79 -24
  51. data/spec/data/wind_spec.rb +156 -38
  52. data/spec/i18n_spec.rb +2 -0
  53. data/spec/parser_spec.rb +224 -64
  54. data/spec/raw_spec.rb +40 -68
  55. data/spec/report_spec.rb +27 -25
  56. data/spec/spec_helper.rb +5 -6
  57. data/spec/station_spec.rb +43 -44
  58. metadata +56 -43
@@ -1,20 +1,21 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
- RSpec::Matchers.define :be_weather_phenomenon do |modifier, descriptor, phenomenon|
5
+ RSpec::Matchers.define :be_weather_phenomenon do |mod, desc, phen, recent|
5
6
  match do |wp|
6
- if wp.nil? && phenomenon.nil?
7
+ if wp.nil? && phen.nil?
7
8
  true
8
- elsif wp.nil? != phenomenon.nil?
9
+ elsif wp.nil? != phen.nil?
9
10
  false
10
- elsif wp.phenomenon != phenomenon
11
+ elsif wp.phenomenon != phen
11
12
  false
12
- elsif wp.modifier != modifier
13
+ elsif wp.modifier != mod
13
14
  false
14
- elsif wp.descriptor != descriptor
15
+ elsif wp.descriptor != desc
15
16
  false
16
17
  else
17
- true
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
- ['simple phenomenon', 'BR', [nil, nil, 'mist']],
26
- ['descriptor + phenomenon', 'BCFG', [nil, 'patches of', 'fog']],
27
- ['thunderstorm and rain', 'TSRA', [nil, 'thunderstorm and', 'rain']],
28
- ['intensity + phenomenon', '+RA', ['heavy', nil, 'rain']],
29
- ['intensity + proximity + phenomenon', '-VCTSRA', ['nearby light', 'thunderstorm and', 'rain']],
30
- ['2 phenomena: SN RA', 'SNRA', [nil, nil, 'snow and rain']],
31
- ['2 phenomena: RA DZ', 'RADZ', [nil, nil, 'rain and drizzle']],
32
- ['modifier + descriptor + phenomenon', 'VCDRFG', ['nearby', 'low drifting', 'fog']],
33
- ['returns nil for unmatched', 'FUBAR', [nil, nil, nil]],
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
- ['simple phenomenon', :en, [ nil, nil, 'mist'], 'mist'],
53
- ['simple phenomenon', :it, [ nil, nil, 'mist'], 'foschia'],
54
- ['descriptor + phenomenon', :en, [ nil, 'patches of', 'fog'], 'patches of fog'],
55
- ['thunderstorm and rain', :en, [ nil, 'thunderstorm and', 'rain'], 'thunderstorm and rain'],
56
- ['modifier + phenomenon', :en, ['heavy', nil, 'drizzle'], 'heavy drizzle'],
57
- ['modifier + descriptor + phenomenon', :en, ['heavy', 'freezing', 'drizzle'], 'heavy freezing drizzle'],
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
-
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
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) && (wind.direction.value - direction).abs > 0.01
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) && (wind.speed.value - speed).abs > 0.01
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
- ['treats 5 digits as degrees and kilometers per hour', '12345', [123.0, 12.50, nil]],
37
- ['understands 5 digits + KMH', '12345KMH', [123.0, 12.50, nil]],
38
- ['understands 5 digits + MPS', '12345MPS', [123.0, 45.00, nil]],
39
- ['understands 5 digits + KT', '12345KT', [123.0, 23.15, nil]],
40
- ['rounds 360 down to 0', '36045KT', [0.0, 23.15, nil]],
41
- ['returns nil for directions outside 0 to 360', '88845KT', [nil, nil, nil]],
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
- ['understands 5 digits + G + 2 digits', '12345G67', [123.0, 12.50, 18.61]],
44
- ['understands 5 digits + G + 2 digits + KMH', '12345G67KMH', [123.0, 12.50, 18.61]],
45
- ['understands 5 digits + G + 2 digits + MPS', '12345G67MPS', [123.0, 45.00, 67.00]],
46
- ['understands 5 digits + G + 2 digits + KT', '12345G67KT', [123.0, 23.15, 34.47]],
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
- ['understands VRB + 2 digits', 'VRB12', [:variable_direction, 3.33, nil]],
49
- ['understands VRB + 2 digits + KMH', 'VRB12KMH', [:variable_direction, 3.33, nil]],
50
- ['understands VRB + 2 digits + MPS', 'VRB12MPS', [:variable_direction, 12.00, nil]],
51
- ['understands VRB + 2 digits + KT', 'VRB12KT', [:variable_direction, 6.17, nil]],
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
- ['understands VRB + 2 digits + G + 2 digits', 'VRB45G67', [:variable_direction, 12.50, 18.61]],
54
- ['understands VRB + 2 digits + G + 2 digits + KMH', 'VRB45G67KMH', [:variable_direction, 12.50, 18.61]],
55
- ['understands VRB + 2 digits + G + 2 digits + MPS', 'VRB45G67MPS', [:variable_direction, 45.00, 67.00]],
56
- ['understands VRB + 2 digits + G + 2 digits + KT', 'VRB45G67KT', [:variable_direction, 23.15, 34.47]],
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
- ['understands /// + 2 digits', '///12', [:unknown_direction, 3.33, nil]],
59
- ['understands /// + 2 digits + KMH', '///12KMH', [:unknown_direction, 3.33, nil]],
60
- ['understands /// + 2 digits + MPS', '///12MPS', [:unknown_direction, 12.00, nil]],
61
- ['understands /// + 2 digits + KT', '///12KT', [:unknown_direction, 6.17, nil]],
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
- ['understands /////', '/////', [:unknown_direction, :unknown_speed, nil]],
132
+ [
133
+ 'understands /////', '/////',
134
+ [:unknown_direction, :unknown_speed, nil]
135
+ ],
64
136
  # Bad data
65
- ['returns nil for badly formatted values', 'XYZ12KT', [nil, nil, nil]],
66
- ['returns nil for nil', nil, [nil, nil, nil]],
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
- ['formats speed and direction', :en, [nil, nil, nil ], '443km/h ESE' ],
86
- ['handles variable_direction', :en, [:variable_direction, nil, nil ], '443km/h variable direction' ],
87
- ['handles unknown_direction', :en, [:unknown_direction, nil, nil ], '443km/h unknown direction' ],
88
- ['handles unknown_speed', :en, [nil, :unknown_speed, nil ], 'unknown speed ESE' ],
89
- ['includes gusts', :en, [nil, nil, Metar::Data::Speed.new(123)], '443km/h ESE gusts 443km/h' ],
90
- ['formats speed and direction', :it, [nil, nil, nil ], '443km/h ESE' ],
91
- ['handles variable_direction', :it, [:variable_direction, nil, nil ], '443km/h direzione variabile' ],
92
- ['handles unknown_direction', :it, [:unknown_direction, nil, nil ], '443km/h direzione sconosciuta'],
93
- ['handles unknown_speed', :it, [nil, :unknown_speed, nil ], 'velocità sconosciuta ESE' ],
94
- ['includes gusts', :it, [nil, nil, Metar::Data::Speed.new(123)], '443km/h ESE folate di 443km/h'],
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)
data/spec/i18n_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe I18n do