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.
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 +28 -19
  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 +43 -44
  58. metadata +56 -42
@@ -1,30 +1,29 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
- RSpec::Matchers.define :be_runway_visible_range do |designator, visibility1, visibility2, tendency|
5
+ RSpec::Matchers.define :be_runway_visible_range do |designator, v1, v2, tend|
5
6
  match do |rvr|
6
- if rvr.nil? && designator.nil?
7
+ if rvr.nil? && designator.nil?
7
8
  true
8
- elsif rvr.nil? != designator.nil?
9
- false
10
- elsif rvr.visibility1.nil? != visibility1.nil?
9
+ elsif rvr.nil? != designator.nil?
11
10
  false
12
- elsif rvr.visibility2.nil? != visibility2.nil?
11
+ elsif rvr.visibility1.nil? != v1.nil?
13
12
  false
14
- elsif rvr.tendency.nil? != tendency.nil?
13
+ elsif rvr.visibility2.nil? != v2.nil?
15
14
  false
16
- elsif ! visibility1.nil? &&
17
- ((rvr.visibility1.distance.value - visibility1[0]).abs > 0.01 ||
18
- rvr.visibility1.comparator != visibility1[ 2 ])
15
+ elsif rvr.tendency.nil? != tend.nil?
19
16
  false
20
- elsif ! visibility2.nil? &&
21
- ((rvr.visibility2.distance.value - visibility2[0]).abs > 0.02 ||
22
- rvr.visibility2.comparator != visibility2[2])
17
+ elsif !v1.nil? &&
18
+ ((rvr.visibility1.distance.value - v1[0]).abs > 0.01 ||
19
+ rvr.visibility1.comparator != v1[2])
23
20
  false
24
- elsif tendency != rvr.tendency
21
+ elsif !v2.nil? &&
22
+ ((rvr.visibility2.distance.value - v2[0]).abs > 0.02 ||
23
+ rvr.visibility2.comparator != v2[2])
25
24
  false
26
25
  else
27
- true
26
+ tend == rvr.tendency
28
27
  end
29
28
  end
30
29
  end
@@ -32,17 +31,44 @@ end
32
31
  describe Metar::Data::RunwayVisibleRange do
33
32
  context '.parse' do
34
33
  [
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/1800V3400FT', ['12', [548.64, nil, nil], [1036.32, nil, nil], nil]],
42
- ['understands second RVR (ft) w/ tendency', 'R29/1800V3400FT/U', ['29', [548.64, nil, nil], [1036.32, nil, nil], :improving]],
43
- ['returns nil for nil', nil, [nil, nil, nil, nil]],
44
- ].each do |docstring, raw, expected|
45
- example docstring do
34
+ [
35
+ 'understands R + nn + / + nnnn', 'R12/3400',
36
+ ['12', [3400.00, nil, nil], nil, nil]
37
+ ],
38
+ [
39
+ 'understands runway positions: RLC', 'R12L/3400',
40
+ ['12L', [3400.00, nil, nil], nil, nil]
41
+ ],
42
+ [
43
+ 'understands comparators: PM', 'R12/P3400',
44
+ ['12', [3400.00, nil, :more_than], nil, nil]
45
+ ],
46
+ [
47
+ 'understands tendencies: NUD', 'R12/3400U',
48
+ ['12', [3400.00, nil, nil], nil, :improving]
49
+ ],
50
+ [
51
+ 'understands feet', 'R12/3400FT',
52
+ ['12', [1036.32, nil, nil], nil, nil]
53
+ ],
54
+ [
55
+ 'understands second visibilities (m)', 'R26/0750V1200U',
56
+ ['12', [750.0, nil, nil], [1200.0, nil, nil], :improving]
57
+ ],
58
+ [
59
+ 'understands second visibilities (ft)', 'R12/1800V3400FT',
60
+ ['12', [548.64, nil, nil], [1036.32, nil, nil], nil]
61
+ ],
62
+ [
63
+ 'understands second RVR (ft) w/ tendency', 'R29/1800V3400FT/U',
64
+ ['29', [548.64, nil, nil], [1036.32, nil, nil], :improving]
65
+ ],
66
+ [
67
+ 'returns nil for nil', nil,
68
+ [nil, nil, nil, nil]
69
+ ]
70
+ ].each do |title, raw, expected|
71
+ example title do
46
72
  expect(described_class.parse(raw)).to be_runway_visible_range(*expected)
47
73
  end
48
74
  end
@@ -59,26 +85,36 @@ describe Metar::Data::RunwayVisibleRange do
59
85
  end
60
86
 
61
87
  [
62
- ['v1', :en, [[3400.00, nil, nil], nil, nil], 'runway 14: 3400m'],
63
- ['v1 and v2', :en, [[3400.00, nil, nil], [1900.00, nil, nil], nil ], 'runway 14: from 3400m to 1900m'],
64
- ['v1 and tendency', :en, [[3400.00, nil, nil], nil, :improving ], 'runway 14: 3400m improving'],
65
- ].each do |docstring, locale, (visibility1, visibility2, tendency), expected|
88
+ [
89
+ 'v1',
90
+ :en, [[3400.00, nil, nil], nil, nil],
91
+ 'runway 14: 3400m'
92
+ ],
93
+ [
94
+ 'v1 and v2',
95
+ :en, [[3400.00, nil, nil], [1900.00, nil, nil], nil],
96
+ 'runway 14: from 3400m to 1900m'
97
+ ],
98
+ [
99
+ 'v1 and tendency',
100
+ :en, [[3400.00, nil, nil], nil, :improving],
101
+ 'runway 14: 3400m improving'
102
+ ]
103
+ ].each do |title, locale, (visibility1, visibility2, tendency), expected|
66
104
  d1 = Metar::Data::Distance.new(visibility1[0])
67
105
  v1 = Metar::Data::Visibility.new(
68
106
  nil, distance: d1, direction: visibility1[1], comparator: visibility1[2]
69
107
  )
70
108
  v2 =
71
- if ! visibility2.nil?
109
+ if !visibility2.nil?
72
110
  d2 = Metar::Data::Distance.new(visibility2[0])
73
111
  Metar::Data::Visibility.new(
74
112
  nil,
75
113
  distance: d2, direction: visibility2[1], comparator: visibility2[2]
76
114
  )
77
- else
78
- nil
79
115
  end
80
116
 
81
- example docstring + " (#{locale})" do
117
+ example title + " (#{locale})" do
82
118
  I18n.locale = locale
83
119
  subject = described_class.new(
84
120
  nil,
@@ -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_sky_condition do |quantity, height, type|
@@ -11,10 +12,8 @@ RSpec::Matchers.define :be_sky_condition do |quantity, height, type|
11
12
  false
12
13
  elsif sk.height.is_a?(Metar::Data::Distance) && sk.height.value != height
13
14
  false
14
- elsif sk.type != type
15
- false
16
15
  else
17
- true
16
+ sk.type == type
18
17
  end
19
18
  end
20
19
  end
@@ -22,13 +21,34 @@ end
22
21
  describe Metar::Data::SkyCondition do
23
22
  context '.parse' do
24
23
  [
25
- ['understands clear skies codes', 'NSC', [nil, nil, nil]],
26
- ['quantity + height', 'BKN12', ['broken', 365.76, nil]],
27
- ['quantity + height + type', 'BKN12CB', ['broken', 365.76, 'cumulonimbus']],
28
- ['quantity + ///', 'BKN///', ['broken', nil, nil]],
29
- ['quantity + height + ///', 'FEW038///',['few', 1158.24, nil]],
30
- ['cumulonimbus only', 'CB', [nil, nil, 'cumulonimbus']], # seems non-standard, but occurs
31
- ['returns nil for unmatched', 'FUBAR', [:expect_nil, nil, nil]],
24
+ [
25
+ 'understands clear skies codes', 'NSC',
26
+ [nil, nil, nil]
27
+ ],
28
+ [
29
+ 'quantity + height', 'BKN12',
30
+ ['broken', 365.76, nil]
31
+ ],
32
+ [
33
+ 'quantity + height + type', 'BKN12CB',
34
+ ['broken', 365.76, 'cumulonimbus']
35
+ ],
36
+ [
37
+ 'quantity + ///', 'BKN///',
38
+ ['broken', nil, nil]
39
+ ],
40
+ [
41
+ 'quantity + height + ///', 'FEW038///',
42
+ ['few', 1158.24, nil]
43
+ ],
44
+ [
45
+ 'cumulonimbus only', 'CB', # seems non-standard, but occurs
46
+ [nil, nil, 'cumulonimbus']
47
+ ],
48
+ [
49
+ 'returns nil for unmatched', 'FUBAR',
50
+ [:expect_nil, nil, nil]
51
+ ]
32
52
  ].each do |docstring, raw, expected|
33
53
  example docstring do
34
54
  expect(described_class.parse(raw)).to be_sky_condition(*expected)
@@ -38,11 +58,26 @@ describe Metar::Data::SkyCondition do
38
58
 
39
59
  context '.to_summary' do
40
60
  [
41
- ['all values nil', [nil, nil, nil ], :en, 'clear skies' ],
42
- ['quantity', ['broken', nil, nil ], :en, 'broken cloud' ],
43
- ['quantity', ['broken', nil, nil ], :'en-US', 'broken clouds' ],
44
- ['quantity + type', ['broken', nil, 'cumulonimbus'], :en, 'broken cumulonimbus'],
45
- ['quantity + type', ['broken', nil, 'cumulonimbus'], :'en-US', 'broken cumulonimbus clouds'],
61
+ [
62
+ 'all values nil', [nil, nil, nil],
63
+ :en, 'clear skies'
64
+ ],
65
+ [
66
+ 'quantity', ['broken', nil, nil],
67
+ :en, 'broken cloud'
68
+ ],
69
+ [
70
+ 'quantity', ['broken', nil, nil],
71
+ :'en-US', 'broken clouds'
72
+ ],
73
+ [
74
+ 'quantity + type', ['broken', nil, 'cumulonimbus'],
75
+ :en, 'broken cumulonimbus'
76
+ ],
77
+ [
78
+ 'quantity + type', ['broken', nil, 'cumulonimbus'],
79
+ :'en-US', 'broken cumulonimbus clouds'
80
+ ]
46
81
  ].each do |docstring, (quantity, height, type), locale, expected|
47
82
  before { @old_locale = I18n.locale }
48
83
  after { I18n.locale = @old_locale }
@@ -59,9 +94,18 @@ describe Metar::Data::SkyCondition do
59
94
 
60
95
  context '.to_s' do
61
96
  [
62
- ['all values nil', [nil, nil, nil], 'clear skies' ],
63
- ['quantity', ['broken', 360, nil], 'broken cloud at 360' ],
64
- ['quantity + type', ['broken', 360, 'cumulonimbus'], 'broken cumulonimbus at 360'],
97
+ [
98
+ 'all values nil', [nil, nil, nil],
99
+ 'clear skies'
100
+ ],
101
+ [
102
+ 'quantity', ['broken', 360, nil],
103
+ 'broken cloud at 360'
104
+ ],
105
+ [
106
+ 'quantity + type', ['broken', 360, 'cumulonimbus'],
107
+ 'broken cumulonimbus at 360'
108
+ ]
65
109
  ].each do |docstring, (quantity, height, type), expected|
66
110
  example docstring do
67
111
  subject = described_class.new(
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Metar::Data::Speed do
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  describe Metar::Data::Temperature do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Metar::Data::VariableWind do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  RSpec::Matchers.define :be_distance do |expected|
@@ -8,10 +10,8 @@ RSpec::Matchers.define :be_distance do |expected|
8
10
  false
9
11
  elsif distance.value.nil? && expected.nil?
10
12
  true
11
- elsif (distance.value - expected).abs > 0.01
12
- false
13
13
  else
14
- true
14
+ (distance.value - expected).abs <= 0.01
15
15
  end
16
16
  end
17
17
  end
@@ -21,7 +21,7 @@ describe Metar::Data::VerticalVisibility do
21
21
  [
22
22
  ['VV + nnn', 'VV300', 9144],
23
23
  ['///', '///', nil],
24
- ['returns nil for unmatched', 'FUBAR', :expect_nil],
24
+ ['returns nil for unmatched', 'FUBAR', :expect_nil]
25
25
  ].each do |docstring, raw, expected|
26
26
  example docstring do
27
27
  expect(described_class.parse(raw)).to be_distance(expected)
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  describe Metar::Data::VisibilityRemark do
@@ -1,11 +1,12 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  RSpec::Matchers.define :be_visibility do |distance, direction, comparator|
5
6
  match do |visibility|
6
- if visibility.nil? && [ distance, direction, comparator ].all?(&:nil?)
7
+ if visibility.nil? && [distance, direction, comparator].all?(&:nil?)
7
8
  true
8
- elsif visibility.nil? != [ distance, direction, comparator ].all?(&:nil?)
9
+ elsif visibility.nil? != [distance, direction, comparator].all?(&:nil?)
9
10
  false
10
11
  elsif visibility.distance.nil? != distance.nil?
11
12
  false
@@ -13,11 +14,13 @@ RSpec::Matchers.define :be_visibility do |distance, direction, comparator|
13
14
  false
14
15
  elsif visibility.comparator.nil? != comparator.nil?
15
16
  false
16
- elsif visibility.distance.is_a?(Metar::Data::Distance) && (visibility.distance.value - distance).abs > 0.01
17
+ elsif visibility.distance.is_a?(Metar::Data::Distance) &&
18
+ (visibility.distance.value - distance).abs > 0.01
17
19
  false
18
- elsif visibility.direction.is_a?(M9t::Direction) && (visibility.direction.value - direction).abs > 0.01
20
+ elsif visibility.direction.is_a?(M9t::Direction) &&
21
+ (visibility.direction.value - direction).abs > 0.01
19
22
  false
20
- elsif comparator.is_a?(Symbol) && visibility.comparator != comparator
23
+ elsif comparator.is_a?(Symbol) && visibility.comparator != comparator
21
24
  false
22
25
  else
23
26
  true
@@ -28,17 +31,17 @@ end
28
31
  describe Metar::Data::Visibility do
29
32
  context '.parse' do
30
33
  [
31
- ['understands 9999', '9999', [10000.00, nil, :more_than]],
32
- ['understands nnnn + NDV', '0123NDV', [ 123.00, nil, nil]],
33
- ['understands n/nSM', '3/4SM', [ 1207.01, nil, nil]],
34
- ['understands 3/16SM', '3/16SM', [ 301.752, nil, nil]],
35
- ['understands n n/nSM', '1 1/4SM', [ 2011.68, nil, nil]],
36
- ['understands nSM', '5SM', [ 8046.72, nil, nil]],
37
- ['understands M1/4SM', 'M1/4SM', [ 402.34, nil, :less_than]],
38
- ['understands n + KM', '5KM', [ 5000.00, nil, nil]],
39
- ['understands n', '500', [ 500.00, nil, nil]],
40
- ['understands n + compass', '500NW', [ 500.00, 315.0, nil]],
41
- ['returns nil for unmatched', 'FUBAR', [ nil, nil, nil]],
34
+ ['understands 9999', '9999', [10_000.00, nil, :more_than]],
35
+ ['understands nnnn + NDV', '0123NDV', [123.00, nil, nil]],
36
+ ['understands n/nSM', '3/4SM', [1207.01, nil, nil]],
37
+ ['understands 3/16SM', '3/16SM', [301.752, nil, nil]],
38
+ ['understands n n/nSM', '1 1/4SM', [2011.68, nil, nil]],
39
+ ['understands nSM', '5SM', [8046.72, nil, nil]],
40
+ ['understands M1/4SM', 'M1/4SM', [402.34, nil, :less_than]],
41
+ ['understands n + KM', '5KM', [5000.00, nil, nil]],
42
+ ['understands n', '500', [500.00, nil, nil]],
43
+ ['understands n + compass', '500NW', [500.00, 315.0, nil]],
44
+ ['returns nil for unmatched', 'FUBAR', [nil, nil, nil]]
42
45
  ].each do |docstring, raw, expected|
43
46
  example docstring do
44
47
  expect(described_class.parse(raw)).to be_visibility(*expected)
@@ -57,15 +60,33 @@ describe Metar::Data::Visibility do
57
60
  end
58
61
 
59
62
  [
60
- ['with distance', :en, [ :set, nil, nil ], '4km'],
61
- ['with distance and direction', :en, [ :set, :set, nil ], '4km ESE'],
62
- ['with distance and comparator', :en, [ :set, nil, :less_than ], 'less than 4km'],
63
- ['with distance, direction and comparator', :en, [ :set, :set, :more_than ], 'more than 4km ESE'],
64
- ['with distance and direction', :it, [ :set, :set, nil ], '4km ESE'],
65
- ['with distance, direction and comparator', :it, [ :set, :set, :more_than ], 'piú di 4km ESE'],
63
+ [
64
+ 'with distance',
65
+ :en, [:set, nil, nil], '4km'
66
+ ],
67
+ [
68
+ 'with distance and direction',
69
+ :en, [:set, :set, nil], '4km ESE'
70
+ ],
71
+ [
72
+ 'with distance and comparator',
73
+ :en, [:set, nil, :less_than], 'less than 4km'
74
+ ],
75
+ [
76
+ 'with distance, direction and comparator',
77
+ :en, %i(set set more_than), 'more than 4km ESE'
78
+ ],
79
+ [
80
+ 'with distance and direction',
81
+ :it, [:set, :set, nil], '4km ESE'
82
+ ],
83
+ [
84
+ 'with distance, direction and comparator',
85
+ :it, %i(set set more_than), 'piú di 4km ESE'
86
+ ]
66
87
  ].each do |docstring, locale, (distance, direction, comparator), expected|
67
- distance = Metar::Data::Distance.new(4321) if distance == :set
68
- direction = M9t::Direction.new(123) if direction == :set
88
+ distance = Metar::Data::Distance.new(4321) if distance == :set
89
+ direction = M9t::Direction.new(123) if direction == :set
69
90
 
70
91
  example docstring + " (#{locale})" do
71
92
  I18n.locale = locale
@@ -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
-