Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/noaa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'time'
require 'nokogiri'
require 'geokit'
require 'libxml'
rescue LoadError => e
if require 'rubygems' then retry
else raise(e)
Expand Down
6 changes: 3 additions & 3 deletions lib/noaa/http_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ def initialize(http = Net::HTTP)
end

def get_current_conditions(station_id)
LibXML::XML::Document.string(@HTTP.get(URI.parse("http://www.weather.gov/xml/current_obs/#{station_id}.xml")))
LibXML::XML::Document.string(@HTTP.get(URI.parse("http://w1.weather.gov/xml/current_obs/#{station_id}.xml")))
end

def get_forecast(num_days, lat, lng)
LibXML::XML::Document.string(@HTTP.get(URI.parse("http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?lat=#{lat}&lon=#{lng}&format=24+hourly&numDays=#{num_days}")))
LibXML::XML::Document.string(@HTTP.get(URI.parse("http://w1.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?lat=#{lat}&lon=#{lng}&format=24+hourly&numDays=#{num_days}")))
end

def get_station_list
LibXML::XML::Document.string(@HTTP.get(URI.parse("http://www.weather.gov/xml/current_obs/index.xml")))
LibXML::XML::Document.string(@HTTP.get(URI.parse("http://w1.weather.gov/xml/current_obs/index.xml")))
end
end
end
12 changes: 6 additions & 6 deletions lib/noaa/station.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ def find(id)
#
# NOAA::Station.closest_to(37.989, -77.507)
# NOAA::Station.closest_to([37.989, -77.507])
# NOAA::Station.closest_to(GeoKit::LatLng.new(37.989, -77.507))
# NOAA::Station.closest_to(Geokit::LatLng.new(37.989, -77.507))
def closest_to(*args)
if args.length == 1
if args.first.respond_to?(:distance_to)
closest_to_coordinates(args.first)
elsif %w(first last).all? { |m| args.first.respond_to?(m) }
closest_to_lat_lng(args.first)
else
raise ArgumentError, "expected two-element Array or GeoKit::LatLng"
raise ArgumentError, "expected two-element Array or Geokit::LatLng"
end
elsif args.length == 2
closest_to_lat_lng(args)
else
raise ArgumentError, "closest_to() will accept one Array argument, one GeoKit::LatLng argument, or two FixNum arguments"
raise ArgumentError, "closest_to() will accept one Array argument, one Geokit::LatLng argument, or two FixNum arguments"
end
end

private

def closest_to_lat_lng(pair)
closest_to_coordinates(GeoKit::LatLng.new(pair.first, pair.last))
closest_to_coordinates(Geokit::LatLng.new(pair.first, pair.last))
end

def closest_to_coordinates(coordinates)
Expand All @@ -74,7 +74,7 @@ def stations_file
end
end

# GeoKit::LatLng containing the station's coordinates
# Geokit::LatLng containing the station's coordinates
attr_reader :coordinates

# Station ID (e.g., "KNYC")
Expand All @@ -92,7 +92,7 @@ def initialize(properties)
@id, @name, @state, @xml_url = %w(id name state xml_url).map do |p|
properties[p]
end
@coordinates = GeoKit::LatLng.new(properties['latitude'], properties['longitude'])
@coordinates = Geokit::LatLng.new(properties['latitude'], properties['longitude'])
end

# Latitude of station
Expand Down
2 changes: 1 addition & 1 deletion lib/noaa/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module NOAA
VERSION = '0.2.3'
VERSION = '0.2.4'
end
63 changes: 38 additions & 25 deletions noaa.gemspec
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
# -*- encoding: utf-8 -*-

$: << File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
require 'noaa/version'
# stub: noaa 0.2.4 ruby lib

Gem::Specification.new do |s|
s.name = %q{noaa}
s.version = NOAA::VERSION
s.name = "noaa"
s.version = "0.2.4"

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Mat Brown"]
s.date = Date.today
s.default_executable = %q{noaa-update-stations}
s.description = %q{Ruby API for National Oceanic and Atmospheric Administration weather data}
s.email = %q{mat@patch.com}
s.date = "2014-12-09"
s.description = "Ruby API for National Oceanic and Atmospheric Administration weather data"
s.email = "mat@patch.com"
s.executables = ["noaa-update-stations"]
s.files = Dir.glob('{bin,lib,test,data}/**/*') + %w(CHANGELOG README)
s.has_rdoc = true
s.homepage = %q{http://github.com/outoftime/noaa}
s.post_install_message = %q{Be sure to update the weather station list:
s.extra_rdoc_files = ["CHANGELOG", "README", "bin/noaa-update-stations", "lib/noaa.rb", "lib/noaa/current_conditions.rb", "lib/noaa/forecast.rb", "lib/noaa/forecast_day.rb", "lib/noaa/http_service.rb", "lib/noaa/station.rb", "lib/noaa/station_writer.rb", "lib/noaa/version.rb"]
s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "bin/noaa-update-stations", "data/stations.yml", "lib/noaa.rb", "lib/noaa/current_conditions.rb", "lib/noaa/forecast.rb", "lib/noaa/forecast_day.rb", "lib/noaa/http_service.rb", "lib/noaa/station.rb", "lib/noaa/station_writer.rb", "lib/noaa/version.rb", "noaa.gemspec", "test/data/4-day.xml", "test/data/KVAY.xml", "test/data/stations-abridged.xml", "test/data/stations.xml", "test/data/stations.yml", "test/test_current_conditions.rb", "test/test_forecast.rb", "test/test_helper.rb", "test/test_http_service.rb", "test/test_station.rb", "test/test_station_writer.rb"]
s.homepage = "http://github.com/outoftime/noaa"
s.post_install_message = "Be sure to update the weather station list:\n\n\tsudo noaa-update-stations\n\nThis can be run at any time to update the stations, but you must run it once to initially populate the station list."
s.rdoc_options = ["--line-numbers", "--title", "Noaa", "--main", "README"]
s.rubyforge_project = "noaa"
s.rubygems_version = "2.4.5"
s.summary = "Ruby API for National Oceanic and Atmospheric Administration weather data"
s.test_files = ["test/test_helper.rb", "test/test_station_writer.rb", "test/test_http_service.rb", "test/test_current_conditions.rb", "test/test_forecast.rb", "test/test_station.rb"]

sudo noaa-update-stations
if s.respond_to? :specification_version then
s.specification_version = 4

This can be run at any time to update the stations, but you must run it once to initially populate the station list.}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Noaa", "--main", "README"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{noaa}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Ruby API for National Oceanic and Atmospheric Administration weather data}
s.test_files = ["test/test_station_writer.rb", "test/test_forecast.rb", "test/test_helper.rb", "test/test_station.rb", "test/test_http_service.rb", "test/test_current_conditions.rb"]
s.add_runtime_dependency('nokogiri', '>= 0.9.7')
s.add_runtime_dependency('geokit', '>= 1.5.0')
s.add_development_dependency('mcmire-context', ">= 0.0.16")
s.add_development_dependency('jnunemaker-matchy', ">= 0.4.0")
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<libxml-ruby (>= 0.9.7)>, [">= 0"])
s.add_runtime_dependency(%q<geokit (>= 1.5.0)>, [">= 0"])
s.add_development_dependency(%q<jeremymcanally-context (>= 0.0.6)>, [">= 0"])
s.add_development_dependency(%q<jeremymcanally-matchy (>= 0.0.1)>, [">= 0"])
s.add_development_dependency(%q<ruby-debug (~> 0.10)>, [">= 0"])
else
s.add_dependency(%q<libxml-ruby (>= 0.9.7)>, [">= 0"])
s.add_dependency(%q<geokit (>= 1.5.0)>, [">= 0"])
s.add_dependency(%q<jeremymcanally-context (>= 0.0.6)>, [">= 0"])
s.add_dependency(%q<jeremymcanally-matchy (>= 0.0.1)>, [">= 0"])
s.add_dependency(%q<ruby-debug (~> 0.10)>, [">= 0"])
end
else
s.add_dependency(%q<libxml-ruby (>= 0.9.7)>, [">= 0"])
s.add_dependency(%q<geokit (>= 1.5.0)>, [">= 0"])
s.add_dependency(%q<jeremymcanally-context (>= 0.0.6)>, [">= 0"])
s.add_dependency(%q<jeremymcanally-matchy (>= 0.0.1)>, [">= 0"])
s.add_dependency(%q<ruby-debug (~> 0.10)>, [">= 0"])
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
begin
require 'context'
require 'matchy'
require 'openssl'
rescue LoadError => e
if require 'rubygems' then retry
else raise(e)
Expand Down
4 changes: 2 additions & 2 deletions test/test_station.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestStation < NOAA::TestCase
end

test 'should find closest to coordinates' do
NOAA::Station.closest_to(GeoKit::LatLng.new(40.8, -73.96)).id.should == 'KNYC'
NOAA::Station.closest_to(Geokit::LatLng.new(40.8, -73.96)).id.should == 'KNYC'
end

test 'should find closest to lat/lng' do
Expand Down Expand Up @@ -54,7 +54,7 @@ class TestStation < NOAA::TestCase
end

test 'should return coordinates' do
station.coordinates.should == GeoKit::LatLng.new(40.783, -73.967)
station.coordinates.should == Geokit::LatLng.new(40.783, -73.967)
end

private
Expand Down