Class: SimpleMetarParser::Wind
- Defined in:
- lib/simple_metar_parser/metar/wind.rb
Constant Summary collapse
- KNOTS_TO_METERS_PER_SECOND =
1.85 / 3.6
- KILOMETERS_PER_HOUR_TO_METERS_PER_SECOND =
1.0 / 3.6
Instance Attribute Summary collapse
-
#wind ⇒ Object
(also: #wind_speed)
readonly
Wind speed in meters per second.
-
#wind_direction ⇒ Object
readonly
Direction of wind.
Attributes inherited from Base
Instance Method Summary collapse
- #decode_split(s) ⇒ Object
-
#decode_wind(s) ⇒ Object
Wind parameters in meters per second.
-
#decode_wind_variable(s) ⇒ Object
Variable wind direction.
-
#direction ⇒ Object
Wind direction.
-
#kmh ⇒ Object
Kilometers per hour.
-
#knots ⇒ Object
Knots.
-
#mps ⇒ Object
Meters per second.
- #post_process ⇒ Object
-
#recalculate_winds ⇒ Object
Calculate wind parameters, some metar string has multiple winds recorded.
- #reset ⇒ Object
-
#wind_speed_kmh ⇒ Object
Wind speed in KM/H.
-
#wind_speed_knots ⇒ Object
Wind speed in knots.
Methods inherited from Base
Constructor Details
This class inherits a constructor from SimpleMetarParser::Base
Instance Attribute Details
#wind ⇒ Object (readonly) Also known as: wind_speed
Wind speed in meters per second
106 107 108 |
# File 'lib/simple_metar_parser/metar/wind.rb', line 106 def wind @wind end |
#wind_direction ⇒ Object (readonly)
Direction of wind
110 111 112 |
# File 'lib/simple_metar_parser/metar/wind.rb', line 110 def wind_direction @wind_direction end |
Instance Method Details
#decode_split(s) ⇒ Object
14 15 16 17 |
# 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) ⇒ Object
Wind parameters in meters per second
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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) ⇒ Object
Variable wind direction
83 84 85 86 87 88 89 90 91 92 |
# 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 ⇒ Object
Wind direction
140 141 142 |
# File 'lib/simple_metar_parser/metar/wind.rb', line 140 def direction self.wind_direction end |
#kmh ⇒ Object
Kilometers per hour
130 131 132 |
# File 'lib/simple_metar_parser/metar/wind.rb', line 130 def kmh self.wind_speed_kmh end |
#knots ⇒ Object
Knots
135 136 137 |
# File 'lib/simple_metar_parser/metar/wind.rb', line 135 def knots self.wind_speed_knots end |
#mps ⇒ Object
Meters per second
125 126 127 |
# File 'lib/simple_metar_parser/metar/wind.rb', line 125 def mps self.wind end |
#post_process ⇒ Object
19 20 21 |
# File 'lib/simple_metar_parser/metar/wind.rb', line 19 def post_process recalculate_winds end |
#recalculate_winds ⇒ Object
Calculate wind parameters, some metar string has multiple winds recorded
95 96 97 98 99 100 101 102 103 |
# 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 ⇒ Object
6 7 8 9 |
# File 'lib/simple_metar_parser/metar/wind.rb', line 6 def reset @winds = Array.new @winds_variable_directions = Array.new end |
#wind_speed_kmh ⇒ Object
Wind speed in KM/H
119 120 121 122 |
# 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 ⇒ Object
Wind speed in knots
113 114 115 116 |
# 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 |