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,13 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Metar::Data::Lightning do
4
6
  context '.parse_chunks' do
5
7
  [
6
- ['direction', 'LTG SE', [:default, nil, ['SE']]],
7
- ['distance direction', 'LTG DSNT SE', [:default, 16093.44, ['SE']]],
8
- ['distance direction and direction', 'LTG DSNT NE AND W', [:default, 16093.44, ['NE', 'W']]],
9
- ['distance direction-direction', 'LTG DSNT SE-SW', [:default, 16093.44, ['SE', 'SW']]],
10
- ['distance all quandrants', 'LTG DSNT ALQDS', [:default, 16093.44, ['N', 'E', 'S', 'W']]],
8
+ [
9
+ 'direction', 'LTG SE',
10
+ [:default, nil, ['SE']]
11
+ ],
12
+ [
13
+ 'distance direction', 'LTG DSNT SE',
14
+ [:default, 16_093.44, ['SE']]
15
+ ],
16
+ [
17
+ 'distance direction and direction', 'LTG DSNT NE AND W',
18
+ [:default, 16_093.44, %w(NE W)]
19
+ ],
20
+ [
21
+ 'distance direction-direction', 'LTG DSNT SE-SW',
22
+ [:default, 16_093.44, %w(SE SW)]
23
+ ],
24
+ [
25
+ 'distance all quandrants', 'LTG DSNT ALQDS',
26
+ [:default, 16_093.44, %w(N E S W)]
27
+ ]
11
28
  ].each do |docstring, section, expected|
12
29
  example docstring do
13
30
  chunks = section.split(' ')
@@ -25,9 +42,9 @@ describe Metar::Data::Lightning do
25
42
  end
26
43
 
27
44
  it 'removes parsed chunks' do
28
- chunks = ['LTG', 'DSNT', 'SE', 'FOO']
45
+ chunks = %w(LTG DSNT SE FOO)
29
46
 
30
- r = described_class.parse_chunks(chunks)
47
+ described_class.parse_chunks(chunks)
31
48
 
32
49
  expect(chunks).to eq(['FOO'])
33
50
  end
@@ -39,9 +56,9 @@ describe Metar::Data::Lightning do
39
56
  end
40
57
 
41
58
  it "doesn't not fail if all chunks are parsed" do
42
- chunks = ['LTG', 'DSNT', 'SE']
59
+ chunks = %w(LTG DSNT SE)
43
60
 
44
- r = described_class.parse_chunks(chunks)
61
+ described_class.parse_chunks(chunks)
45
62
 
46
63
  expect(chunks).to eq([])
47
64
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Metar::Data::Pressure do
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Metar::Data::Remark do
4
6
  context '.parse' do
5
7
  it 'delegate to subclasses' do
6
- expect(described_class.parse('21012')).to be_a(Metar::Data::TemperatureExtreme)
8
+ expect(described_class.parse('21012')).
9
+ to be_a(Metar::Data::TemperatureExtreme)
7
10
  end
8
11
 
9
12
  it 'returns nil for unrecognised' do
@@ -12,13 +15,14 @@ describe Metar::Data::Remark do
12
15
 
13
16
  context '6-hour maximum or minimum' do
14
17
  [
15
- ['positive maximum', '10046', [:maximum, 4.6]],
18
+ ['positive maximum', '10046', [:maximum, 4.6]],
16
19
  ['negative maximum', '11012', [:maximum, -1.2]],
17
- ['positive minimum', '20046', [:minimum, 4.6]],
18
- ['negative minimum', '21012', [:minimum, -1.2]],
20
+ ['positive minimum', '20046', [:minimum, 4.6]],
21
+ ['negative minimum', '21012', [:minimum, -1.2]]
19
22
  ].each do |docstring, raw, expected|
20
23
  example docstring do
21
- expect(described_class.parse(raw)).to be_temperature_extreme(*expected)
24
+ expect(described_class.parse(raw)).
25
+ to be_temperature_extreme(*expected)
22
26
  end
23
27
  end
24
28
  end
@@ -27,7 +31,7 @@ describe Metar::Data::Remark do
27
31
  it 'returns minimum and maximum' do
28
32
  max, min = described_class.parse('400461006')
29
33
 
30
- expect(max).to be_temperature_extreme(:maximum, 4.6)
34
+ expect(max).to be_temperature_extreme(:maximum, 4.6)
31
35
  expect(min).to be_temperature_extreme(:minimum, -0.6)
32
36
  end
33
37
  end
@@ -63,10 +67,23 @@ describe Metar::Data::Remark do
63
67
  end
64
68
 
65
69
  context 'automated station' do
66
-
67
70
  [
68
- ['with precipitation dicriminator', 'AO1', [Metar::Data::AutomatedStationType, :with_precipitation_discriminator]],
69
- ['without precipitation dicriminator', 'AO2', [Metar::Data::AutomatedStationType, :without_precipitation_discriminator]],
71
+ [
72
+ 'with precipitation dicriminator',
73
+ 'AO1',
74
+ [
75
+ Metar::Data::AutomatedStationType,
76
+ :with_precipitation_discriminator
77
+ ]
78
+ ],
79
+ [
80
+ 'without precipitation dicriminator',
81
+ 'AO2',
82
+ [
83
+ Metar::Data::AutomatedStationType,
84
+ :without_precipitation_discriminator
85
+ ]
86
+ ]
70
87
  ].each do |docstring, raw, expected|
71
88
  example docstring do
72
89
  aut = described_class.parse(raw)
@@ -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