Skip to content
Browse files

specials (begin)

  • Loading branch information...
1 parent b2e3391 commit 034d1df10a098e42bd71073abe9bceffbcc4adb0 @akwiatkowski committed Jan 22, 2012
View
4 lib/simple_metar_parser/metar.rb
@@ -8,6 +8,7 @@
require 'metar/pressure'
require 'metar/visibility'
require 'metar/clouds'
+require 'metar/metar_specials'
module SimpleMetarParser
class Metar
@@ -32,7 +33,8 @@ def initialize(_raw, _options = { })
:temperature => Temperature.new(self),
:pressure => Pressure.new(self),
:visibility => Visibility.new(self),
- :clouds => Clouds.new(self)
+ :clouds => Clouds.new(self),
+ :specials => MetarSpecials.new(self)
}
# Create dynamically accessors
View
131 lib/simple_metar_parser/metar/metar_specials.rb
@@ -0,0 +1,131 @@
+$:.unshift(File.dirname(__FILE__))
+
+module SimpleMetarParser
+ class MetarSpecials < Base
+
+ def reset
+ @specials = Array.new
+ end
+
+ attr_reader :specials
+
+ def decode_split(s)
+ decode_specials(s)
+ end
+
+ # Calculate numeric description of clouds
+ def post_process
+ end
+
+ def decode_specials(s)
+ if s =~ /^(VC|\-|\+|\b)(MI|PR|BC|DR|BL|SH|TS|FZ|)(DZ|RA|SN|SG|IC|PE|GR|GS|UP|)(BR|FG|FU|VA|DU|SA|HZ|PY|)(PO|SQ|FC|SS|)$/
+ intensity = case $1
+ when "VC" then
+ "in the vicinity"
+ when "+" then
+ "heavy"
+ when "-" then
+ "light"
+ else
+ "moderate"
+ end
+
+ descriptor = case $2
+ when "MI" then
+ "shallow"
+ when "PR" then
+ "partial"
+ when "BC" then
+ "patches"
+ when "DR" then
+ "low drifting"
+ when "BL" then
+ "blowing"
+ when "SH" then
+ "shower"
+ when "TS" then
+ "thunderstorm"
+ when "FZ" then
+ "freezing"
+ else
+ nil
+ end
+
+ precipitation = case $3
+ when "DZ" then
+ "drizzle"
+ when "RA" then
+ "rain"
+ when "SN" then
+ "snow"
+ when "SG" then
+ "snow grains"
+ when "IC" then
+ "ice crystals"
+ when "PE" then
+ "ice pellets"
+ when "GR" then
+ "hail"
+ when "GS" then
+ "small hail/snow pellets"
+ when "UP" then
+ "unknown"
+ else
+ nil
+ end
+
+ obscuration = case $4
+ when "BR" then
+ "mist"
+ when "FG" then
+ "fog"
+ when "FU" then
+ "smoke"
+ when "VA" then
+ "volcanic ash"
+ when "DU" then
+ "dust"
+ when "SA" then
+ "sand"
+ when "HZ" then
+ "haze"
+ when "PY" then
+ "spray"
+ else
+ nil
+ end
+
+ misc = case $5
+ when "PO" then
+ "dust whirls"
+ when "SQ" then
+ "squalls"
+ #when "FC " then "funnel cloud/tornado/waterspout"
+ when "FC" then
+ "funnel cloud/tornado/waterspout"
+ when "SS" then
+ "duststorm"
+ else
+ nil
+ end
+
+ # when no sensible data do nothing
+ return if descriptor.nil? and precipitation.nil? and obscuration.nil? and misc.nil?
+
+ @specials << {
+ :intensity => intensity,
+ :intensity_raw => $1,
+ :descriptor => descriptor,
+ :descriptor_raw => $2,
+ :precipitation => precipitation,
+ :precipitation_raw => $3,
+ :obscuration => obscuration,
+ :obscuration_raw => $4,
+ :misc => misc,
+ :misc_raw => $5
+ }
+
+ end
+ end
+ end
+end
View
107 lib/simple_metar_parser/tmp/tmp.rb
@@ -36,114 +36,7 @@ def decode_specials(s)
# description http://www.ofcm.gov/fmh-1/pdf/H-CH8.pdf
- if s =~ /^(VC|\-|\+|\b)(MI|PR|BC|DR|BL|SH|TS|FZ|)(DZ|RA|SN|SG|IC|PE|GR|GS|UP|)(BR|FG|FU|VA|DU|SA|HZ|PY|)(PO|SQ|FC|SS|)$/
- intensity = case $1
- when "VC" then
- "in the vicinity"
- when "+" then
- "heavy"
- when "-" then
- "light"
- else
- "moderate"
- end
-
- descriptor = case $2
- when "MI" then
- "shallow"
- when "PR" then
- "partial"
- when "BC" then
- "patches"
- when "DR" then
- "low drifting"
- when "BL" then
- "blowing"
- when "SH" then
- "shower"
- when "TS" then
- "thunderstorm"
- when "FZ" then
- "freezing"
- else
- nil
- end
-
- precipitation = case $3
- when "DZ" then
- "drizzle"
- when "RA" then
- "rain"
- when "SN" then
- "snow"
- when "SG" then
- "snow grains"
- when "IC" then
- "ice crystals"
- when "PE" then
- "ice pellets"
- when "GR" then
- "hail"
- when "GS" then
- "small hail/snow pellets"
- when "UP" then
- "unknown"
- else
- nil
- end
-
- obscuration = case $4
- when "BR" then
- "mist"
- when "FG" then
- "fog"
- when "FU" then
- "smoke"
- when "VA" then
- "volcanic ash"
- when "DU" then
- "dust"
- when "SA" then
- "sand"
- when "HZ" then
- "haze"
- when "PY" then
- "spray"
- else
- nil
- end
-
- misc = case $5
- when "PO" then
- "dust whirls"
- when "SQ" then
- "squalls"
- #when "FC " then "funnel cloud/tornado/waterspout"
- when "FC" then
- "funnel cloud/tornado/waterspout"
- when "SS" then
- "duststorm"
- else
- nil
- end
-
- # when no sensible data do nothing
- return if descriptor.nil? and precipitation.nil? and obscuration.nil? and misc.nil?
-
- @output[:specials] << {
- :intensity => intensity,
- :intensity_raw => $1,
- :descriptor => descriptor,
- :descriptor_raw => $2,
- :precipitation => precipitation,
- :precipitation_raw => $3,
- :obscuration => obscuration,
- :obscuration_raw => $4,
- :misc => misc,
- :misc_raw => $5
- }
- end
end
# Calculate precipitation in self defined units and aproximated real world units
View
6 spec/metar_spec.rb
@@ -75,6 +75,10 @@ def self.find_by_metar(m)
m.clouds.clouds.should be_kind_of(Array)
m.clouds.clouds.size.should == 2
m.clouds.clouds_max.should == 100
+
+ m.specials.should be_kind_of(SimpleMetarParser::MetarSpecials)
+ m.specials.specials.should be_kind_of(Array)
+ m.specials.specials.size.should == 1
end
it "decode metar string (1)" do
@@ -107,6 +111,8 @@ def self.find_by_metar(m)
m.clouds.clouds.size.should == 2
m.clouds.clouds_max.should == 100
+
+ m.specials.specials.size.should == 3
end
end

0 comments on commit 034d1df

Please sign in to comment.
Something went wrong with that request. Please try again.