class SimpleMetarParser::Wind
Constants
- KILOMETERS_PER_HOUR_TO_METERS_PER_SECOND
- KNOTS_TO_METERS_PER_SECOND
Attributes
wind[R]
Wind
speed in meters per second
wind_direction[R]
Direction of wind
wind_speed[R]
Wind
speed in meters per second
Public Instance Methods
decode_split(s)
click to toggle source
# File lib/simple_metar_parser/metar/wind.rb, line 14 def decode_split(s) decode_wind(s) decode_wind_variable(s) end
decode_wind(s)
click to toggle source
Wind
parameters in meters per second
# File lib/simple_metar_parser/metar/wind.rb, line 24 def decode_wind(s) if s =~ /(\d{3})(\d{2})G?(\d{2})?(KT|MPS|KMH)/ # different units wind = case $4 when "KT" then $2.to_f * KNOTS_TO_METERS_PER_SECOND when "MPS" then $2.to_f when "KMH" then $2.to_f * KILOMETERS_PER_HOUR_TO_METERS_PER_SECOND else nil end wind_max = case $4 when "KT" then $3.to_f * KNOTS_TO_METERS_PER_SECOND when "MPS" then $3.to_f when "KMH" then $3.to_f * KILOMETERS_PER_HOUR_TO_METERS_PER_SECOND else nil end # wind_max is not less than normal wind if wind_max < wind or wind_max.nil? wind_max = wind end @winds << { :wind => wind, :wind_max => wind_max, :wind_direction => $1.to_i } end # variable/unknown direction if s =~ /VRB(\d{2})(KT|MPS|KMH)/ wind = case $2 when "KT" then $1.to_f * KNOTS_TO_METERS_PER_SECOND when "MPS" then $1.to_f when "KMH" then $1.to_f * KILOMETERS_PER_HOUR_TO_METERS_PER_SECOND else nil end @winds << { :wind => wind } end end
decode_wind_variable(s)
click to toggle source
Variable wind direction
# File lib/simple_metar_parser/metar/wind.rb, line 83 def decode_wind_variable(s) if s =~ /(\d{3})V(\d{3})/ @winds_variable_directions << { :wind_variable_direction_from => $1.to_i, :wind_variable_direction_to => $2.to_i, :wind_direction => ($1.to_i + $2.to_i) / 2, :wind_variable => true } end end
direction()
click to toggle source
Wind
direction
# File lib/simple_metar_parser/metar/wind.rb, line 140 def direction self.wind_direction end
kmh()
click to toggle source
Kilometers per hour
# File lib/simple_metar_parser/metar/wind.rb, line 130 def kmh self.wind_speed_kmh end
knots()
click to toggle source
Knots
# File lib/simple_metar_parser/metar/wind.rb, line 135 def knots self.wind_speed_knots end
mps()
click to toggle source
Meters per second
# File lib/simple_metar_parser/metar/wind.rb, line 125 def mps self.wind end
post_process()
click to toggle source
# File lib/simple_metar_parser/metar/wind.rb, line 19 def post_process recalculate_winds end
recalculate_winds()
click to toggle source
Calculate wind parameters, some metar string has multiple winds recorded
# File lib/simple_metar_parser/metar/wind.rb, line 95 def recalculate_winds wind_sum = @winds.collect { |w| w[:wind] }.inject(0) { |b, i| b + i } @wind = wind_sum.to_f / @winds.size if @winds.size == 1 @wind_direction = @winds.first[:wind_direction] else @wind_direction = nil end end
reset()
click to toggle source
# File lib/simple_metar_parser/metar/wind.rb, line 6 def reset @winds = Array.new @winds_variable_directions = Array.new end
wind_speed_kmh()
click to toggle source
Wind
speed in KM/H
# File lib/simple_metar_parser/metar/wind.rb, line 119 def wind_speed_kmh return self.wind if self.wind.nil? return self.wind / KILOMETERS_PER_HOUR_TO_METERS_PER_SECOND end
wind_speed_knots()
click to toggle source
Wind
speed in knots
# File lib/simple_metar_parser/metar/wind.rb, line 113 def wind_speed_knots return self.wind if self.wind.nil? return self.wind / KNOTS_TO_METERS_PER_SECOND end