metar-parser 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metar/data/base.rb +15 -0
  3. data/lib/metar/data/density_altitude.rb +15 -0
  4. data/lib/metar/data/direction.rb +9 -0
  5. data/lib/metar/data/distance.rb +27 -0
  6. data/lib/metar/data/lightning.rb +61 -0
  7. data/lib/metar/data/observer.rb +24 -0
  8. data/lib/metar/data/pressure.rb +23 -0
  9. data/lib/metar/data/remark.rb +98 -0
  10. data/lib/metar/data/runway_visible_range.rb +85 -0
  11. data/lib/metar/data/sky_condition.rb +61 -0
  12. data/lib/metar/data/speed.rb +22 -0
  13. data/lib/metar/data/station_code.rb +7 -0
  14. data/lib/metar/data/temperature.rb +21 -0
  15. data/lib/metar/data/temperature_and_dew_point.rb +18 -0
  16. data/lib/metar/data/time.rb +54 -0
  17. data/lib/metar/data/variable_wind.rb +25 -0
  18. data/lib/metar/data/vertical_visibility.rb +26 -0
  19. data/lib/metar/data/visibility.rb +71 -0
  20. data/lib/metar/data/visibility_remark.rb +8 -0
  21. data/lib/metar/data/weather_phenomenon.rb +86 -0
  22. data/lib/metar/data/wind.rb +82 -0
  23. data/lib/metar/data.rb +22 -636
  24. data/lib/metar/i18n.rb +6 -0
  25. data/lib/metar/parser.rb +165 -120
  26. data/lib/metar/report.rb +1 -1
  27. data/lib/metar/version.rb +2 -2
  28. data/lib/metar.rb +7 -6
  29. data/locales/de.yml +1 -0
  30. data/locales/en.yml +1 -0
  31. data/locales/it.yml +2 -1
  32. data/locales/pt-BR.yml +1 -0
  33. data/spec/data/density_altitude_spec.rb +12 -0
  34. data/spec/{distance_spec.rb → data/distance_spec.rb} +1 -1
  35. data/spec/data/lightning_spec.rb +49 -0
  36. data/spec/data/pressure_spec.rb +22 -0
  37. data/spec/data/remark_spec.rb +99 -0
  38. data/spec/data/runway_visible_range_spec.rb +92 -0
  39. data/spec/{sky_condition_spec.rb → data/sky_condition_spec.rb} +10 -6
  40. data/spec/data/speed_spec.rb +45 -0
  41. data/spec/data/temperature_spec.rb +36 -0
  42. data/spec/{variable_wind_spec.rb → data/variable_wind_spec.rb} +6 -6
  43. data/spec/{vertical_visibility_spec.rb → data/vertical_visibility_spec.rb} +2 -2
  44. data/spec/{data_spec.rb → data/visibility_remark_spec.rb} +1 -11
  45. data/spec/{visibility_spec.rb → data/visibility_spec.rb} +9 -7
  46. data/spec/{weather_phenomenon_spec.rb → data/weather_phenomenon_spec.rb} +7 -3
  47. data/spec/{wind_spec.rb → data/wind_spec.rb} +10 -7
  48. data/spec/parser_spec.rb +107 -13
  49. data/spec/report_spec.rb +12 -1
  50. data/spec/spec_helper.rb +1 -1
  51. data/spec/station_spec.rb +2 -1
  52. metadata +56 -31
  53. data/spec/pressure_spec.rb +0 -22
  54. data/spec/remark_spec.rb +0 -147
  55. data/spec/runway_visible_range_spec.rb +0 -81
  56. data/spec/speed_spec.rb +0 -45
  57. data/spec/temperature_spec.rb +0 -36
@@ -0,0 +1,99 @@
1
+ require "spec_helper"
2
+
3
+ describe Metar::Data::Remark do
4
+ context '.parse' do
5
+ it 'delegate to subclasses' do
6
+ expect(described_class.parse('21012')).to be_a(Metar::Data::TemperatureExtreme)
7
+ end
8
+
9
+ it 'returns nil for unrecognised' do
10
+ expect(described_class.parse('FOO')).to be_nil
11
+ end
12
+
13
+ context '6-hour maximum or minimum' do
14
+ [
15
+ ['positive maximum', '10046', [:maximum, 4.6]],
16
+ ['negative maximum', '11012', [:maximum, -1.2]],
17
+ ['positive minimum', '20046', [:minimum, 4.6]],
18
+ ['negative minimum', '21012', [:minimum, -1.2]],
19
+ ].each do |docstring, raw, expected|
20
+ example docstring do
21
+ expect(described_class.parse(raw)).to be_temperature_extreme(*expected)
22
+ end
23
+ end
24
+ end
25
+
26
+ context '24-hour maximum and minimum' do
27
+ it 'returns minimum and maximum' do
28
+ max, min = described_class.parse('400461006')
29
+
30
+ expect(max).to be_temperature_extreme(:maximum, 4.6)
31
+ expect(min).to be_temperature_extreme(:minimum, -0.6)
32
+ end
33
+ end
34
+
35
+ context 'pressure tendency' do
36
+ it 'steady_then_decreasing' do
37
+ pt = described_class.parse('58033')
38
+
39
+ expect(pt).to be_a(Metar::Data::PressureTendency)
40
+ expect(pt.character).to eq(:steady_then_decreasing)
41
+ expect(pt.value).to eq(3.3)
42
+ end
43
+ end
44
+
45
+ context '3-hour and 6-hour precipitation' do
46
+ it '60009' do
47
+ pr = described_class.parse('60009')
48
+
49
+ expect(pr).to be_a(Metar::Data::Precipitation)
50
+ expect(pr.period).to eq(3)
51
+ expect(pr.amount.value).to eq(0.002286)
52
+ end
53
+ end
54
+
55
+ context '24-hour precipitation' do
56
+ it '70015' do
57
+ pr = described_class.parse('70015')
58
+
59
+ expect(pr).to be_a(Metar::Data::Precipitation)
60
+ expect(pr.period).to eq(24)
61
+ expect(pr.amount.value).to eq(0.003810)
62
+ end
63
+ end
64
+
65
+ context 'automated station' do
66
+
67
+ [
68
+ ['with precipitation dicriminator', 'AO1', [Metar::Data::AutomatedStationType, :with_precipitation_discriminator]],
69
+ ['without precipitation dicriminator', 'AO2', [Metar::Data::AutomatedStationType, :without_precipitation_discriminator]],
70
+ ].each do |docstring, raw, expected|
71
+ example docstring do
72
+ aut = described_class.parse(raw)
73
+
74
+ expect(aut).to be_a(expected[0])
75
+ expect(aut.type).to eq(expected[1])
76
+ end
77
+ end
78
+ end
79
+
80
+ context 'sea-level pressure' do
81
+ it 'SLP125' do
82
+ slp = described_class.parse('SLP125')
83
+
84
+ expect(slp).to be_a(Metar::Data::SeaLevelPressure)
85
+ expect(slp.pressure.value).to eq(0.0125)
86
+ end
87
+ end
88
+
89
+ context 'hourly temperature and dew point' do
90
+ it 'T00640036' do
91
+ htm = described_class.parse('T00641036')
92
+
93
+ expect(htm).to be_a(Metar::Data::HourlyTemperatureAndDewPoint)
94
+ expect(htm.temperature.value).to eq(6.4)
95
+ expect(htm.dew_point.value).to eq(-3.6)
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ RSpec::Matchers.define :be_runway_visible_range do |designator, visibility1, visibility2, tendency|
5
+ match do |rvr|
6
+ if rvr.nil? && designator.nil?
7
+ true
8
+ elsif rvr.nil? != designator.nil?
9
+ false
10
+ elsif rvr.visibility1.nil? != visibility1.nil?
11
+ false
12
+ elsif rvr.visibility2.nil? != visibility2.nil?
13
+ false
14
+ elsif rvr.tendency.nil? != tendency.nil?
15
+ false
16
+ elsif ! visibility1.nil? &&
17
+ ((rvr.visibility1.distance.value - visibility1[0]).abs > 0.01 ||
18
+ rvr.visibility1.comparator != visibility1[ 2 ])
19
+ false
20
+ elsif ! visibility2.nil? &&
21
+ ((rvr.visibility2.distance.value - visibility2[0]).abs > 0.02 ||
22
+ rvr.visibility2.comparator != visibility2[2])
23
+ false
24
+ elsif tendency != rvr.tendency
25
+ false
26
+ else
27
+ true
28
+ end
29
+ end
30
+ end
31
+
32
+ describe Metar::Data::RunwayVisibleRange do
33
+ context '.parse' do
34
+ [
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
46
+ expect(described_class.parse(raw)).to be_runway_visible_range(*expected)
47
+ end
48
+ end
49
+ end
50
+
51
+ context '#to_s' do
52
+ before :all do
53
+ @locale = I18n.locale
54
+ I18n.locale = :it
55
+ end
56
+
57
+ after :all do
58
+ I18n.locale = @locale
59
+ end
60
+
61
+ [
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|
66
+ d1 = Metar::Data::Distance.new(visibility1[0])
67
+ v1 = Metar::Data::Visibility.new(
68
+ nil, distance: d1, direction: visibility1[1], comparator: visibility1[2]
69
+ )
70
+ v2 =
71
+ if ! visibility2.nil?
72
+ d2 = Metar::Data::Distance.new(visibility2[0])
73
+ Metar::Data::Visibility.new(
74
+ nil,
75
+ distance: d2, direction: visibility2[1], comparator: visibility2[2]
76
+ )
77
+ else
78
+ nil
79
+ end
80
+
81
+ example docstring + " (#{locale})" do
82
+ I18n.locale = locale
83
+ subject = described_class.new(
84
+ nil,
85
+ designator: '14',
86
+ visibility1: v1, visibility2: v2, tendency: tendency
87
+ )
88
+ expect(subject.to_s).to eq(expected)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -9,7 +9,7 @@ RSpec::Matchers.define :be_sky_condition do |quantity, height, type|
9
9
  false
10
10
  elsif sk.quantity != quantity
11
11
  false
12
- elsif sk.height.is_a?(Metar::Distance) && sk.height.value != height
12
+ elsif sk.height.is_a?(Metar::Data::Distance) && sk.height.value != height
13
13
  false
14
14
  elsif sk.type != type
15
15
  false
@@ -19,7 +19,7 @@ RSpec::Matchers.define :be_sky_condition do |quantity, height, type|
19
19
  end
20
20
  end
21
21
 
22
- describe Metar::SkyCondition do
22
+ describe Metar::Data::SkyCondition do
23
23
  context '.parse' do
24
24
  [
25
25
  ['understands clear skies codes', 'NSC', [nil, nil, nil]],
@@ -31,7 +31,7 @@ describe Metar::SkyCondition do
31
31
  ['returns nil for unmatched', 'FUBAR', [:expect_nil, nil, nil]],
32
32
  ].each do |docstring, raw, expected|
33
33
  example docstring do
34
- expect(Metar::SkyCondition.parse(raw)).to be_sky_condition(*expected)
34
+ expect(described_class.parse(raw)).to be_sky_condition(*expected)
35
35
  end
36
36
  end
37
37
  end
@@ -48,7 +48,9 @@ describe Metar::SkyCondition do
48
48
  after { I18n.locale = @old_locale }
49
49
 
50
50
  example "#{docstring} - #{locale}" do
51
- condition = Metar::SkyCondition.new(quantity, height, type)
51
+ condition = described_class.new(
52
+ nil, quantity: quantity, height: height, type: type
53
+ )
52
54
  I18n.locale = locale
53
55
  expect(condition.to_summary).to eq(expected)
54
56
  end
@@ -62,8 +64,10 @@ describe Metar::SkyCondition do
62
64
  ['quantity + type', ['broken', 360, 'cumulonimbus'], 'broken cumulonimbus at 360'],
63
65
  ].each do |docstring, (quantity, height, type), expected|
64
66
  example docstring do
65
- condition = Metar::SkyCondition.new(quantity, height, type)
66
- expect(condition.to_s).to eq(expected)
67
+ subject = described_class.new(
68
+ nil, quantity: quantity, height: height, type: type
69
+ )
70
+ expect(subject.to_s).to eq(expected)
67
71
  end
68
72
  end
69
73
  end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe Metar::Data::Speed do
4
+ context ".parse" do
5
+ it "returns nil for nil" do
6
+ speed = described_class.parse(nil)
7
+
8
+ expect(speed).to be_nil
9
+ end
10
+
11
+ it "parses knots" do
12
+ speed = described_class.parse("5KT")
13
+
14
+ expect(speed).to be_a(described_class)
15
+ expect(speed.value).to be_within(0.01).of(2.57)
16
+ end
17
+
18
+ it "parses meters per second" do
19
+ speed = described_class.parse("7MPS")
20
+
21
+ expect(speed).to be_a(described_class)
22
+ expect(speed.value).to be_within(0.01).of(7.00)
23
+ end
24
+
25
+ it "parses kilometers per hour" do
26
+ speed = described_class.parse("14KMH")
27
+
28
+ expect(speed).to be_a(described_class)
29
+ expect(speed.value).to be_within(0.01).of(3.89)
30
+ end
31
+
32
+ it "treats straight numbers as kilomters per hour" do
33
+ speed = described_class.parse("14")
34
+
35
+ expect(speed).to be_a(described_class)
36
+ expect(speed.value).to be_within(0.01).of(3.89)
37
+ end
38
+
39
+ it "returns nil for other strings" do
40
+ speed = described_class.parse("")
41
+
42
+ expect(speed).to be_nil
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Metar::Data::Temperature do
5
+ context ".parse" do
6
+ it "understands numbers" do
7
+ t = described_class.parse("5")
8
+
9
+ expect(t.value).to be_within(0.01).of(5.0)
10
+ end
11
+
12
+ it "treats an M-prefix as a negative indicator" do
13
+ t = described_class.parse("M5")
14
+
15
+ expect(t.value).to be_within(0.01).of(-5.0)
16
+ end
17
+
18
+ it "returns nil for other values" do
19
+ expect(described_class.parse("")).to be_nil
20
+ expect(described_class.parse("aaa")).to be_nil
21
+ end
22
+ end
23
+
24
+ context "#to_s" do
25
+ it "abbreviates the units" do
26
+ t = described_class.new(5)
27
+
28
+ expect(t.to_s).to eq("5°C")
29
+ end
30
+
31
+ it "rounds to the nearest degree" do
32
+ expect(described_class.new(5.1).to_s).to eq("5°C")
33
+ expect(described_class.new(5.5).to_s).to eq("6°C")
34
+ end
35
+ end
36
+ end
@@ -1,30 +1,30 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Metar::VariableWind do
3
+ describe Metar::Data::VariableWind do
4
4
  context '.parse' do
5
5
  it 'understands nnn + V + nnn' do
6
- vw = Metar::VariableWind.parse('090V180')
6
+ vw = described_class.parse('090V180')
7
7
 
8
8
  expect(vw.direction1.value).to eq(90.0)
9
9
  expect(vw.direction2.value).to eq(180.0)
10
10
  end
11
11
 
12
12
  it 'accepts 360, rounding to 0 - 1' do
13
- vw = Metar::VariableWind.parse('360V090')
13
+ vw = described_class.parse('360V090')
14
14
 
15
15
  expect(vw.direction1.value).to eq(0.0)
16
16
  expect(vw.direction2.value).to eq(90.0)
17
17
  end
18
18
 
19
19
  it 'accepts 360, rounding to 0 - 2' do
20
- vw = Metar::VariableWind.parse('090V360')
20
+ vw = described_class.parse('090V360')
21
21
 
22
22
  expect(vw.direction1.value).to eq(90.0)
23
23
  expect(vw.direction2.value).to eq(0.0)
24
24
  end
25
25
 
26
26
  it 'returns nil for other' do
27
- vw = Metar::VariableWind.parse('XXX')
27
+ vw = described_class.parse('XXX')
28
28
 
29
29
  expect(vw).to be_nil
30
30
  end
@@ -32,7 +32,7 @@ describe Metar::VariableWind do
32
32
 
33
33
  context '#to_s' do
34
34
  it 'renders compatible values as compass directions' do
35
- vw = Metar::VariableWind.parse('090V180')
35
+ vw = described_class.parse('090V180')
36
36
 
37
37
  expect(vw.to_s).to eq('E - S')
38
38
  end
@@ -16,7 +16,7 @@ RSpec::Matchers.define :be_distance do |expected|
16
16
  end
17
17
  end
18
18
 
19
- describe Metar::VerticalVisibility do
19
+ describe Metar::Data::VerticalVisibility do
20
20
  context '.parse' do
21
21
  [
22
22
  ['VV + nnn', 'VV300', 9144],
@@ -24,7 +24,7 @@ describe Metar::VerticalVisibility do
24
24
  ['returns nil for unmatched', 'FUBAR', :expect_nil],
25
25
  ].each do |docstring, raw, expected|
26
26
  example docstring do
27
- expect(Metar::VerticalVisibility.parse(raw)).to be_distance(expected)
27
+ expect(described_class.parse(raw)).to be_distance(expected)
28
28
  end
29
29
  end
30
30
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
3
 
4
- RSpec.describe Metar::VisibilityRemark do
4
+ describe Metar::Data::VisibilityRemark do
5
5
  describe ".parse" do
6
6
  subject { described_class.parse("2000W") }
7
7
 
@@ -14,13 +14,3 @@ RSpec.describe Metar::VisibilityRemark do
14
14
  end
15
15
  end
16
16
  end
17
-
18
- RSpec.describe Metar::DensityAltitude do
19
- describe ".parse" do
20
- subject { described_class.parse("50FT") }
21
-
22
- it "interprets the value as feet" do
23
- expect(subject.height.to_feet).to eq(50)
24
- end
25
- end
26
- end
@@ -13,9 +13,9 @@ RSpec::Matchers.define :be_visibility do |distance, direction, comparator|
13
13
  false
14
14
  elsif visibility.comparator.nil? != comparator.nil?
15
15
  false
16
- elsif visibility.distance.is_a?(Metar::Distance)&& (visibility.distance.value - distance).abs > 0.01
16
+ elsif visibility.distance.is_a?(Metar::Data::Distance) && (visibility.distance.value - distance).abs > 0.01
17
17
  false
18
- elsif visibility.direction.is_a?(M9t::Direction)&& (visibility.direction.value - direction).abs > 0.01
18
+ elsif visibility.direction.is_a?(M9t::Direction) && (visibility.direction.value - direction).abs > 0.01
19
19
  false
20
20
  elsif comparator.is_a?(Symbol) && visibility.comparator != comparator
21
21
  false
@@ -25,7 +25,7 @@ RSpec::Matchers.define :be_visibility do |distance, direction, comparator|
25
25
  end
26
26
  end
27
27
 
28
- describe Metar::Visibility do
28
+ describe Metar::Data::Visibility do
29
29
  context '.parse' do
30
30
  [
31
31
  ['understands 9999', '9999', [10000.00, nil, :more_than]],
@@ -41,7 +41,7 @@ describe Metar::Visibility do
41
41
  ['returns nil for unmatched', 'FUBAR', [ nil, nil, nil]],
42
42
  ].each do |docstring, raw, expected|
43
43
  example docstring do
44
- expect(Metar::Visibility.parse(raw)).to be_visibility(*expected)
44
+ expect(described_class.parse(raw)).to be_visibility(*expected)
45
45
  end
46
46
  end
47
47
  end
@@ -64,14 +64,16 @@ describe Metar::Visibility do
64
64
  ['with distance and direction', :it, [ :set, :set, nil ], '4km ESE'],
65
65
  ['with distance, direction and comparator', :it, [ :set, :set, :more_than ], 'piú di 4km ESE'],
66
66
  ].each do |docstring, locale, (distance, direction, comparator), expected|
67
- distance = Metar::Distance.new(4321) if distance == :set
67
+ distance = Metar::Data::Distance.new(4321) if distance == :set
68
68
  direction = M9t::Direction.new(123) if direction == :set
69
69
 
70
70
  example docstring + " (#{locale})" do
71
71
  I18n.locale = locale
72
- value = Metar::Visibility.new(distance, direction, comparator).to_s
72
+ subject = described_class.new(
73
+ nil, distance: distance, direction: direction, comparator: comparator
74
+ )
73
75
 
74
- expect(value).to eq(expected)
76
+ expect(subject.to_s).to eq(expected)
75
77
  end
76
78
  end
77
79
  end
@@ -19,7 +19,7 @@ RSpec::Matchers.define :be_weather_phenomenon do |modifier, descriptor, phenomen
19
19
  end
20
20
  end
21
21
 
22
- describe Metar::WeatherPhenomenon do
22
+ describe Metar::Data::WeatherPhenomenon do
23
23
  context '.parse' do
24
24
  [
25
25
  ['simple phenomenon', 'BR', [nil, nil, 'mist']],
@@ -33,7 +33,7 @@ describe Metar::WeatherPhenomenon do
33
33
  ['returns nil for unmatched', 'FUBAR', [nil, nil, nil]],
34
34
  ].each do |docstring, raw, expected|
35
35
  example docstring do
36
- expect(Metar::WeatherPhenomenon.parse(raw)).to be_weather_phenomenon(*expected)
36
+ expect(described_class.parse(raw)).to be_weather_phenomenon(*expected)
37
37
  end
38
38
  end
39
39
  end
@@ -58,7 +58,11 @@ describe Metar::WeatherPhenomenon do
58
58
  ].each do |docstring, locale, (modifier, descriptor, phenomenon), expected|
59
59
  example docstring + " (#{locale})" do
60
60
  I18n.locale = locale
61
- expect(Metar::WeatherPhenomenon.new(phenomenon, modifier, descriptor).to_s).to eq(expected)
61
+ subject = described_class.new(
62
+ nil,
63
+ phenomenon: phenomenon, modifier: modifier, descriptor: descriptor
64
+ )
65
+ expect(subject.to_s).to eq(expected)
62
66
  end
63
67
  end
64
68
  end
@@ -19,7 +19,7 @@ RSpec::Matchers.define :be_wind do |direction, speed, gusts|
19
19
  false
20
20
  elsif speed.is_a?(Symbol) && wind.speed != speed
21
21
  false
22
- elsif speed.is_a?(Metar::Speed) && (wind.speed.value - speed).abs > 0.01
22
+ elsif speed.is_a?(Metar::Data::Speed) && (wind.speed.value - speed).abs > 0.01
23
23
  false
24
24
  elsif !wind.gusts.nil? && (wind.gusts.value - gusts).abs > 0.01
25
25
  false
@@ -29,7 +29,7 @@ RSpec::Matchers.define :be_wind do |direction, speed, gusts|
29
29
  end
30
30
  end
31
31
 
32
- describe Metar::Wind do
32
+ describe Metar::Data::Wind do
33
33
  context '.parse' do
34
34
  [
35
35
  # Direction and speed
@@ -66,7 +66,7 @@ describe Metar::Wind do
66
66
  ['returns nil for nil', nil, [nil, nil, nil]],
67
67
  ].each do |docstring, raw, expected|
68
68
  example docstring do
69
- expect(Metar::Wind.parse(raw)).to be_wind(*expected)
69
+ expect(described_class.parse(raw)).to be_wind(*expected)
70
70
  end
71
71
  end
72
72
  end
@@ -86,19 +86,22 @@ describe Metar::Wind do
86
86
  ['handles variable_direction', :en, [:variable_direction, nil, nil ], '443km/h variable direction' ],
87
87
  ['handles unknown_direction', :en, [:unknown_direction, nil, nil ], '443km/h unknown direction' ],
88
88
  ['handles unknown_speed', :en, [nil, :unknown_speed, nil ], 'unknown speed ESE' ],
89
- ['includes gusts', :en, [nil, nil, Metar::Speed.new(123)], '443km/h ESE gusts 443km/h' ],
89
+ ['includes gusts', :en, [nil, nil, Metar::Data::Speed.new(123)], '443km/h ESE gusts 443km/h' ],
90
90
  ['formats speed and direction', :it, [nil, nil, nil ], '443km/h ESE' ],
91
91
  ['handles variable_direction', :it, [:variable_direction, nil, nil ], '443km/h direzione variabile' ],
92
92
  ['handles unknown_direction', :it, [:unknown_direction, nil, nil ], '443km/h direzione sconosciuta'],
93
93
  ['handles unknown_speed', :it, [nil, :unknown_speed, nil ], 'velocità sconosciuta ESE' ],
94
- ['includes gusts', :it, [nil, nil, Metar::Speed.new(123)], '443km/h ESE folate di 443km/h'],
94
+ ['includes gusts', :it, [nil, nil, Metar::Data::Speed.new(123)], '443km/h ESE folate di 443km/h'],
95
95
  ].each do |docstring, locale, (direction, speed, gusts), expected|
96
96
  direction ||= M9t::Direction.new(123)
97
- speed ||= Metar::Speed.new(123)
97
+ speed ||= Metar::Data::Speed.new(123)
98
98
 
99
99
  example docstring + " (#{locale})" do
100
100
  I18n.locale = locale
101
- expect(Metar::Wind.new(direction, speed, gusts).to_s).to eq(expected)
101
+ subject = described_class.new(
102
+ "chunk", direction: direction, speed: speed, gusts: gusts
103
+ )
104
+ expect(subject.to_s).to eq(expected)
102
105
  end
103
106
  end
104
107
  end