Module: Noaaer
- Defined in:
- lib/noaaer.rb,
lib/noaaer/station.rb,
lib/noaaer/version.rb,
lib/noaaer/forecast.rb,
lib/noaaer/forecast_day.rb,
lib/noaaer/http_service.rb,
lib/noaaer/current_conditions.rb
Overview
require ‘libxml’
Defined Under Namespace
Classes: CurrentConditions, Forecast, ForecastDay, HttpService, Station
Constant Summary collapse
- VERSION =
"0.0.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.
28 29 30 |
# File 'lib/noaaer.rb', line 28 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.
40 41 42 |
# File 'lib/noaaer.rb', line 40 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
53 54 55 |
# File 'lib/noaaer.rb', line 53 def forecast(num_days, lat, lng) Forecast.from_xml(HttpService.new.get_forecast(num_days, lat, lng)) end |