Class: Metar::Parser
- Inherits:
-
Object
- Object
- Metar::Parser
- Defined in:
- lib/metar/parser.rb
Constant Summary collapse
- COMPLIANCE =
%i(strict loose).freeze
Instance Attribute Summary collapse
-
#metar ⇒ Object
readonly
Returns the value of attribute metar.
-
#minimum_visibility ⇒ Object
readonly
Returns the value of attribute minimum_visibility.
-
#observer ⇒ Object
readonly
Returns the value of attribute observer.
-
#present_weather ⇒ Object
readonly
Returns the value of attribute present_weather.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#recent_weather ⇒ Object
readonly
Returns the value of attribute recent_weather.
-
#remarks ⇒ Object
readonly
Returns the value of attribute remarks.
-
#runway_visible_range ⇒ Object
readonly
Returns the value of attribute runway_visible_range.
-
#sea_level_pressure ⇒ Object
readonly
Returns the value of attribute sea_level_pressure.
-
#sky_conditions ⇒ Object
readonly
Returns the value of attribute sky_conditions.
-
#temperature_and_dew_point ⇒ Object
readonly
Returns the value of attribute temperature_and_dew_point.
-
#unparsed ⇒ Object
readonly
Returns the value of attribute unparsed.
-
#variable_wind ⇒ Object
readonly
Returns the value of attribute variable_wind.
-
#vertical_visibility ⇒ Object
readonly
Returns the value of attribute vertical_visibility.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
-
#wind ⇒ Object
readonly
Returns the value of attribute wind.
Class Method Summary collapse
- .compliance ⇒ Object
- .compliance=(compliance) ⇒ Object
- .for_cccc(cccc) ⇒ Object
- .thread_attributes ⇒ Object
Instance Method Summary collapse
- #cavok? ⇒ Boolean
- #dew_point ⇒ Object
-
#initialize(raw) ⇒ Parser
constructor
A new instance of Parser.
- #raw_attributes ⇒ Object
- #station_code ⇒ Object
- #temperature ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(raw) ⇒ Parser
Returns a new instance of Parser.
51 52 53 54 55 |
# File 'lib/metar/parser.rb', line 51 def initialize(raw) @raw = raw @metar = raw..clone analyze end |
Instance Attribute Details
#metar ⇒ Object (readonly)
Returns the value of attribute metar.
35 36 37 |
# File 'lib/metar/parser.rb', line 35 def @metar end |
#minimum_visibility ⇒ Object (readonly)
Returns the value of attribute minimum_visibility.
40 41 42 |
# File 'lib/metar/parser.rb', line 40 def minimum_visibility @minimum_visibility end |
#observer ⇒ Object (readonly)
Returns the value of attribute observer.
36 37 38 |
# File 'lib/metar/parser.rb', line 36 def observer @observer end |
#present_weather ⇒ Object (readonly)
Returns the value of attribute present_weather.
42 43 44 |
# File 'lib/metar/parser.rb', line 42 def present_weather @present_weather end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
34 35 36 |
# File 'lib/metar/parser.rb', line 34 def raw @raw end |
#recent_weather ⇒ Object (readonly)
Returns the value of attribute recent_weather.
47 48 49 |
# File 'lib/metar/parser.rb', line 47 def recent_weather @recent_weather end |
#remarks ⇒ Object (readonly)
Returns the value of attribute remarks.
49 50 51 |
# File 'lib/metar/parser.rb', line 49 def remarks @remarks end |
#runway_visible_range ⇒ Object (readonly)
Returns the value of attribute runway_visible_range.
41 42 43 |
# File 'lib/metar/parser.rb', line 41 def runway_visible_range @runway_visible_range end |
#sea_level_pressure ⇒ Object (readonly)
Returns the value of attribute sea_level_pressure.
46 47 48 |
# File 'lib/metar/parser.rb', line 46 def sea_level_pressure @sea_level_pressure end |
#sky_conditions ⇒ Object (readonly)
Returns the value of attribute sky_conditions.
43 44 45 |
# File 'lib/metar/parser.rb', line 43 def sky_conditions @sky_conditions end |
#temperature_and_dew_point ⇒ Object (readonly)
Returns the value of attribute temperature_and_dew_point.
45 46 47 |
# File 'lib/metar/parser.rb', line 45 def temperature_and_dew_point @temperature_and_dew_point end |
#unparsed ⇒ Object (readonly)
Returns the value of attribute unparsed.
48 49 50 |
# File 'lib/metar/parser.rb', line 48 def unparsed @unparsed end |
#variable_wind ⇒ Object (readonly)
Returns the value of attribute variable_wind.
38 39 40 |
# File 'lib/metar/parser.rb', line 38 def variable_wind @variable_wind end |
#vertical_visibility ⇒ Object (readonly)
Returns the value of attribute vertical_visibility.
44 45 46 |
# File 'lib/metar/parser.rb', line 44 def vertical_visibility @vertical_visibility end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
39 40 41 |
# File 'lib/metar/parser.rb', line 39 def visibility @visibility end |
#wind ⇒ Object (readonly)
Returns the value of attribute wind.
37 38 39 |
# File 'lib/metar/parser.rb', line 37 def wind @wind end |
Class Method Details
.compliance ⇒ Object
24 25 26 |
# File 'lib/metar/parser.rb', line 24 def self.compliance thread_attributes[:compliance] ||= :loose end |
.compliance=(compliance) ⇒ Object
28 29 30 31 32 |
# File 'lib/metar/parser.rb', line 28 def self.compliance=(compliance) raise 'Unknown compliance' unless COMPLIANCE.find(compliance) thread_attributes[:compliance] = compliance end |
.for_cccc(cccc) ⇒ Object
13 14 15 16 |
# File 'lib/metar/parser.rb', line 13 def self.for_cccc(cccc) raw = Metar::Raw::Noaa.new(cccc) new(raw) end |
.thread_attributes ⇒ Object
20 21 22 |
# File 'lib/metar/parser.rb', line 20 def self.thread_attributes Thread.current[:metar_parser] ||= {} end |
Instance Method Details
#cavok? ⇒ Boolean
65 66 67 |
# File 'lib/metar/parser.rb', line 65 def cavok? @cavok end |
#dew_point ⇒ Object
75 76 77 78 79 |
# File 'lib/metar/parser.rb', line 75 def dew_point return nil if @temperature_and_dew_point.nil? @temperature_and_dew_point.dew_point end |
#raw_attributes ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/metar/parser.rb', line 81 def raw_attributes attr = { metar: , datetime: @time.raw, station_code: station_code } %i( minimum_visibility observer sea_level_pressure temperature_and_dew_point visibility variable_wind vertical_visibility wind ).each do |key| attr = add_raw_if_present(attr, key) end %i( present_weather recent_weather remarks runway_visible_range sky_conditions ).each do |key| attr = add_raw_if_not_empty(attr, key) end attr[:cavok] = "CAVOK" if cavok? attr end |
#station_code ⇒ Object
57 58 59 |
# File 'lib/metar/parser.rb', line 57 def station_code @station_code.value end |
#temperature ⇒ Object
69 70 71 72 73 |
# File 'lib/metar/parser.rb', line 69 def temperature return nil if @temperature_and_dew_point.nil? @temperature_and_dew_point.temperature end |
#time ⇒ Object
61 62 63 |
# File 'lib/metar/parser.rb', line 61 def time @time.value end |