Class: Barometer::WebService::NoaaStation
- Inherits:
-
WebService
- Object
- WebService
- Barometer::WebService::NoaaStation
- Defined in:
- lib/barometer/web_services/noaa_station_id.rb
Overview
Web Service: NOAA Station ID
uses noaa to find the closest station id
Class Method Summary collapse
- ._fetch_via_noaa(latitude, longitude) ⇒ Object
-
.fetch(latitude, longitude) ⇒ Object
get the closest station id for given coordinates.
Class Method Details
._fetch_via_noaa(latitude, longitude) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/barometer/web_services/noaa_station_id.rb', line 26 def self._fetch_via_noaa(latitude, longitude) response = self.get( "http://forecast.weather.gov/MapClick.php?", :query => { :textField1 => latitude, :textField2 => longitude }, :format => :html, :timeout => Barometer.timeout ) # parse the station id from the given page station_id = nil begin doc = Nokogiri::HTML.parse(response.body) if doc && links = doc.search(".current-conditions-extra a") sid_link = links.detect{|link| link.attr("href").match(/sid=(.*)&/)} begin station_id = sid_link.attr("href").match(/sid=(.*?)&/)[1] rescue end end rescue puts "[ERROR] finding NOAA station near #{latitude}, #{longitude}" if Barometer::debug? end station_id end |
.fetch(latitude, longitude) ⇒ Object
get the closest station id for given coordinates
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/barometer/web_services/noaa_station_id.rb', line 11 def self.fetch(latitude, longitude) begin require 'nokogiri' rescue LoadError puts "\n****\nTo use this functionality you will need to install Nokogiri >= 1.3.3\n****\n\n" return nil end puts "fetching NOAA station ID near #{latitude}, #{longitude}" if Barometer::debug? return nil unless latitude && longitude _fetch_via_noaa(latitude, longitude) end |