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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b47782dda9aa78314cf6244e1d395acff88cd025
|
4
|
+
data.tar.gz: 097ed5364bdf7ded700dd77b5722a863655ae2b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf5217c8b8edbe61045f48f7293ed479864208021c16792b0d436292ac4513c74688fa0d09e05a23140cafb3b0dc93b97a6165b661b4e5f5d77e6ab42b4e4f5
|
7
|
+
data.tar.gz: 84a588b82027c09eab3856a0dacafad06b2638a8ab34e1f75c5047f81af5018b7964e6a0319d8849a9918322060ea71bb4058f7affe7fb1f81d7892ce5ec016b
|
data/Rakefile
CHANGED
@@ -3,8 +3,8 @@ require "bundler/gem_tasks"
|
|
3
3
|
require 'rcov/rcovtask' if RUBY_VERSION < '1.9'
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
|
6
|
-
task :
|
6
|
+
task default: :spec
|
7
7
|
|
8
|
-
RSpec::Core::RakeTask.new do |
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
9
|
t.pattern = 'spec/**/*_spec.rb'
|
10
10
|
end
|
data/lib/metar/data.rb
CHANGED
@@ -23,9 +23,9 @@ module Metar
|
|
23
23
|
# Handles nil case differently to M9t::Distance
|
24
24
|
def to_s(options = {})
|
25
25
|
options = {
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
26
|
+
units: @units,
|
27
|
+
precision: 0,
|
28
|
+
abbreviated: true,
|
29
29
|
}.merge(options)
|
30
30
|
return I18n.t('metar.distance.unknown') if @value.nil?
|
31
31
|
super(options)
|
@@ -66,7 +66,7 @@ module Metar
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def to_s(options = {})
|
69
|
-
options = {:
|
69
|
+
options = {abbreviated: true, precision: 0}.merge(options)
|
70
70
|
super(options)
|
71
71
|
end
|
72
72
|
end
|
@@ -124,8 +124,8 @@ module Metar
|
|
124
124
|
|
125
125
|
def to_s(options = {})
|
126
126
|
options = {
|
127
|
-
:
|
128
|
-
:
|
127
|
+
direction_units: :compass,
|
128
|
+
speed_units: :kilometers_per_hour,
|
129
129
|
}.merge(options)
|
130
130
|
speed =
|
131
131
|
case @speed
|
@@ -133,9 +133,9 @@ module Metar
|
|
133
133
|
I18n.t('metar.wind.unknown_speed')
|
134
134
|
else
|
135
135
|
@speed.to_s(
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
136
|
+
abbreviated: true,
|
137
|
+
precision: 0,
|
138
|
+
units: options[:speed_units]
|
139
139
|
)
|
140
140
|
end
|
141
141
|
direction =
|
@@ -145,14 +145,14 @@ module Metar
|
|
145
145
|
when :unknown_direction
|
146
146
|
I18n.t('metar.wind.unknown_direction')
|
147
147
|
else
|
148
|
-
@direction.to_s(:
|
148
|
+
@direction.to_s(units: options[:direction_units])
|
149
149
|
end
|
150
150
|
s = "#{speed} #{direction}"
|
151
151
|
if not @gusts.nil?
|
152
152
|
g = @gusts.to_s(
|
153
|
-
:
|
154
|
-
:
|
155
|
-
:
|
153
|
+
abbreviated: true,
|
154
|
+
precision: 0,
|
155
|
+
units: options[:speed_units]
|
156
156
|
)
|
157
157
|
s += " #{I18n.t('metar.wind.gusts')} #{g}"
|
158
158
|
end
|
@@ -176,7 +176,7 @@ module Metar
|
|
176
176
|
end
|
177
177
|
|
178
178
|
def to_s
|
179
|
-
"#{@direction1.to_s(:
|
179
|
+
"#{@direction1.to_s(units: :compass)} - #{@direction2.to_s(units: :compass)}"
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
@@ -219,29 +219,29 @@ module Metar
|
|
219
219
|
|
220
220
|
def to_s(options = {})
|
221
221
|
distance_options = {
|
222
|
-
:
|
223
|
-
:
|
224
|
-
:
|
222
|
+
abbreviated: true,
|
223
|
+
precision: 0,
|
224
|
+
units: :kilometers,
|
225
225
|
}.merge(options)
|
226
|
-
direction_options = {:
|
226
|
+
direction_options = {units: :compass}
|
227
227
|
case
|
228
228
|
when (@direction.nil? and @comparator.nil?)
|
229
229
|
@distance.to_s(distance_options)
|
230
230
|
when @comparator.nil?
|
231
231
|
[
|
232
232
|
@distance.to_s(distance_options),
|
233
|
-
@direction.to_s(direction_options)
|
233
|
+
@direction.to_s(direction_options),
|
234
234
|
].join(' ')
|
235
235
|
when @direction.nil?
|
236
236
|
[
|
237
237
|
I18n.t('comparison.' + @comparator.to_s),
|
238
|
-
@distance.to_s(distance_options)
|
238
|
+
@distance.to_s(distance_options),
|
239
239
|
].join(' ')
|
240
240
|
else
|
241
241
|
[
|
242
242
|
I18n.t('comparison.' + @comparator.to_s),
|
243
243
|
@distance.to_s(distance_options),
|
244
|
-
@direction.to_s(direction_options)
|
244
|
+
@direction.to_s(direction_options),
|
245
245
|
].join(' ')
|
246
246
|
end
|
247
247
|
end
|
@@ -288,9 +288,9 @@ module Metar
|
|
288
288
|
|
289
289
|
def to_s
|
290
290
|
distance_options = {
|
291
|
-
:
|
292
|
-
:
|
293
|
-
:
|
291
|
+
abbreviated: true,
|
292
|
+
precision: 0,
|
293
|
+
units: @units,
|
294
294
|
}
|
295
295
|
s =
|
296
296
|
if @visibility2.nil?
|
@@ -395,7 +395,7 @@ module Metar
|
|
395
395
|
'CB' => 'cumulonimbus',
|
396
396
|
'TCU' => 'towering cumulus',
|
397
397
|
'///' => nil, # cloud type unknown as observed by automatic system (15.9.1.7)
|
398
|
-
'' => nil
|
398
|
+
'' => nil,
|
399
399
|
}
|
400
400
|
CLEAR_SKIES = [
|
401
401
|
'NSC', # WMO
|
@@ -492,7 +492,7 @@ module Metar
|
|
492
492
|
when /^4([01])(\d{3})([01])(\d{3})$/
|
493
493
|
[
|
494
494
|
TemperatureExtreme.new(:maximum, sign($1) * tenths($2)),
|
495
|
-
TemperatureExtreme.new(:minimum, sign($3) * tenths($4))
|
495
|
+
TemperatureExtreme.new(:minimum, sign($3) * tenths($4)),
|
496
496
|
]
|
497
497
|
when /^5([0-8])(\d{3})$/
|
498
498
|
character = PRESSURE_CHANGE_CHARACTER[$1.to_i]
|
@@ -615,17 +615,17 @@ module Metar
|
|
615
615
|
|
616
616
|
class VisibilityRemark < Visibility
|
617
617
|
def self.parse(chunk)
|
618
|
-
|
619
|
-
distance = Distance.new(
|
618
|
+
metres, direction = chunk.scan(/^(\d{4})([NESW]?)$/)[0]
|
619
|
+
distance = Distance.new(metres)
|
620
620
|
|
621
|
-
new(distance,
|
621
|
+
new(distance, direction, :more_than)
|
622
622
|
end
|
623
623
|
end
|
624
624
|
|
625
625
|
class DensityAltitude
|
626
626
|
def self.parse(chunk)
|
627
|
-
|
628
|
-
height = Distance.feet(
|
627
|
+
feet = chunk[/^(\d+)(FT)/, 1]
|
628
|
+
height = Distance.feet(feet)
|
629
629
|
|
630
630
|
new(height)
|
631
631
|
end
|
@@ -637,4 +637,3 @@ module Metar
|
|
637
637
|
end
|
638
638
|
end
|
639
639
|
end
|
640
|
-
|
data/lib/metar/parser.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'data')
|
2
2
|
|
3
|
-
|
3
|
+
# References:
|
4
|
+
# WMO = World Meteorological Organization Manual on Codes Volume I.1
|
5
|
+
# Section FM 15
|
4
6
|
|
7
|
+
module Metar
|
5
8
|
class Parser
|
6
|
-
|
7
9
|
def self.for_cccc(cccc)
|
8
10
|
raw = Metar::Raw::Noaa.new(cccc)
|
9
11
|
new(raw)
|
@@ -103,7 +105,7 @@ module Metar
|
|
103
105
|
@day, @hour, @minute = $1.to_i, $2.to_i, $3.to_i
|
104
106
|
found = true
|
105
107
|
else
|
106
|
-
if not strict?
|
108
|
+
if not strict?
|
107
109
|
if @chunks[0] =~ /^(\d{1,2})(\d{2})Z$/
|
108
110
|
# The day is missing, use today's date
|
109
111
|
@day = Time.now.day
|
@@ -267,7 +269,7 @@ module Metar
|
|
267
269
|
@sea_level_pressure = sea_level_pressure
|
268
270
|
end
|
269
271
|
end
|
270
|
-
|
272
|
+
|
271
273
|
def seek_recent_weather
|
272
274
|
loop do
|
273
275
|
return if @chunks.size == 0
|
@@ -292,6 +294,7 @@ module Metar
|
|
292
294
|
end
|
293
295
|
end
|
294
296
|
|
297
|
+
# WMO: 15.15
|
295
298
|
def seek_remarks
|
296
299
|
return if @chunks.size == 0
|
297
300
|
raise 'seek_remarks calls without remark' if @chunks[0] != 'RMK'
|
@@ -308,16 +311,16 @@ module Metar
|
|
308
311
|
@remarks << r
|
309
312
|
end
|
310
313
|
@chunks.shift
|
311
|
-
next
|
314
|
+
next
|
312
315
|
end
|
313
316
|
if @chunks[0] == 'VIS' and @chunks.size >= 3 and @chunks[1] == 'MIN'
|
314
|
-
@chunks.shift(
|
315
|
-
r = Metar::VisibilityRemark.parse(@chunks[
|
317
|
+
@chunks.shift(2)
|
318
|
+
r = Metar::VisibilityRemark.parse(@chunks[0])
|
316
319
|
@remarks << r
|
317
320
|
end
|
318
321
|
if @chunks[0] == 'DENSITY' and @chunks.size >= 3 and @chunks[1] == 'ALT'
|
319
|
-
@chunks.shift(
|
320
|
-
r = Metar::DensityAltitude.parse(@chunks[
|
322
|
+
@chunks.shift(2)
|
323
|
+
r = Metar::DensityAltitude.parse(@chunks[0])
|
321
324
|
@remarks << r
|
322
325
|
end
|
323
326
|
case
|
@@ -333,7 +336,5 @@ module Metar
|
|
333
336
|
def strict?
|
334
337
|
self.class.compliance == :strict
|
335
338
|
end
|
336
|
-
|
337
339
|
end
|
338
|
-
|
339
340
|
end
|
data/lib/metar/raw.rb
CHANGED
data/lib/metar/report.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Metar
|
4
|
-
|
5
4
|
class Report
|
6
|
-
|
7
5
|
ATTRIBUTES = [
|
8
6
|
:station_name,
|
9
7
|
:station_country,
|
@@ -13,7 +11,7 @@ module Metar
|
|
13
11
|
:minimum_visibility,
|
14
12
|
:present_weather,
|
15
13
|
:sky_summary,
|
16
|
-
:temperature
|
14
|
+
:temperature,
|
17
15
|
]
|
18
16
|
|
19
17
|
attr_reader :parser, :station
|
@@ -68,7 +66,7 @@ module Metar
|
|
68
66
|
end
|
69
67
|
|
70
68
|
def present_weather
|
71
|
-
@parser.present_weather.join(
|
69
|
+
@parser.present_weather.join(', ')
|
72
70
|
end
|
73
71
|
|
74
72
|
def sky_summary
|
@@ -109,13 +107,11 @@ module Metar
|
|
109
107
|
private
|
110
108
|
|
111
109
|
def attributes
|
112
|
-
a = Metar::Report::ATTRIBUTES.map do |
|
110
|
+
a = Metar::Report::ATTRIBUTES.map do |key|
|
113
111
|
value = self.send(key).to_s
|
114
112
|
{:attribute => key, :value => value} if not value.empty?
|
115
113
|
end
|
116
114
|
a.compact
|
117
115
|
end
|
118
|
-
|
119
116
|
end
|
120
|
-
|
121
117
|
end
|
data/lib/metar/station.rb
CHANGED
@@ -6,16 +6,14 @@ require 'set'
|
|
6
6
|
# As soon of any of the attributes are read, the data is downloaded (if necessary), and attributes are set.
|
7
7
|
|
8
8
|
module Metar
|
9
|
-
|
10
9
|
class Station
|
11
10
|
NOAA_STATION_LIST_URL = 'http://weather.noaa.gov/data/nsd_cccc.txt'
|
12
11
|
|
13
12
|
class << self
|
14
|
-
|
15
13
|
@nsd_cccc = nil # Contains the text of the station list
|
16
14
|
|
17
15
|
def countries
|
18
|
-
all_structures.reduce(
|
16
|
+
all_structures.reduce(Set.new) { |a, s| a.add(s[ :country ]) }.to_a.sort
|
19
17
|
end
|
20
18
|
|
21
19
|
def all
|
@@ -35,8 +33,8 @@ module Metar
|
|
35
33
|
not find_data_by_cccc(cccc).nil?
|
36
34
|
end
|
37
35
|
|
38
|
-
def find_all_by_country(
|
39
|
-
all.select { |
|
36
|
+
def find_all_by_country(country)
|
37
|
+
all.select { |s| s.country == country }
|
40
38
|
end
|
41
39
|
|
42
40
|
def to_longitude(s)
|
@@ -54,7 +52,7 @@ module Metar
|
|
54
52
|
alias :code :cccc
|
55
53
|
|
56
54
|
# No check is made on the existence of the station
|
57
|
-
def initialize(
|
55
|
+
def initialize(cccc, noaa_data)
|
58
56
|
raise "Station identifier must not be nil" if cccc.nil?
|
59
57
|
raise "Station identifier must not be empty" if cccc.to_s == ''
|
60
58
|
@cccc = cccc
|
@@ -62,18 +60,17 @@ module Metar
|
|
62
60
|
end
|
63
61
|
|
64
62
|
def parser
|
65
|
-
raw = Metar::Raw::Noaa.new(
|
66
|
-
Metar::Parser.new(
|
63
|
+
raw = Metar::Raw::Noaa.new(@cccc)
|
64
|
+
Metar::Parser.new(raw)
|
67
65
|
end
|
68
66
|
|
69
67
|
def report
|
70
|
-
Metar::Report.new(
|
68
|
+
Metar::Report.new(parser)
|
71
69
|
end
|
72
70
|
|
73
71
|
private
|
74
72
|
|
75
73
|
class << self
|
76
|
-
|
77
74
|
@structures = nil
|
78
75
|
|
79
76
|
def download_stations
|
@@ -89,13 +86,13 @@ module Metar
|
|
89
86
|
@nsd_cccc.each_line do |station|
|
90
87
|
fields = station.split(';')
|
91
88
|
@structures << {
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
98
|
-
:
|
89
|
+
cccc: fields[0],
|
90
|
+
name: fields[3],
|
91
|
+
state: fields[4],
|
92
|
+
country: fields[5],
|
93
|
+
latitude: fields[7],
|
94
|
+
longitude: fields[8],
|
95
|
+
raw: station.clone,
|
99
96
|
}
|
100
97
|
end
|
101
98
|
|
@@ -108,7 +105,7 @@ module Metar
|
|
108
105
|
|
109
106
|
end
|
110
107
|
|
111
|
-
def load!(
|
108
|
+
def load!(noaa_data)
|
112
109
|
@name = noaa_data[:name]
|
113
110
|
@state = noaa_data[:state]
|
114
111
|
@country = noaa_data[:country]
|
@@ -116,8 +113,5 @@ module Metar
|
|
116
113
|
@latitude = Station.to_latitude(noaa_data[:latitude])
|
117
114
|
@raw = noaa_data[:raw]
|
118
115
|
end
|
119
|
-
|
120
116
|
end
|
121
|
-
|
122
117
|
end
|
123
|
-
|
data/lib/metar/version.rb
CHANGED
data/spec/data_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
RSpec.describe Metar::VisibilityRemark do
|
5
|
+
describe ".parse" do
|
6
|
+
subject { described_class.parse("2000W") }
|
7
|
+
|
8
|
+
it "interprets distance in metres" do
|
9
|
+
expect(subject.distance.value).to eq(2000)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "interprets compass direction" do
|
13
|
+
expect(subject.direction).to eq("W")
|
14
|
+
end
|
15
|
+
end
|
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
|
@@ -2,20 +2,20 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe Metar::Distance do
|
5
|
-
let(:value) {
|
5
|
+
let(:value) { 12_345.6789 }
|
6
6
|
|
7
7
|
subject { described_class.new(value) }
|
8
8
|
|
9
9
|
context '#value' do
|
10
10
|
it 'treats the parameter as meters' do
|
11
11
|
expect(subject.units).to eq(:meters)
|
12
|
-
expect(subject.value).to eq(
|
12
|
+
expect(subject.value).to eq(12_345.6789)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
context '#to_s' do
|
17
17
|
it 'should default to meters' do
|
18
|
-
expect(subject.to_s).to match(
|
18
|
+
expect(subject.to_s).to match(/^\d+m/)
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'when <= 0.5' do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe I18n do
|
4
4
|
it 'adds our locales to the load path' do
|
5
|
-
project_root = File.expand_path('
|
5
|
+
project_root = File.expand_path('..', File.dirname(__FILE__))
|
6
6
|
english_path = File.join(project_root, 'locales', 'en.yml')
|
7
7
|
italian_path = File.join(project_root, 'locales', 'it.yml')
|
8
8
|
german_path = File.join(project_root, 'locales', 'de.yml')
|
@@ -35,7 +35,7 @@ describe Metar::Parser do
|
|
35
35
|
|
36
36
|
it '.location missing' do
|
37
37
|
expect do
|
38
|
-
setup_parser("FUBAR 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
38
|
+
setup_parser("FUBAR 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
39
39
|
end.to raise_error(Metar::ParseError, /Expecting location/)
|
40
40
|
end
|
41
41
|
|
@@ -48,7 +48,7 @@ describe Metar::Parser do
|
|
48
48
|
|
49
49
|
it 'throws an error is missing' do
|
50
50
|
expect do
|
51
|
-
setup_parser("PAIL 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
51
|
+
setup_parser("PAIL 24006KT 1 3/4SM -SN BKN016 OVC030 M17/M20 A2910 RMK AO2 P0000")
|
52
52
|
end.to raise_error(Metar::ParseError, /Expecting datetime/)
|
53
53
|
end
|
54
54
|
|
@@ -168,7 +168,7 @@ describe Metar::Parser do
|
|
168
168
|
parser = setup_parser('VABB 282210Z 22005KT 4000 HZ SCT018 FEW025TCU BKN100 28/25 Q1003 NOSIG')
|
169
169
|
|
170
170
|
expect(parser.visibility.distance.value).to be_within(0.01).of(4000)
|
171
|
-
|
171
|
+
end
|
172
172
|
|
173
173
|
it '//// with automatic observer' do
|
174
174
|
parser = setup_parser("CYXS 151034Z AUTO 09003KT //// FZFG VV001 M03/M03 A3019 RMK SLP263 ICG")
|
@@ -286,11 +286,25 @@ describe Metar::Parser do
|
|
286
286
|
expect(parser.remarks.size).to eq(0)
|
287
287
|
end
|
288
288
|
|
289
|
-
|
290
|
-
|
289
|
+
context 'known remarks' do
|
290
|
+
it 'parses sea level pressure' do
|
291
|
+
parser = setup_parser('CYZT 052200Z 31010KT 20SM SKC 17/12 A3005 RMK SLP174 20046')
|
292
|
+
|
293
|
+
expect(parser.remarks[0]).to be_a(Metar::SeaLevelPressure)
|
294
|
+
end
|
291
295
|
|
292
|
-
|
293
|
-
|
296
|
+
it 'parses extreme temperature' do
|
297
|
+
parser = setup_parser('CYZT 052200Z 31010KT 20SM SKC 17/12 A3005 RMK SLP174 20046')
|
298
|
+
|
299
|
+
expect(parser.remarks[1]).to be_temperature_extreme(:minimum, 4.6)
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'parses density altitude' do
|
303
|
+
parser = setup_parser('CYBW 010000Z AUTO VRB04KT 9SM SCT070 13/M01 A3028 RMK DENSITY ALT 4100FT=')
|
304
|
+
|
305
|
+
expect(parser.remarks[0]).to be_a(Metar::DensityAltitude)
|
306
|
+
expect(parser.remarks[0].height.value).to be_within(0.001).of(1249.68)
|
307
|
+
end
|
294
308
|
end
|
295
309
|
|
296
310
|
context 'in strict mode' do
|
@@ -314,7 +328,7 @@ describe Metar::Parser do
|
|
314
328
|
end
|
315
329
|
end
|
316
330
|
end
|
317
|
-
|
331
|
+
|
318
332
|
def setup_parser(metar)
|
319
333
|
raw = Metar::Raw::Data.new(metar, Time.now)
|
320
334
|
Metar::Parser.new(raw)
|
@@ -0,0 +1,22 @@
|
|
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
|