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
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format progress
36 changes: 36 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
PATH
remote: .
specs:
noaa (0.2.3)
geokit (>= 1.5.0)
nokogiri (>= 0.9.7)

GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
geokit (1.8.4)
multi_json (>= 1.3.2)
jnunemaker-matchy (0.4.0)
mcmire-context (0.5.6)
mini_portile (0.5.2)
multi_json (1.8.4)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)

PLATFORMS
ruby

DEPENDENCIES
jnunemaker-matchy (>= 0.4.0)
mcmire-context (>= 0.0.16)
noaa!
rspec
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
7 changes: 3 additions & 4 deletions noaa.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.description = %q{Ruby API for National Oceanic and Atmospheric Administration weather data}
s.email = %q{mat@patch.com}
s.executables = ["noaa-update-stations"]
s.files = Dir.glob('{bin,lib,test,data}/**/*') + %w(CHANGELOG README)
s.files = Dir.glob('{bin,lib,spec,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:
Expand All @@ -27,9 +27,8 @@ This can be run at any time to update the stations, but you must run it once to
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.test_files = ["spec/station_writer_spec.rb", "spec/forecast_spec.rb", "spec/spec_helper.rb", "spec/station_spec.rb", "spec/http_service_spec.rb", "spec/current_conditions_spec.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")
s.add_development_dependency('rspec')
end
212 changes: 212 additions & 0 deletions spec/current_conditions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
require "spec_helper"

describe NOAA do
describe NOAA::CurrentConditions do
let(:xml_doc) { LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', 'KVAY.xml')) }
let(:current_conditions) { NOAA::CurrentConditions.from_xml(xml_doc) }

describe "#observed_at" do
it "returns observation time" do
expect(current_conditions.observed_at)
.to eq Time.parse('2008-12-23 10:54:00 -0500')
end
end

describe "#weather_description" do
it "returns the weather description" do
expect(current_conditions.weather_description).to eq 'Fair'
end
end

describe "#weather_summary" do
it "returns the weather description" do
expect(current_conditions.weather_summary).to eq 'Fair'
end
end

describe "#weather_type_code" do
it "returns the weather type code" do
expect(current_conditions.weather_type_code).to eq :skc
end
end

describe "#temperature" do
context "when the unit is not specified" do
it "returns the temperature in farenheit" do
expect(current_conditions.temperature).to eq 24
end
end

context "when farenheit is specified" do
it "returns the temperature in farenheit" do
expect(current_conditions.temperature(:f)).to eq 24
end
end

context "when celsius is specified" do
it "returns the temperature in celsius" do
expect(current_conditions.temperature(:c)).to eq -4
end
end

context "when an unknown unit is specified" do
it "raises an Argument error" do
expect { current_conditions.temperature(:kelvin) }
.to raise_error ArgumentError
end
end
end

describe "#image_url" do
it "returns the image URL" do
expect(current_conditions.image_url)
.to eq 'http://weather.gov/weather/images/fcicons/skc.jpg'
end
end

describe "#relative_humidity" do
it "returns the relative humidity" do
expect(current_conditions.relative_humidity)
.to eq 52
end
end

describe "#wind_direction" do
it 'returns the wind direction' do
expect(current_conditions.wind_direction).to eq 'Northwest'
end
end

describe "#wind_degrees" do
it 'returns the wind degrees' do
expect(current_conditions.wind_degrees).to eq 330
end
end

describe "#wind_speed" do
it 'returns the wind speed in MPH' do
expect(current_conditions.wind_speed).to eq 3.45
end
end

describe "#wind_gust" do
it 'returns the wind gust in MPH' do
expect(current_conditions.wind_gust).to eq 10.25
end
end

describe "#pressure" do
context "when the unit is not specified" do
it 'returns the pressure in inches' do
expect(current_conditions.pressure).to eq 30.7
end
end

context "when the provided unit is 'in'" do
it 'returns the pressure in inches' do
expect(current_conditions.pressure(:in)).to eq 30.7
end
end

context "when the provided unit is 'mb'" do
it 'returns the pressure in millibars' do
expect(current_conditions.pressure(:mb)).to eq 1039.5
end
end

context "when the provided unit is not recognized" do
it 'raises an ArgumentError' do
expect { current_conditions.pressure(:psi) }.to raise_error(ArgumentError)
end
end
end


describe "#dew_point" do
context "when the unit is not specified" do
it 'returns the dew point in fahrenheit' do
expect(current_conditions.dew_point).to eq 9
end
end

context "when the provided unit is farenheit" do
it 'returns the dew point in fahrenheit' do
expect(current_conditions.dew_point(:f)).to eq 9
end
end

context "when the provided unit is celsius" do
it 'returns the dew point in celsius' do
expect(current_conditions.dew_point(:c)).to eq -13
end
end

context "when the provided unit is not recognized" do
it 'raises an ArgumentError' do
expect { current_conditions.dew_point(:kelvin) }
.to raise_error(ArgumentError)
end
end
end

describe "#heat_index" do
it 'returns the heat index in fahrenheit by default' do
expect(current_conditions.heat_index).to eq 105
end

context "when the provided unit is farenheit" do
it 'returns the heat index in fahrenheit' do
expect(current_conditions.heat_index(:f)).to eq 105
end
end

context "when the provided unit is celsius" do
it 'returns the heat index in celsius' do
expect(current_conditions.heat_index(:c)).to eq 41
end
end

context "when the provided unit is unrecognized" do
it 'raises an ArgumentError' do
expect { current_conditions.heat_index(:kelvin) }
.to raise_error(ArgumentError)
end
end

context "when the heat index is NA"
end

describe "#wind_chill" do
it 'returns the wind chill in fahrenheit by default' do
expect(current_conditions.wind_chill).to eq 19
end

context "when the provided unit is farenheit" do
it 'returns the wind chill in fahrenheit' do
expect(current_conditions.wind_chill(:f)).to eq 19
end
end

context "when the provided unit is celsius" do
it 'returns the wind chill in celsius' do
expect(current_conditions.wind_chill(:c)).to eq -7
end
end

context "when the provided unit is unrecognized" do
it 'raises an ArgumentError' do
expect { current_conditions.wind_chill(:kelvin) }.to raise_error(ArgumentError)
end
end

context "when the heat index is NA"
end


describe "#visibility" do
it 'returns the visibility in miles' do
expect(current_conditions.visibility).to eq 10.0
end
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading