class SimpleMetarParser::Metar
Constants
- DEFAULT_TIME_INTERVAL
Attributes
month[R]
options[R]
Initial options
raw[R]
Raw metar string
raw_splits[R]
Splits of raw string
year[R]
Public Class Methods
new(_raw, _options = { })
click to toggle source
# File lib/simple_metar_parser/metar.rb, line 20 def initialize(_raw, _options = { }) @raw = _raw.to_s.gsub(/\s/, ' ').strip @raw_splits = @raw.split(' ') @options = _options @options[:time_interval] = _options[:time_interval] || DEFAULT_TIME_INTERVAL @year = _options[:year] || Time.now.utc.year @month = _options[:month] || Time.now.utc.month # metar city code @options_city = _options[:city] @modules = { :wind => Wind.new(self), :time => MetarTime.new(self), :city => MetarCity.new(self), :temperature => Temperature.new(self), :pressure => Pressure.new(self), :visibility => Visibility.new(self), :clouds => Clouds.new(self), :specials => MetarSpecials.new(self), :other => MetarOther.new(self), :runway => Runway.new(self) } # Create dynamically accessors @modules.each_key do |k| self.instance_variable_set("@#{k}".to_sym, @modules[k]) self.class.send :define_method, k do instance_variable_get("@" + k.to_s) end end reset decode post_process end
rails_model=(klass)
click to toggle source
You can set AR model for fetching additional information about city
# File lib/simple_metar_parser/metar.rb, line 98 def self.rails_model=(klass) MetarCity.rails_model = klass end
Public Instance Methods
decode()
click to toggle source
Decode all string fragments
# File lib/simple_metar_parser/metar.rb, line 81 def decode self.raw_splits.each do |split| self.modules.each do |m| m.decode_split(split) end end end
modules()
click to toggle source
Array of all parsing modules
# File lib/simple_metar_parser/metar.rb, line 58 def modules @modules.values end
post_process()
click to toggle source
# File lib/simple_metar_parser/metar.rb, line 89 def post_process self.modules.each do |m| m.post_process end end
reset()
click to toggle source
Reset everything
# File lib/simple_metar_parser/metar.rb, line 74 def reset @modules.each_value do |m| m.reset end end
time_from()
click to toggle source
# File lib/simple_metar_parser/metar.rb, line 102 def time_from self.time.time_from end
time_to()
click to toggle source
# File lib/simple_metar_parser/metar.rb, line 106 def time_to self.time.time_to end
valid?()
click to toggle source
# File lib/simple_metar_parser/metar.rb, line 110 def valid? if not self.temperature.nil? and not self.temperature.degrees.nil? and not self.wind.nil? and not self.time_from.nil? return true else return false end end