metar-parser 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -2
  3. data/lib/metar/data.rb +31 -32
  4. data/lib/metar/parser.rb +12 -11
  5. data/lib/metar/raw.rb +1 -1
  6. data/lib/metar/report.rb +3 -7
  7. data/lib/metar/station.rb +15 -21
  8. data/lib/metar/version.rb +1 -2
  9. data/spec/data_spec.rb +26 -0
  10. data/spec/{unit/distance_spec.rb → distance_spec.rb} +3 -3
  11. data/spec/{unit/i18n_spec.rb → i18n_spec.rb} +1 -1
  12. data/spec/{unit/parser_spec.rb → parser_spec.rb} +22 -8
  13. data/spec/pressure_spec.rb +22 -0
  14. data/spec/{unit/raw_spec.rb → raw_spec.rb} +33 -40
  15. data/spec/{unit/remark_spec.rb → remark_spec.rb} +4 -25
  16. data/spec/{unit/report_spec.rb → report_spec.rb} +18 -16
  17. data/spec/runway_visible_range_spec.rb +81 -0
  18. data/spec/{unit/sky_condition_spec.rb → sky_condition_spec.rb} +0 -1
  19. data/spec/spec_helper.rb +1 -1
  20. data/spec/speed_spec.rb +45 -0
  21. data/spec/{unit/station_spec.rb → station_spec.rb} +83 -52
  22. data/spec/{unit/temperature_spec.rb → temperature_spec.rb} +7 -7
  23. data/spec/{unit/variable_wind_spec.rb → variable_wind_spec.rb} +10 -11
  24. data/spec/{unit/vertical_visibility_spec.rb → vertical_visibility_spec.rb} +1 -1
  25. data/spec/{unit/visibility_spec.rb → visibility_spec.rb} +16 -20
  26. data/spec/weather_phenomenon_spec.rb +66 -0
  27. data/spec/{unit/wind_spec.rb → wind_spec.rb} +10 -11
  28. metadata +53 -38
  29. data/bin/parse_raw.rb +0 -27
  30. data/spec/unit/pressure_spec.rb +0 -22
  31. data/spec/unit/runway_visible_range_spec.rb +0 -88
  32. data/spec/unit/speed_spec.rb +0 -45
  33. data/spec/unit/weather_phenomenon_spec.rb +0 -66
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f2c3aa5a4cae4d28cfa2ac65827416eae8ea706
4
- data.tar.gz: 2edc10a772b9142531f3e3a942b5c913d043c98b
3
+ metadata.gz: b47782dda9aa78314cf6244e1d395acff88cd025
4
+ data.tar.gz: 097ed5364bdf7ded700dd77b5722a863655ae2b9
5
5
  SHA512:
6
- metadata.gz: aa27381ba8e8bca2a90df135f4d1d3d9558d8c063f119e575a51e76577b4bb97164412204d0cffd49d4557e6ea99654ddd44b48c3781dfd4826bb3a4e18c93dd
7
- data.tar.gz: 18eb8ba4319e3864b129dce58fffc9231623e63da8f8c737445c53693e5eaef669c9d4da3c87377d2b3dffcdaac00787a848c51fcd679cecd31d47396a2e08e5
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 :default => :spec
6
+ task default: :spec
7
7
 
8
- RSpec::Core::RakeTask.new do | t |
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
- :units => @units,
27
- :precision => 0,
28
- :abbreviated => true
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 = {:abbreviated => true, :precision => 0}.merge(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
- :direction_units => :compass,
128
- :speed_units => :kilometers_per_hour
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
- :abbreviated => true,
137
- :precision => 0,
138
- :units => options[:speed_units]
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(:units => options[:direction_units])
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
- :abbreviated => true,
154
- :precision => 0,
155
- :units => options[:speed_units]
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(:units => :compass)} - #{@direction2.to_s(:units => :compass)}"
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
- :abbreviated => true,
223
- :precision => 0,
224
- :units => :kilometers
222
+ abbreviated: true,
223
+ precision: 0,
224
+ units: :kilometers,
225
225
  }.merge(options)
226
- direction_options = {:units => :compass}
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
- :abbreviated => true,
292
- :precision => 0,
293
- :units => @units
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
- chunk =~ /^(\d{4})([NESW]?)$/
619
- distance = Distance.new($1)
618
+ metres, direction = chunk.scan(/^(\d{4})([NESW]?)$/)[0]
619
+ distance = Distance.new(metres)
620
620
 
621
- new(distance, $2, :more_than)
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
- chunk =~ /^(\d+)(FT)$/
628
- height = Distance.feet($1)
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
- module Metar
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(3)
315
- r = Metar::VisibilityRemark.parse(@chunks[2])
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(3)
320
- r = Metar::DensityAltitude.parse(@chunks[2])
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
@@ -98,7 +98,7 @@ module Metar
98
98
  while attempts < 2
99
99
  begin
100
100
  s = ''
101
- connection.retrbinary( "RETR #{ cccc }.TXT", 1024 ) do |chunk|
101
+ connection.retrbinary("RETR #{ cccc }.TXT", 1024) do |chunk|
102
102
  s << chunk
103
103
  end
104
104
  return s
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 | key |
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( Set.new ) { |a, s| a.add( s[ :country ] ) }.to_a.sort
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( country )
39
- all.select { | s | s.country == country }
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( cccc, noaa_data )
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( @cccc )
66
- Metar::Parser.new( raw )
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( parser )
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
- :cccc => fields[0],
93
- :name => fields[3],
94
- :state => fields[4],
95
- :country => fields[5],
96
- :latitude => fields[7],
97
- :longitude => fields[8],
98
- :raw => station.clone
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!( noaa_data )
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
@@ -2,9 +2,8 @@ module Metar
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
9
  end
10
-
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) { 12345.6789 }
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(12345.6789)
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(%r(^\d+m))
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('../..', File.dirname(__FILE__))
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
- end
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
- it 'parses known remarks' do
290
- parser = setup_parser('CYZT 052200Z 31010KT 20SM SKC 17/12 A3005 RMK SLP174 20046')
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
- expect(parser.remarks[0]).to be_a(Metar::SeaLevelPressure)
293
- expect(parser.remarks[1]).to be_temperature_extreme(:minimum, 4.6)
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