Class: Metar::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/metar/parser.rb

Constant Summary collapse

COMPLIANCE =
%i(strict loose).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.metar.clone
  analyze
end

Instance Attribute Details

#metarObject (readonly)

Returns the value of attribute metar.



35
36
37
# File 'lib/metar/parser.rb', line 35

def metar
  @metar
end

#minimum_visibilityObject (readonly)

Returns the value of attribute minimum_visibility.



40
41
42
# File 'lib/metar/parser.rb', line 40

def minimum_visibility
  @minimum_visibility
end

#observerObject (readonly)

Returns the value of attribute observer.



36
37
38
# File 'lib/metar/parser.rb', line 36

def observer
  @observer
end

#present_weatherObject (readonly)

Returns the value of attribute present_weather.



42
43
44
# File 'lib/metar/parser.rb', line 42

def present_weather
  @present_weather
end

#rawObject (readonly)

Returns the value of attribute raw.



34
35
36
# File 'lib/metar/parser.rb', line 34

def raw
  @raw
end

#recent_weatherObject (readonly)

Returns the value of attribute recent_weather.



47
48
49
# File 'lib/metar/parser.rb', line 47

def recent_weather
  @recent_weather
end

#remarksObject (readonly)

Returns the value of attribute remarks.



49
50
51
# File 'lib/metar/parser.rb', line 49

def remarks
  @remarks
end

#runway_visible_rangeObject (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_pressureObject (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_conditionsObject (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_pointObject (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

#unparsedObject (readonly)

Returns the value of attribute unparsed.



48
49
50
# File 'lib/metar/parser.rb', line 48

def unparsed
  @unparsed
end

#variable_windObject (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_visibilityObject (readonly)

Returns the value of attribute vertical_visibility.



44
45
46
# File 'lib/metar/parser.rb', line 44

def vertical_visibility
  @vertical_visibility
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



39
40
41
# File 'lib/metar/parser.rb', line 39

def visibility
  @visibility
end

#windObject (readonly)

Returns the value of attribute wind.



37
38
39
# File 'lib/metar/parser.rb', line 37

def wind
  @wind
end

Class Method Details

.complianceObject



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_attributesObject



20
21
22
# File 'lib/metar/parser.rb', line 20

def self.thread_attributes
  Thread.current[:metar_parser] ||= {}
end

Instance Method Details

#cavok?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/metar/parser.rb', line 65

def cavok?
  @cavok
end

#dew_pointObject



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_attributesObject



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: 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_codeObject



57
58
59
# File 'lib/metar/parser.rb', line 57

def station_code
  @station_code.value
end

#temperatureObject



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

#timeObject



61
62
63
# File 'lib/metar/parser.rb', line 61

def time
  @time.value
end