metar-parser 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/lib/metar/data.rb +31 -32
- data/lib/metar/parser.rb +12 -11
- data/lib/metar/raw.rb +1 -1
- data/lib/metar/report.rb +3 -7
- data/lib/metar/station.rb +15 -21
- data/lib/metar/version.rb +1 -2
- data/spec/data_spec.rb +26 -0
- data/spec/{unit/distance_spec.rb → distance_spec.rb} +3 -3
- data/spec/{unit/i18n_spec.rb → i18n_spec.rb} +1 -1
- data/spec/{unit/parser_spec.rb → parser_spec.rb} +22 -8
- data/spec/pressure_spec.rb +22 -0
- data/spec/{unit/raw_spec.rb → raw_spec.rb} +33 -40
- data/spec/{unit/remark_spec.rb → remark_spec.rb} +4 -25
- data/spec/{unit/report_spec.rb → report_spec.rb} +18 -16
- data/spec/runway_visible_range_spec.rb +81 -0
- data/spec/{unit/sky_condition_spec.rb → sky_condition_spec.rb} +0 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/speed_spec.rb +45 -0
- data/spec/{unit/station_spec.rb → station_spec.rb} +83 -52
- data/spec/{unit/temperature_spec.rb → temperature_spec.rb} +7 -7
- data/spec/{unit/variable_wind_spec.rb → variable_wind_spec.rb} +10 -11
- data/spec/{unit/vertical_visibility_spec.rb → vertical_visibility_spec.rb} +1 -1
- data/spec/{unit/visibility_spec.rb → visibility_spec.rb} +16 -20
- data/spec/weather_phenomenon_spec.rb +66 -0
- data/spec/{unit/wind_spec.rb → wind_spec.rb} +10 -11
- metadata +53 -38
- data/bin/parse_raw.rb +0 -27
- data/spec/unit/pressure_spec.rb +0 -22
- data/spec/unit/runway_visible_range_spec.rb +0 -88
- data/spec/unit/speed_spec.rb +0 -45
- data/spec/unit/weather_phenomenon_spec.rb +0 -66
@@ -4,15 +4,15 @@ require "spec_helper"
|
|
4
4
|
describe Metar::Temperature do
|
5
5
|
context '.parse' do
|
6
6
|
it 'understands numbers' do
|
7
|
-
t = Metar::Temperature.parse(
|
7
|
+
t = Metar::Temperature.parse('5')
|
8
8
|
|
9
|
-
expect(t.value).to be_within(
|
9
|
+
expect(t.value).to be_within(0.01).of(5.0)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'treats an M-prefix as a negative indicator' do
|
13
|
-
t = Metar::Temperature.parse(
|
13
|
+
t = Metar::Temperature.parse('M5')
|
14
14
|
|
15
|
-
expect(t.value).to be_within(
|
15
|
+
expect(t.value).to be_within(0.01).of(-5.0)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'returns nil for other values' do
|
@@ -23,14 +23,14 @@ describe Metar::Temperature do
|
|
23
23
|
|
24
24
|
context '#to_s' do
|
25
25
|
it 'abbreviates the units' do
|
26
|
-
t = Metar::Temperature.new(
|
26
|
+
t = Metar::Temperature.new(5)
|
27
27
|
|
28
28
|
expect(t.to_s).to eq('5°C')
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'rounds to the nearest degree' do
|
32
|
-
expect(Metar::Temperature.new(
|
33
|
-
expect(Metar::Temperature.new(
|
32
|
+
expect(Metar::Temperature.new(5.1).to_s).to eq('5°C')
|
33
|
+
expect(Metar::Temperature.new(5.5).to_s).to eq('6°C')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -3,29 +3,28 @@ require "spec_helper"
|
|
3
3
|
describe Metar::VariableWind do
|
4
4
|
context '.parse' do
|
5
5
|
it 'understands nnn + V + nnn' do
|
6
|
-
vw = Metar::VariableWind.parse(
|
6
|
+
vw = Metar::VariableWind.parse('090V180')
|
7
7
|
|
8
|
-
expect(vw.direction1.value).to eq(
|
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(
|
13
|
+
vw = Metar::VariableWind.parse('360V090')
|
14
14
|
|
15
|
-
expect(vw.direction1.value).to eq(
|
16
|
-
expect(vw.direction2.value).to eq(
|
15
|
+
expect(vw.direction1.value).to eq(0.0)
|
16
|
+
expect(vw.direction2.value).to eq(90.0)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
19
|
it 'accepts 360, rounding to 0 - 2' do
|
21
|
-
vw = Metar::VariableWind.parse(
|
20
|
+
vw = Metar::VariableWind.parse('090V360')
|
22
21
|
|
23
|
-
expect(vw.direction1.value).to eq(
|
24
|
-
expect(vw.direction2.value).to eq(
|
22
|
+
expect(vw.direction1.value).to eq(90.0)
|
23
|
+
expect(vw.direction2.value).to eq(0.0)
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'returns nil for other' do
|
28
|
-
vw = Metar::VariableWind.parse(
|
27
|
+
vw = Metar::VariableWind.parse('XXX')
|
29
28
|
|
30
29
|
expect(vw).to be_nil
|
31
30
|
end
|
@@ -33,7 +32,7 @@ describe Metar::VariableWind do
|
|
33
32
|
|
34
33
|
context '#to_s' do
|
35
34
|
it 'renders compatible values as compass directions' do
|
36
|
-
vw = Metar::VariableWind.parse(
|
35
|
+
vw = Metar::VariableWind.parse('090V180')
|
37
36
|
|
38
37
|
expect(vw.to_s).to eq('E - S')
|
39
38
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
|
-
RSpec::Matchers.define :be_visibility do |
|
5
|
-
match do |
|
6
|
-
if visibility.nil? && [ distance, direction, comparator ].all?(
|
4
|
+
RSpec::Matchers.define :be_visibility do |distance, direction, comparator|
|
5
|
+
match do |visibility|
|
6
|
+
if visibility.nil? && [ distance, direction, comparator ].all?(&:nil?)
|
7
7
|
true
|
8
|
-
elsif visibility.nil? != [ distance, direction, comparator ].all?(
|
8
|
+
elsif visibility.nil? != [ distance, direction, comparator ].all?(&:nil?)
|
9
9
|
false
|
10
10
|
elsif visibility.distance.nil? != distance.nil?
|
11
11
|
false
|
@@ -13,11 +13,11 @@ 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?(
|
16
|
+
elsif visibility.distance.is_a?(Metar::Distance)&& (visibility.distance.value - distance).abs > 0.01
|
17
17
|
false
|
18
|
-
elsif visibility.direction.is_a?(
|
18
|
+
elsif visibility.direction.is_a?(M9t::Direction)&& (visibility.direction.value - direction).abs > 0.01
|
19
19
|
false
|
20
|
-
elsif comparator.is_a?(
|
20
|
+
elsif comparator.is_a?(Symbol) && visibility.comparator != comparator
|
21
21
|
false
|
22
22
|
else
|
23
23
|
true
|
@@ -47,7 +47,6 @@ describe Metar::Visibility do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
context '#to_s' do
|
50
|
-
|
51
50
|
before :each do
|
52
51
|
@locale = I18n.locale
|
53
52
|
I18n.locale = :it
|
@@ -58,15 +57,15 @@ describe Metar::Visibility do
|
|
58
57
|
end
|
59
58
|
|
60
59
|
[
|
61
|
-
[
|
62
|
-
[
|
63
|
-
[
|
64
|
-
[
|
65
|
-
[
|
66
|
-
[
|
67
|
-
].each do |
|
68
|
-
distance = Metar::Distance.new(
|
69
|
-
direction = M9t::Direction.new(
|
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'],
|
66
|
+
].each do |docstring, locale, (distance, direction, comparator), expected|
|
67
|
+
distance = Metar::Distance.new(4321) if distance == :set
|
68
|
+
direction = M9t::Direction.new(123) if direction == :set
|
70
69
|
|
71
70
|
example docstring + " (#{locale})" do
|
72
71
|
I18n.locale = locale
|
@@ -75,8 +74,5 @@ describe Metar::Visibility do
|
|
75
74
|
expect(value).to eq(expected)
|
76
75
|
end
|
77
76
|
end
|
78
|
-
|
79
77
|
end
|
80
|
-
|
81
78
|
end
|
82
|
-
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
RSpec::Matchers.define :be_weather_phenomenon do |modifier, descriptor, phenomenon|
|
5
|
+
match do |wp|
|
6
|
+
if wp.nil? && phenomenon.nil?
|
7
|
+
true
|
8
|
+
elsif wp.nil? != phenomenon.nil?
|
9
|
+
false
|
10
|
+
elsif wp.phenomenon != phenomenon
|
11
|
+
false
|
12
|
+
elsif wp.modifier != modifier
|
13
|
+
false
|
14
|
+
elsif wp.descriptor != descriptor
|
15
|
+
false
|
16
|
+
else
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Metar::WeatherPhenomenon do
|
23
|
+
context '.parse' do
|
24
|
+
[
|
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]],
|
34
|
+
].each do |docstring, raw, expected|
|
35
|
+
example docstring do
|
36
|
+
expect(Metar::WeatherPhenomenon.parse(raw)).to be_weather_phenomenon(*expected)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context '#to_s' do
|
42
|
+
before :all do
|
43
|
+
@locale = I18n.locale
|
44
|
+
I18n.locale = :it
|
45
|
+
end
|
46
|
+
|
47
|
+
after :all do
|
48
|
+
I18n.locale = @locale
|
49
|
+
end
|
50
|
+
|
51
|
+
[
|
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'],
|
58
|
+
].each do |docstring, locale, (modifier, descriptor, phenomenon), expected|
|
59
|
+
example docstring + " (#{locale})" do
|
60
|
+
I18n.locale = locale
|
61
|
+
expect(Metar::WeatherPhenomenon.new(phenomenon, modifier, descriptor).to_s).to eq(expected)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -3,26 +3,26 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
RSpec::Matchers.define :be_wind do |direction, speed, gusts|
|
5
5
|
match do |wind|
|
6
|
-
if wind.nil?
|
6
|
+
if wind.nil? && [direction, speed, gusts].all?(&:nil?)
|
7
7
|
true
|
8
8
|
elsif wind.nil?
|
9
9
|
false
|
10
10
|
elsif wind.direction.nil? != direction.nil?
|
11
11
|
false
|
12
|
-
elsif wind.speed.nil?
|
12
|
+
elsif wind.speed.nil? != speed.nil?
|
13
13
|
false
|
14
|
-
elsif wind.gusts.nil?
|
14
|
+
elsif wind.gusts.nil? != gusts.nil?
|
15
15
|
false
|
16
|
-
elsif direction.is_a?(Symbol)
|
16
|
+
elsif direction.is_a?(Symbol) && wind.direction != direction
|
17
17
|
false
|
18
18
|
elsif direction.is_a?(M9t::Direction) && (wind.direction.value - direction).abs > 0.01
|
19
19
|
false
|
20
|
-
elsif speed.is_a?(Symbol)
|
21
|
-
|
22
|
-
elsif speed.is_a?(Metar::Speed)
|
20
|
+
elsif speed.is_a?(Symbol) && wind.speed != speed
|
21
|
+
false
|
22
|
+
elsif speed.is_a?(Metar::Speed) && (wind.speed.value - speed).abs > 0.01
|
23
|
+
false
|
24
|
+
elsif !wind.gusts.nil? && (wind.gusts.value - gusts).abs > 0.01
|
23
25
|
false
|
24
|
-
elsif ! wind.gusts.nil? && (wind.gusts.value - gusts).abs > 0.01
|
25
|
-
false
|
26
26
|
else
|
27
27
|
true
|
28
28
|
end
|
@@ -37,7 +37,7 @@ describe Metar::Wind do
|
|
37
37
|
['understands 5 digits + KMH', '12345KMH', [123.0, 12.50, nil]],
|
38
38
|
['understands 5 digits + MPS', '12345MPS', [123.0, 45.00, nil]],
|
39
39
|
['understands 5 digits + KT', '12345KT', [123.0, 23.15, nil]],
|
40
|
-
['rounds 360 down to 0', '36045KT', [
|
40
|
+
['rounds 360 down to 0', '36045KT', [0.0, 23.15, nil]],
|
41
41
|
['returns nil for directions outside 0 to 360', '88845KT', [nil, nil, nil]],
|
42
42
|
# +gusts
|
43
43
|
['understands 5 digits + G + 2 digits', '12345G67', [123.0, 12.50, 18.61]],
|
@@ -103,4 +103,3 @@ describe Metar::Wind do
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metar-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: timecop
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,7 +164,6 @@ files:
|
|
150
164
|
- COPYING
|
151
165
|
- README.md
|
152
166
|
- Rakefile
|
153
|
-
- bin/parse_raw.rb
|
154
167
|
- lib/metar.rb
|
155
168
|
- lib/metar/data.rb
|
156
169
|
- lib/metar/parser.rb
|
@@ -162,24 +175,25 @@ files:
|
|
162
175
|
- locales/en.yml
|
163
176
|
- locales/it.yml
|
164
177
|
- locales/pt-BR.yml
|
178
|
+
- spec/data_spec.rb
|
179
|
+
- spec/distance_spec.rb
|
180
|
+
- spec/i18n_spec.rb
|
181
|
+
- spec/parser_spec.rb
|
182
|
+
- spec/pressure_spec.rb
|
183
|
+
- spec/raw_spec.rb
|
184
|
+
- spec/remark_spec.rb
|
185
|
+
- spec/report_spec.rb
|
186
|
+
- spec/runway_visible_range_spec.rb
|
187
|
+
- spec/sky_condition_spec.rb
|
165
188
|
- spec/spec_helper.rb
|
166
|
-
- spec/
|
167
|
-
- spec/
|
168
|
-
- spec/
|
169
|
-
- spec/
|
170
|
-
- spec/
|
171
|
-
- spec/
|
172
|
-
- spec/
|
173
|
-
- spec/
|
174
|
-
- spec/unit/sky_condition_spec.rb
|
175
|
-
- spec/unit/speed_spec.rb
|
176
|
-
- spec/unit/station_spec.rb
|
177
|
-
- spec/unit/temperature_spec.rb
|
178
|
-
- spec/unit/variable_wind_spec.rb
|
179
|
-
- spec/unit/vertical_visibility_spec.rb
|
180
|
-
- spec/unit/visibility_spec.rb
|
181
|
-
- spec/unit/weather_phenomenon_spec.rb
|
182
|
-
- spec/unit/wind_spec.rb
|
189
|
+
- spec/speed_spec.rb
|
190
|
+
- spec/station_spec.rb
|
191
|
+
- spec/temperature_spec.rb
|
192
|
+
- spec/variable_wind_spec.rb
|
193
|
+
- spec/vertical_visibility_spec.rb
|
194
|
+
- spec/visibility_spec.rb
|
195
|
+
- spec/weather_phenomenon_spec.rb
|
196
|
+
- spec/wind_spec.rb
|
183
197
|
homepage: http://github.com/joeyates/metar-parser
|
184
198
|
licenses: []
|
185
199
|
metadata: {}
|
@@ -191,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
205
|
requirements:
|
192
206
|
- - ">="
|
193
207
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
208
|
+
version: 1.9.3
|
195
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
210
|
requirements:
|
197
211
|
- - ">="
|
@@ -204,21 +218,22 @@ signing_key:
|
|
204
218
|
specification_version: 4
|
205
219
|
summary: A Ruby gem for worldwide weather reports
|
206
220
|
test_files:
|
207
|
-
- spec/
|
208
|
-
- spec/
|
209
|
-
- spec/
|
210
|
-
- spec/
|
211
|
-
- spec/
|
212
|
-
- spec/
|
213
|
-
- spec/
|
214
|
-
- spec/
|
215
|
-
- spec/
|
216
|
-
- spec/
|
217
|
-
- spec/
|
218
|
-
- spec/
|
219
|
-
- spec/
|
220
|
-
- spec/
|
221
|
-
- spec/
|
222
|
-
- spec/
|
223
|
-
- spec/
|
221
|
+
- spec/runway_visible_range_spec.rb
|
222
|
+
- spec/weather_phenomenon_spec.rb
|
223
|
+
- spec/temperature_spec.rb
|
224
|
+
- spec/i18n_spec.rb
|
225
|
+
- spec/pressure_spec.rb
|
226
|
+
- spec/remark_spec.rb
|
227
|
+
- spec/speed_spec.rb
|
228
|
+
- spec/vertical_visibility_spec.rb
|
229
|
+
- spec/parser_spec.rb
|
230
|
+
- spec/visibility_spec.rb
|
231
|
+
- spec/data_spec.rb
|
232
|
+
- spec/report_spec.rb
|
233
|
+
- spec/raw_spec.rb
|
234
|
+
- spec/distance_spec.rb
|
235
|
+
- spec/wind_spec.rb
|
236
|
+
- spec/sky_condition_spec.rb
|
237
|
+
- spec/station_spec.rb
|
238
|
+
- spec/variable_wind_spec.rb
|
224
239
|
has_rdoc:
|
data/bin/parse_raw.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
=begin
|
4
|
-
|
5
|
-
Use the data downloaded by 'download_raw.rb' to bulk test the Report
|
6
|
-
|
7
|
-
=end
|
8
|
-
|
9
|
-
require 'yaml'
|
10
|
-
require File.join(File.expand_path(File.dirname(__FILE__) + '/../lib'), 'metar')
|
11
|
-
|
12
|
-
filename = File.join(File.expand_path(File.dirname(__FILE__) + '/../data'), "stations.yml")
|
13
|
-
stations = YAML.load_file(filename)
|
14
|
-
|
15
|
-
stations.each_pair do |cccc, raw_text|
|
16
|
-
raw = Metar::Raw.new(cccc, raw_text)
|
17
|
-
report = nil
|
18
|
-
begin
|
19
|
-
report = Metar::Report.new(raw)
|
20
|
-
$stdout.print '.'
|
21
|
-
rescue => e
|
22
|
-
$stderr.puts "#{ raw.metar }"
|
23
|
-
$stderr.puts " Error: #{ e }"
|
24
|
-
$stdout.print 'E'
|
25
|
-
end
|
26
|
-
$stdout.flush
|
27
|
-
end
|
data/spec/unit/pressure_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Metar::Pressure do
|
4
|
-
context '.parse' do
|
5
|
-
it 'interprets the Q prefix as hectopascals' do
|
6
|
-
expect(Metar::Pressure.parse( 'Q1300' ).value).to be_within( 0.01 ).of( 1.3 )
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'interprets the A prefix as inches of mercury' do
|
10
|
-
expect(Metar::Pressure.parse( 'A1234' ).value).to be_within( 0.01 ).of( 0.42 )
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'require 4 digits' do
|
14
|
-
expect(Metar::Pressure.parse( 'Q12345' )).to be_nil
|
15
|
-
expect(Metar::Pressure.parse( 'A123' )).to be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns nil for nil' do
|
19
|
-
expect(Metar::Pressure.parse( nil )).to be_nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,88 +0,0 @@
|
|
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::RunwayVisibleRange do
|
33
|
-
|
34
|
-
context '.parse' do
|
35
|
-
|
36
|
-
[
|
37
|
-
[ 'understands R + nn + / + nnnn', 'R12/3400', [ '12', [3400.00, nil, nil], nil, nil ] ],
|
38
|
-
[ 'understands runway positions: RLC', 'R12L/3400', [ '12L', [3400.00, nil, nil], nil, nil ] ],
|
39
|
-
[ 'understands comparators: PM', 'R12/P3400', [ '12', [3400.00, nil, :more_than], nil, nil ] ],
|
40
|
-
[ 'understands tendencies: NUD', 'R12/3400U', [ '12', [3400.00, nil, nil], nil, :improving ] ],
|
41
|
-
[ 'understands feet', 'R12/3400FT', [ '12', [1036.32, nil, nil], nil, nil ] ],
|
42
|
-
[ 'understands second visibilities (m)', 'R26/0750V1200U', [ '12', [ 750.0, nil, nil], [1200.0, nil, nil], :improving ] ],
|
43
|
-
[ 'understands second visibilities (ft)', 'R12/3400V1800FT', [ '12', [1036.32, nil, nil], [548.64, nil, nil], nil ] ],
|
44
|
-
[ 'returns nil for nil', nil, [ nil, nil, nil, nil ] ],
|
45
|
-
].each do | docstring, raw, expected |
|
46
|
-
example docstring do
|
47
|
-
expect(Metar::RunwayVisibleRange.parse(raw)).to be_runway_visible_range( *expected )
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
context '#to_s' do
|
54
|
-
|
55
|
-
before :all do
|
56
|
-
@locale = I18n.locale
|
57
|
-
I18n.locale = :it
|
58
|
-
end
|
59
|
-
|
60
|
-
after :all do
|
61
|
-
I18n.locale = @locale
|
62
|
-
end
|
63
|
-
|
64
|
-
[
|
65
|
-
[ 'v1', :en, [ [3400.00, nil, nil], nil, nil ], 'runway 14: 3400m' ],
|
66
|
-
[ 'v1 and v2', :en, [ [3400.00, nil, nil], [1900.00, nil, nil], nil ], 'runway 14: from 3400m to 1900m' ],
|
67
|
-
[ 'v1 and tendency', :en, [ [3400.00, nil, nil], nil, :improving ], 'runway 14: 3400m improving' ],
|
68
|
-
].each do | docstring, locale, ( visibility1, visibility2, tendency ), expected |
|
69
|
-
d1 = Metar::Distance.new( visibility1[0] )
|
70
|
-
v1 = Metar::Visibility.new( d1, visibility1[1], visibility1[2] )
|
71
|
-
v2 =
|
72
|
-
if ! visibility2.nil?
|
73
|
-
d2 = Metar::Distance.new( visibility2[0] )
|
74
|
-
Metar::Visibility.new( d2, visibility2[1], visibility2[2] )
|
75
|
-
else
|
76
|
-
nil
|
77
|
-
end
|
78
|
-
|
79
|
-
example docstring + " (#{locale})" do
|
80
|
-
I18n.locale = locale
|
81
|
-
expect(Metar::RunwayVisibleRange.new('14', v1, v2, tendency).to_s).to eq(expected)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
data/spec/unit/speed_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Metar::Speed do
|
4
|
-
context '.parse' do
|
5
|
-
it 'returns nil for nil' do
|
6
|
-
speed = Metar::Speed.parse( nil )
|
7
|
-
|
8
|
-
expect(speed).to be_nil
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'parses knots' do
|
12
|
-
speed = Metar::Speed.parse( '5KT' )
|
13
|
-
|
14
|
-
expect(speed).to be_a( Metar::Speed )
|
15
|
-
expect(speed.value).to be_within( 0.01 ).of( 2.57 )
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'parses meters per second' do
|
19
|
-
speed = Metar::Speed.parse( '7MPS' )
|
20
|
-
|
21
|
-
expect(speed).to be_a( Metar::Speed )
|
22
|
-
expect(speed.value).to be_within( 0.01 ).of( 7.00 )
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'parses kilometers per hour' do
|
26
|
-
speed = Metar::Speed.parse( '14KMH' )
|
27
|
-
|
28
|
-
expect(speed).to be_a( Metar::Speed )
|
29
|
-
expect(speed.value).to be_within( 0.01 ).of( 3.89 )
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'trates straight numbers as kilomters per hour' do
|
33
|
-
speed = Metar::Speed.parse( '14' )
|
34
|
-
|
35
|
-
expect(speed).to be_a( Metar::Speed )
|
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 = Metar::Speed.parse( '' )
|
41
|
-
|
42
|
-
expect(speed).to be_nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
RSpec::Matchers.define :be_weather_phenomenon do | modifier, descriptor, phenomenon |
|
5
|
-
match do | wp |
|
6
|
-
if wp.nil? && phenomenon.nil?
|
7
|
-
true
|
8
|
-
elsif wp.nil? != phenomenon.nil?
|
9
|
-
false
|
10
|
-
elsif wp.phenomenon != phenomenon
|
11
|
-
false
|
12
|
-
elsif wp.modifier != modifier
|
13
|
-
false
|
14
|
-
elsif wp.descriptor != descriptor
|
15
|
-
false
|
16
|
-
else
|
17
|
-
true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe Metar::WeatherPhenomenon do
|
23
|
-
context '.parse' do
|
24
|
-
[
|
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 ] ],
|
34
|
-
].each do | docstring, raw, expected |
|
35
|
-
example docstring do
|
36
|
-
expect(Metar::WeatherPhenomenon.parse( raw )).to be_weather_phenomenon(*expected)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context '#to_s' do
|
42
|
-
before :all do
|
43
|
-
@locale = I18n.locale
|
44
|
-
I18n.locale = :it
|
45
|
-
end
|
46
|
-
|
47
|
-
after :all do
|
48
|
-
I18n.locale = @locale
|
49
|
-
end
|
50
|
-
|
51
|
-
[
|
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' ],
|
58
|
-
].each do | docstring, locale, ( modifier, descriptor, phenomenon ), expected |
|
59
|
-
example docstring + " (#{locale})" do
|
60
|
-
I18n.locale = locale
|
61
|
-
expect(Metar::WeatherPhenomenon.new( phenomenon, modifier, descriptor ).to_s).to eq(expected)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|