Module: NOAA
- Defined in:
- lib/noaa.rb,
lib/noaa/station.rb,
lib/noaa/version.rb,
lib/noaa/forecast.rb,
lib/noaa/forecast_day.rb,
lib/noaa/http_service.rb,
lib/noaa/station_writer.rb,
lib/noaa/current_conditions.rb
Overview
The NOAA singleton provides methods to conveniently access information from the NOAA weather feed. For the most part, NOAA.current_conditions and NOAA.forecast will be the only entry point into the NOAA API you will need; one exception is discussed below.
Defined Under Namespace
Classes: CurrentConditions, Forecast, ForecastDay, HttpService, Station, StationWriter
Constant Summary collapse
- VERSION =
'0.2.4'
Class Method Summary collapse
-
.current_conditions(lat, lng) ⇒ Object
Retrieve the current weather conditions for a given latitude and longitude.
-
.current_conditions_at_station(station_id) ⇒ Object
Retrieve the current weather conditions for a given weather station ID.
-
.forecast(num_days, lat, lng) ⇒ Object
Retrieve daily forecast information for a given latitude and longitude.
Class Method Details
.current_conditions(lat, lng) ⇒ Object
Retrieve the current weather conditions for a given latitude and longitude. Returns an instance of NOAA::CurrentConditions.
NOAA.current_conditions(37.989, -77.507) #=> NOAA::CurrentConditions encapsulating current conditions at this point
Note: This method parses the stored list of all weather stations in the US and then finds the closest one to the given coordinates, as the NOAA XML API only takes a weather station ID as input. Clearly, this is an expensive operation; if your application needs to repeatedly request conditions for the same point, you will be much better off determining the current station once using NOAA::Station.closest_to, storing the station ID, and then passing it into NOAA.current_conditions_at_station when you need to get the latest conditions.
34 35 36 |
# File 'lib/noaa.rb', line 34 def current_conditions(lat, lng) current_conditions_at_station(Station.closest_to(lat, lng).id) end |
.current_conditions_at_station(station_id) ⇒ Object
Retrieve the current weather conditions for a given weather station ID. Returns an instance of NOAA::CurrentConditions.
NOAA.current_conditions_at_station('KNYC') #=> NOAA::CurrentConditions encapsulating current conditions in Central Park
See discussion above regarding why this method is often preferable to simply calling #current_conditions.
46 47 48 |
# File 'lib/noaa.rb', line 46 def current_conditions_at_station(station_id) CurrentConditions.from_xml(HttpService.new.get_current_conditions(station_id)) end |
.forecast(num_days, lat, lng) ⇒ Object
Retrieve daily forecast information for a given latitude and longitude. Returns an instance of NOAA::Forecast.
NOAA.forecast(4, 37.989, -77.507) #=> NOAA::Forecast containing next four days of forecast data for given coordinates
Note: The NOAA updates this data no more than once an hour, and asks that users of the API not request the forecast for a given location more frequently than that. For more information, please see www.nws.noaa.gov/xml/#frequency
59 60 61 |
# File 'lib/noaa.rb', line 59 def forecast(num_days, lat, lng) Forecast.from_xml(HttpService.new.get_forecast(num_days, lat, lng)) end |