Class: Metarman::Weather

Inherits:
Object
  • Object
show all
Defined in:
lib/metarman/weather.rb

Instance Method Summary collapse

Constructor Details

#initialize(icao) ⇒ Weather

Returns a new instance of Weather.



5
6
7
8
# File 'lib/metarman/weather.rb', line 5

def initialize(icao)
  @icao = icao.upcase
  @result = {}
end

Instance Method Details

#getObject



10
11
12
13
14
15
16
17
18
19
20
21
# 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_rawObject

This returns time and metar only.



24
25
26
27
# File 'lib/metarman/weather.rb', line 24

def get_raw
  self.get
  @result
end

#get_with_infoObject

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



30
31
32
33
34
35
36
37
# 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