metar-parser 1.5.0 → 1.7.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 +6 -48
  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 -14
  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 +105 -93
  25. data/lib/metar/data.rb +25 -23
  26. data/lib/metar/i18n.rb +5 -2
  27. data/lib/metar/parser.rb +46 -21
  28. data/lib/metar/raw.rb +32 -44
  29. data/lib/metar/report.rb +31 -20
  30. data/lib/metar/station.rb +29 -20
  31. data/lib/metar/version.rb +3 -1
  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 +192 -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 +92 -52
  58. metadata +53 -39
@@ -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