class Metarman::Weather

Public Class Methods

new(icao) click to toggle source
# File lib/metarman/weather.rb, line 5
def initialize(icao)
  @icao = icao.upcase
  @result = {}
end

Public Instance Methods

get() click to toggle source
# File lib/metarman/weather.rb, line 10
def get
  uri = URI.parse("https://tgftp.nws.noaa.gov/data/observations/metar/stations/#{@icao}.TXT")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  req = Net::HTTP::Get.new(uri.request_uri)
  res = http.request(req).body.chomp.split("\n")

  @result[:time] = res[0]
  @result[:metar_raw] = res[1]
end
get_raw() click to toggle source

This returns time and metar only.

# File lib/metarman/weather.rb, line 24
def get_raw
  self.get
  @result
end
get_with_info() click to toggle source

This returns time, metar, airport information and human-readable weather information.

# File lib/metarman/weather.rb, line 30
def get_with_info
  self.get
  ap = Data.new(@icao).get
  parser = MetarParser.new(@result[:metar_raw])
  @result[:airport] = ap
  @result[:weather] = parser.execute
  @result
end