barometer 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.pelusa.yml +7 -0
- data/.travis.yml +6 -3
- data/Gemfile +11 -1
- data/README.md +89 -244
- data/Rakefile +1 -1
- data/barometer.gemspec +22 -24
- data/lib/barometer.rb +14 -65
- data/lib/barometer/base.rb +35 -65
- data/lib/barometer/data.rb +15 -20
- data/lib/barometer/data/attribute.rb +19 -0
- data/lib/barometer/data/attributes/distance.rb +11 -0
- data/lib/barometer/data/attributes/float.rb +11 -0
- data/lib/barometer/data/attributes/integer.rb +11 -0
- data/lib/barometer/data/attributes/location.rb +11 -0
- data/lib/barometer/data/attributes/pressure.rb +11 -0
- data/lib/barometer/data/attributes/sun.rb +15 -0
- data/lib/barometer/data/attributes/temperature.rb +11 -0
- data/lib/barometer/data/attributes/time.rb +11 -0
- data/lib/barometer/data/attributes/vector.rb +11 -0
- data/lib/barometer/data/attributes/zone.rb +11 -0
- data/lib/barometer/data/convertable_units.rb +145 -0
- data/lib/barometer/data/coordinates.rb +16 -0
- data/lib/barometer/data/distance.rb +14 -133
- data/lib/barometer/data/geo.rb +22 -59
- data/lib/barometer/data/location.rb +14 -20
- data/lib/barometer/data/pressure.rb +14 -135
- data/lib/barometer/data/sun.rb +24 -24
- data/lib/barometer/data/temperature.rb +14 -169
- data/lib/barometer/data/vector.rb +44 -0
- data/lib/barometer/data/zone.rb +109 -112
- data/lib/barometer/query.rb +23 -161
- data/lib/barometer/query/base.rb +88 -0
- data/lib/barometer/query/converter.rb +64 -0
- data/lib/barometer/query/converters/from_coordinates_to_noaa_station_id.rb +30 -0
- data/lib/barometer/query/converters/from_geocode_to_coordinates.rb +28 -0
- data/lib/barometer/query/converters/from_short_zipcode_to_zipcode.rb +28 -0
- data/lib/barometer/query/converters/from_weather_id_to_geocode.rb +30 -0
- data/lib/barometer/query/converters/from_woe_id_or_ipv4_to_geocode.rb +32 -0
- data/lib/barometer/query/converters/to_geocode.rb +30 -0
- data/lib/barometer/query/converters/to_weather_id.rb +30 -0
- data/lib/barometer/query/converters/to_woe_id.rb +30 -0
- data/lib/barometer/query/format.rb +59 -0
- data/lib/barometer/query/formats/base.rb +22 -0
- data/lib/barometer/query/formats/coordinates.rb +14 -0
- data/lib/barometer/query/formats/geocode.rb +15 -0
- data/lib/barometer/query/formats/icao.rb +35 -0
- data/lib/barometer/query/formats/ipv4_address.rb +19 -0
- data/lib/barometer/query/formats/noaa_station_id.rb +15 -0
- data/lib/barometer/query/formats/postalcode.rb +20 -0
- data/lib/barometer/query/formats/short_zipcode.rb +15 -0
- data/lib/barometer/{translations → query/formats/translations}/icao_country_codes.yml +0 -0
- data/lib/barometer/{translations → query/formats/translations}/weather_country_codes.yml +0 -0
- data/lib/barometer/query/formats/unknown.rb +14 -0
- data/lib/barometer/query/formats/weather_id.rb +33 -0
- data/lib/barometer/query/formats/woe_id.rb +28 -0
- data/lib/barometer/query/formats/zipcode.rb +15 -0
- data/lib/barometer/query/service.rb +13 -0
- data/lib/barometer/query/services/apis/geonames_timezone.rb +26 -0
- data/lib/barometer/query/services/apis/google_geocode.rb +35 -0
- data/lib/barometer/query/services/apis/noaa_station.rb +31 -0
- data/lib/barometer/query/services/apis/weather_id.rb +35 -0
- data/lib/barometer/query/services/apis/wunderground_timezone.rb +26 -0
- data/lib/barometer/query/services/apis/yahoo_placefinder.rb +35 -0
- data/lib/barometer/query/services/apis/yahoo_weather.rb +31 -0
- data/lib/barometer/query/services/from_weather_id.rb +64 -0
- data/lib/barometer/query/services/geonames_timezone.rb +18 -0
- data/lib/barometer/query/services/google_geocode.rb +106 -0
- data/lib/barometer/query/services/noaa_station_id.rb +28 -0
- data/lib/barometer/query/services/to_weather_id.rb +25 -0
- data/lib/barometer/query/services/to_woe_id.rb +29 -0
- data/lib/barometer/query/services/wunderground_timezone.rb +18 -0
- data/lib/barometer/query/services/yahoo_geocode.rb +69 -0
- data/lib/barometer/response.rb +12 -0
- data/lib/barometer/response/base.rb +57 -0
- data/lib/barometer/response/current.rb +27 -0
- data/lib/barometer/response/prediction.rb +41 -0
- data/lib/barometer/response/prediction_collection.rb +48 -0
- data/lib/barometer/utils.rb +17 -0
- data/lib/barometer/utils/address.rb +33 -0
- data/lib/barometer/utils/api.rb +30 -0
- data/lib/barometer/utils/config_reader.rb +40 -0
- data/lib/barometer/utils/get.rb +17 -0
- data/lib/barometer/utils/json_reader.rb +22 -0
- data/lib/barometer/utils/payload.rb +100 -0
- data/lib/barometer/utils/payload_request.rb +37 -0
- data/lib/barometer/utils/post.rb +24 -0
- data/lib/barometer/utils/time.rb +78 -0
- data/lib/barometer/{translations → utils/translations}/zone_codes.yml +0 -0
- data/lib/barometer/utils/versioned_registration.rb +70 -0
- data/lib/barometer/utils/xml_reader.rb +27 -0
- data/lib/barometer/utils/zone_code_lookup.rb +30 -0
- data/lib/barometer/version.rb +1 -1
- data/lib/barometer/weather.rb +44 -173
- data/lib/barometer/weather_service.rb +41 -0
- data/lib/barometer/weather_services/base.rb +50 -0
- data/lib/barometer/weather_services/forecast_io.rb +36 -0
- data/lib/barometer/weather_services/forecast_io/api.rb +22 -0
- data/lib/barometer/weather_services/forecast_io/query.rb +38 -0
- data/lib/barometer/weather_services/forecast_io/response.rb +31 -0
- data/lib/barometer/weather_services/forecast_io/response/current_weather.rb +78 -0
- data/lib/barometer/weather_services/forecast_io/response/forecasted_weather.rb +74 -0
- data/lib/barometer/weather_services/forecast_io/response/location.rb +19 -0
- data/lib/barometer/weather_services/forecast_io/response/timezone.rb +25 -0
- data/lib/barometer/weather_services/noaa.rb +21 -305
- data/lib/barometer/weather_services/noaa/current_api.rb +25 -0
- data/lib/barometer/weather_services/noaa/current_query.rb +30 -0
- data/lib/barometer/weather_services/noaa/current_response.rb +29 -0
- data/lib/barometer/weather_services/noaa/forecast_api.rb +25 -0
- data/lib/barometer/weather_services/noaa/forecast_query.rb +39 -0
- data/lib/barometer/weather_services/noaa/forecast_response.rb +28 -0
- data/lib/barometer/weather_services/noaa/response/current_location.rb +42 -0
- data/lib/barometer/weather_services/noaa/response/current_station.rb +46 -0
- data/lib/barometer/weather_services/noaa/response/current_weather.rb +82 -0
- data/lib/barometer/weather_services/noaa/response/forecasted_weather.rb +90 -0
- data/lib/barometer/weather_services/noaa/response/location.rb +19 -0
- data/lib/barometer/weather_services/noaa/response/timezone.rb +15 -0
- data/lib/barometer/weather_services/response.rb +9 -0
- data/lib/barometer/weather_services/response/location.rb +42 -0
- data/lib/barometer/weather_services/response/time_zone.rb +19 -0
- data/lib/barometer/weather_services/weather_bug.rb +24 -280
- data/lib/barometer/weather_services/weather_bug/current_api.rb +26 -0
- data/lib/barometer/weather_services/weather_bug/current_response.rb +33 -0
- data/lib/barometer/weather_services/weather_bug/forecast_api.rb +26 -0
- data/lib/barometer/weather_services/weather_bug/forecast_response.rb +29 -0
- data/lib/barometer/weather_services/weather_bug/query.rb +42 -0
- data/lib/barometer/weather_services/weather_bug/response/current_weather.rb +82 -0
- data/lib/barometer/weather_services/weather_bug/response/forecasted_weather.rb +67 -0
- data/lib/barometer/weather_services/weather_bug/response/location.rb +23 -0
- data/lib/barometer/weather_services/weather_bug/response/station.rb +43 -0
- data/lib/barometer/weather_services/weather_bug/response/sun.rb +32 -0
- data/lib/barometer/weather_services/weather_bug/response/time_helper.rb +52 -0
- data/lib/barometer/weather_services/weather_bug/response/timezone.rb +15 -0
- data/lib/barometer/weather_services/wunderground_v1.rb +32 -0
- data/lib/barometer/weather_services/wunderground_v1/current_api.rb +21 -0
- data/lib/barometer/weather_services/wunderground_v1/current_response.rb +31 -0
- data/lib/barometer/weather_services/wunderground_v1/forecast_api.rb +21 -0
- data/lib/barometer/weather_services/wunderground_v1/forecast_response.rb +33 -0
- data/lib/barometer/weather_services/wunderground_v1/query.rb +30 -0
- data/lib/barometer/weather_services/wunderground_v1/response/current_weather.rb +92 -0
- data/lib/barometer/weather_services/wunderground_v1/response/forecasted_weather.rb +87 -0
- data/lib/barometer/weather_services/wunderground_v1/response/full_timezone.rb +22 -0
- data/lib/barometer/weather_services/wunderground_v1/response/location.rb +43 -0
- data/lib/barometer/weather_services/wunderground_v1/response/station.rb +39 -0
- data/lib/barometer/weather_services/wunderground_v1/response/sun.rb +53 -0
- data/lib/barometer/weather_services/wunderground_v1/response/timezone.rb +15 -0
- data/lib/barometer/weather_services/yahoo.rb +16 -198
- data/lib/barometer/weather_services/yahoo/api.rb +21 -0
- data/lib/barometer/weather_services/yahoo/query.rb +42 -0
- data/lib/barometer/weather_services/yahoo/response.rb +39 -0
- data/lib/barometer/weather_services/yahoo/response/current_weather.rb +86 -0
- data/lib/barometer/weather_services/yahoo/response/forecasted_weather.rb +71 -0
- data/lib/barometer/weather_services/yahoo/response/location.rb +47 -0
- data/lib/barometer/weather_services/yahoo/response/sun.rb +43 -0
- data/lib/barometer/weather_services/yahoo/response/timezone.rb +15 -0
- data/spec/barometer_spec.rb +18 -120
- data/spec/base_spec.rb +114 -0
- data/spec/cassettes/Converter_FromCoordinatesToNoaaStationId.json +1 -0
- data/spec/cassettes/Converter_FromWeatherIdToGeocode.json +1 -0
- data/spec/cassettes/Converter_FromWoeIdOrIpv4ToGeocode.json +1 -0
- data/spec/cassettes/Converter_ToGeocode.json +1 -0
- data/spec/cassettes/Converter_ToWeatherId.json +1 -0
- data/spec/cassettes/Converter_ToWoeId.json +1 -0
- data/spec/cassettes/Service_FromWeatherId.json +1 -0
- data/spec/cassettes/Service_GoogleGeocode.json +1 -0
- data/spec/cassettes/Service_NoaaStation.json +1 -0
- data/spec/cassettes/Service_ToWeatherId.json +1 -0
- data/spec/cassettes/Service_ToWoeId.json +1 -0
- data/spec/cassettes/Service_YahooGeocode.json +1 -0
- data/spec/cassettes/WeatherService_ForecastIo.json +1 -0
- data/spec/cassettes/WeatherService_Noaa.json +1 -1
- data/spec/cassettes/WeatherService_WeatherBug.json +1 -1
- data/spec/cassettes/WeatherService_WundergroundV1.json +1 -0
- data/spec/cassettes/WeatherService_Yahoo.json +1 -1
- data/spec/data/attributes/distance_spec.rb +60 -0
- data/spec/data/attributes/location_spec.rb +41 -0
- data/spec/data/attributes/pressure_spec.rb +60 -0
- data/spec/data/attributes/sun_spec.rb +33 -0
- data/spec/data/attributes/temperature_spec.rb +60 -0
- data/spec/data/attributes/time_spec.rb +58 -0
- data/spec/data/attributes/vector_spec.rb +43 -0
- data/spec/data/attributes/zone_spec.rb +34 -0
- data/spec/data/convertable_units_spec.rb +299 -0
- data/spec/data/coordinates_spec.rb +15 -0
- data/spec/data/distance_spec.rb +49 -333
- data/spec/data/geo_spec.rb +72 -71
- data/spec/data/location_spec.rb +70 -65
- data/spec/data/pressure_spec.rb +49 -333
- data/spec/data/sun_spec.rb +57 -81
- data/spec/data/temperature_spec.rb +49 -393
- data/spec/data/vector_spec.rb +100 -0
- data/spec/data/zone_spec.rb +199 -266
- data/spec/query/base_spec.rb +296 -0
- data/spec/query/converter_spec.rb +98 -0
- data/spec/query/converters/from_coordinates_to_noaa_station_id_spec.rb +35 -0
- data/spec/query/converters/from_geocode_to_coordinates_spec.rb +25 -0
- data/spec/query/converters/from_short_zipcode_to_zipcode_spec.rb +31 -0
- data/spec/query/converters/from_weather_id_to_geocode_spec.rb +40 -0
- data/spec/query/converters/from_woe_id_or_ipv4_to_geocode_spec.rb +51 -0
- data/spec/query/converters/to_geocode_spec.rb +99 -0
- data/spec/query/converters/to_weather_id_spec.rb +35 -0
- data/spec/query/converters/to_woe_id_spec.rb +74 -0
- data/spec/query/formats/base_spec.rb +15 -0
- data/spec/query/formats/coordinates_spec.rb +13 -0
- data/spec/query/formats/geocode_spec.rb +9 -0
- data/spec/query/formats/icao_spec.rb +20 -0
- data/spec/query/formats/ipv4_address_spec.rb +33 -0
- data/spec/query/formats/noaa_station_id_spec.rb +9 -0
- data/spec/query/formats/postalcode_spec.rb +18 -0
- data/spec/query/formats/short_zipcode_spec.rb +18 -0
- data/spec/query/formats/unknown_spec.rb +9 -0
- data/spec/query/formats/weather_id_spec.rb +31 -0
- data/spec/query/formats/woe_id_spec.rb +45 -0
- data/spec/query/formats/zipcode_spec.rb +18 -0
- data/spec/query/formats_spec.rb +55 -0
- data/spec/query/services/from_weather_id_spec.rb +54 -0
- data/spec/query/services/google_geocode_spec.rb +60 -0
- data/spec/query/services/noaa_station_id_spec.rb +23 -0
- data/spec/query/services/to_weather_id_spec.rb +23 -0
- data/spec/query/services/to_woe_id_spec.rb +51 -0
- data/spec/query/services/yahoo_geocode_spec.rb +72 -0
- data/spec/response/base_spec.rb +103 -0
- data/spec/response/current_spec.rb +33 -0
- data/spec/response/predicition_spec.rb +65 -0
- data/spec/response/prediction_collection_spec.rb +97 -0
- data/spec/spec_helper.rb +14 -12
- data/spec/support/key_file_parser.rb +22 -0
- data/spec/support/matchers/formats.rb +36 -0
- data/spec/support/matchers/have_data.rb +46 -0
- data/spec/support/matchers/have_field.rb +128 -0
- data/spec/support/matchers/have_forecast.rb +46 -0
- data/spec/support/matchers/path.rb +23 -0
- data/spec/support/query_factory.rb +20 -0
- data/spec/utils/address_spec.rb +67 -0
- data/spec/utils/config_reader_spec.rb +157 -0
- data/spec/utils/get_spec.rb +22 -0
- data/spec/utils/payload_request_spec.rb +69 -0
- data/spec/utils/payload_spec.rb +168 -0
- data/spec/utils/post_spec.rb +20 -0
- data/spec/utils/time_spec.rb +93 -0
- data/spec/utils/versioned_registration_spec.rb +105 -0
- data/spec/weather_services/base_spec.rb +116 -0
- data/spec/weather_services/forecast_io_spec.rb +71 -0
- data/spec/weather_services/noaa/current_response_spec.rb +22 -0
- data/spec/weather_services/noaa/forecast_response_spec.rb +33 -0
- data/spec/weather_services/noaa_spec.rb +68 -166
- data/spec/weather_services/weather_bug/current_response_spec.rb +64 -0
- data/spec/weather_services/weather_bug/forecast_response_spec.rb +23 -0
- data/spec/weather_services/weather_bug_spec.rb +62 -202
- data/spec/weather_services/wunderground_v1/current_response_spec.rb +19 -0
- data/spec/weather_services/wunderground_v1/forecast_response_spec.rb +62 -0
- data/spec/weather_services/wunderground_v1_spec.rb +78 -0
- data/spec/weather_services/yahoo/response_spec.rb +73 -0
- data/spec/weather_services/yahoo_spec.rb +52 -135
- data/spec/weather_services_spec.rb +103 -0
- data/spec/weather_spec.rb +167 -347
- metadata +342 -123
- data/.document +0 -5
- data/TODO +0 -60
- data/bin/barometer +0 -441
- data/lib/barometer/data/local_datetime.rb +0 -145
- data/lib/barometer/data/local_time.rb +0 -134
- data/lib/barometer/data/speed.rb +0 -158
- data/lib/barometer/data/units.rb +0 -49
- data/lib/barometer/formats.rb +0 -13
- data/lib/barometer/formats/coordinates.rb +0 -57
- data/lib/barometer/formats/format.rb +0 -64
- data/lib/barometer/formats/geocode.rb +0 -60
- data/lib/barometer/formats/icao.rb +0 -37
- data/lib/barometer/formats/postalcode.rb +0 -22
- data/lib/barometer/formats/short_zipcode.rb +0 -17
- data/lib/barometer/formats/weather_id.rb +0 -92
- data/lib/barometer/formats/woe_id.rb +0 -150
- data/lib/barometer/formats/zipcode.rb +0 -31
- data/lib/barometer/key_file_parser.rb +0 -20
- data/lib/barometer/measurements/measurement.rb +0 -202
- data/lib/barometer/measurements/result.rb +0 -207
- data/lib/barometer/measurements/result_array.rb +0 -75
- data/lib/barometer/services.rb +0 -19
- data/lib/barometer/weather_services/service.rb +0 -189
- data/lib/barometer/weather_services/wunderground.rb +0 -264
- data/lib/barometer/web_services/geocode.rb +0 -34
- data/lib/barometer/web_services/noaa_station_id.rb +0 -53
- data/lib/barometer/web_services/placemaker.rb +0 -95
- data/lib/barometer/web_services/timezone.rb +0 -38
- data/lib/barometer/web_services/weather_id.rb +0 -50
- data/lib/barometer/web_services/web_service.rb +0 -29
- data/spec/cassettes/Barometer.json +0 -1
- data/spec/cassettes/Query.json +0 -1
- data/spec/cassettes/Query_Format_Coordinates.json +0 -1
- data/spec/cassettes/Query_Format_Geocode.json +0 -1
- data/spec/cassettes/Query_Format_WeatherID.json +0 -1
- data/spec/cassettes/Query_Format_WoeID.json +0 -1
- data/spec/cassettes/WeatherService.json +0 -1
- data/spec/cassettes/WeatherService_Wunderground.json +0 -1
- data/spec/cassettes/WebService_Geocode.json +0 -1
- data/spec/cassettes/WebService_NoaaStation.json +0 -1
- data/spec/data/local_datetime_spec.rb +0 -274
- data/spec/data/local_time_spec.rb +0 -239
- data/spec/data/speed_spec.rb +0 -374
- data/spec/data/units_spec.rb +0 -101
- data/spec/formats/coordinates_spec.rb +0 -166
- data/spec/formats/format_spec.rb +0 -74
- data/spec/formats/geocode_spec.rb +0 -163
- data/spec/formats/icao_spec.rb +0 -55
- data/spec/formats/postalcode_spec.rb +0 -53
- data/spec/formats/short_zipcode_spec.rb +0 -47
- data/spec/formats/weather_id_spec.rb +0 -182
- data/spec/formats/woe_id_spec.rb +0 -211
- data/spec/formats/zipcode_spec.rb +0 -103
- data/spec/key_file_parser_spec.rb +0 -28
- data/spec/measurements/measurement_spec.rb +0 -381
- data/spec/measurements/result_array_spec.rb +0 -150
- data/spec/measurements/result_spec.rb +0 -632
- data/spec/query_spec.rb +0 -498
- data/spec/weather_services/services_spec.rb +0 -135
- data/spec/weather_services/wunderground_spec.rb +0 -179
- data/spec/web_services/geocode_spec.rb +0 -31
- data/spec/web_services/noaa_station_id_spec.rb +0 -33
- data/spec/web_services/placemaker_spec.rb +0 -41
- data/spec/web_services/web_services_spec.rb +0 -20
data/spec/weather_spec.rb
CHANGED
@@ -1,440 +1,260 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
it "responds to current" do
|
16
|
-
@weather.respond_to?("current").should be_true
|
17
|
-
end
|
18
|
-
|
19
|
-
it "responds to forecast" do
|
20
|
-
@weather.respond_to?("forecast").should be_true
|
21
|
-
end
|
22
|
-
|
23
|
-
it "responds to today" do
|
24
|
-
@weather.respond_to?("today").should be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "responds to tommorrow" do
|
28
|
-
@weather.respond_to?("tomorrow").should be_true
|
29
|
-
end
|
30
|
-
|
31
|
-
it "responds to for" do
|
32
|
-
@weather.respond_to?("for").should be_true
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "with measurements" do
|
38
|
-
|
39
|
-
before(:each) do
|
40
|
-
@weather = Barometer::Weather.new
|
41
|
-
@wunderground = Barometer::Measurement.new(:wunderground)
|
42
|
-
@wunderground.stub!(:success).and_return(true)
|
43
|
-
@wunderground.stub!(:success?).and_return(true)
|
44
|
-
@yahoo = Barometer::Measurement.new(:yahoo)
|
45
|
-
@yahoo.stub!(:success).and_return(true)
|
46
|
-
@yahoo.stub!(:success?).and_return(true)
|
47
|
-
@google = Barometer::Measurement.new(:google)
|
48
|
-
@weather.measurements << @wunderground
|
49
|
-
@weather.measurements << @yahoo
|
50
|
-
@weather.measurements << @google
|
51
|
-
end
|
52
|
-
|
53
|
-
it "retrieves a source measurement" do
|
54
|
-
lambda { @weather.source(1) }.should raise_error(ArgumentError)
|
55
|
-
lambda { @weather.source("valid") }.should_not raise_error(ArgumentError)
|
56
|
-
lambda { @weather.source(:valid) }.should_not raise_error(ArgumentError)
|
57
|
-
@weather.source(:does_not_exist).should be_nil
|
58
|
-
@weather.source(:wunderground).should == @wunderground
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Barometer
|
4
|
+
describe Weather do
|
5
|
+
def fake_response(args)
|
6
|
+
success = args.delete(:success?)
|
7
|
+
weight = args.delete(:weight) || 1
|
8
|
+
|
9
|
+
double(:response,
|
10
|
+
success?: success.nil? ? true : success,
|
11
|
+
weight: weight,
|
12
|
+
current: double(:current, args)
|
13
|
+
)
|
59
14
|
end
|
60
15
|
|
61
|
-
|
62
|
-
sources = @weather.sources
|
63
|
-
sources.should_not be_nil
|
64
|
-
@wunderground.success?.should be_true
|
65
|
-
sources.include?(:wunderground).should be_true
|
66
|
-
@yahoo.success?.should be_true
|
67
|
-
sources.include?(:yahoo).should be_true
|
68
|
-
@google.success?.should be_false
|
69
|
-
sources.include?(:google).should be_false
|
70
|
-
end
|
71
|
-
|
72
|
-
it "returns the default source" do
|
73
|
-
@weather.default.should == @wunderground
|
74
|
-
end
|
16
|
+
let(:weather) { Weather.new }
|
75
17
|
|
76
|
-
|
77
|
-
|
78
|
-
describe "when calculating averages" do
|
79
|
-
|
80
|
-
before(:each) do
|
81
|
-
@weather = Barometer::Weather.new
|
82
|
-
@wunderground = Barometer::Measurement.new(:wunderground)
|
83
|
-
@wunderground.current = Barometer::Measurement::Result.new
|
84
|
-
@wunderground.stub!(:success).and_return(true)
|
85
|
-
@wunderground.stub!(:success?).and_return(true)
|
86
|
-
@yahoo = Barometer::Measurement.new(:yahoo)
|
87
|
-
@yahoo.current = Barometer::Measurement::Result.new
|
88
|
-
@yahoo.stub!(:success).and_return(true)
|
89
|
-
@yahoo.stub!(:success?).and_return(true)
|
90
|
-
@google = Barometer::Measurement.new(:google)
|
91
|
-
@weather.measurements << @wunderground
|
92
|
-
@weather.measurements << @yahoo
|
93
|
-
@weather.measurements << @google
|
18
|
+
describe ".new" do
|
19
|
+
specify { expect( weather.responses ).to be_empty }
|
94
20
|
end
|
95
21
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
@weather.temperature.c.should == 10
|
22
|
+
describe "#source" do
|
23
|
+
let(:bar_response) { double(:response, source: :bar) }
|
24
|
+
let(:foo_response) { double(:response, source: :foo) }
|
101
25
|
|
102
|
-
|
103
|
-
@weather.source(:yahoo).current.temperature.c = nil
|
26
|
+
before { weather.responses = [foo_response, bar_response] }
|
104
27
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
it "respects the measurement weight" do
|
109
|
-
@weather.source(:wunderground).current.temperature = Data::Temperature.new
|
110
|
-
@weather.source(:wunderground).current.temperature.c = 10
|
111
|
-
@weather.source(:yahoo).current.temperature = Data::Temperature.new
|
112
|
-
@weather.source(:yahoo).current.temperature.c = 4
|
113
|
-
|
114
|
-
@weather.measurements.first.weight = 2
|
115
|
-
|
116
|
-
@weather.temperature.c.should == 8
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "for temperature" do
|
120
|
-
|
121
|
-
before(:each) do
|
122
|
-
@weather.source(:wunderground).current.temperature = Data::Temperature.new
|
123
|
-
@weather.source(:wunderground).current.temperature.c = 10
|
124
|
-
@weather.source(:yahoo).current.temperature = Data::Temperature.new
|
125
|
-
@weather.source(:yahoo).current.temperature.c = 6
|
28
|
+
it "returns the response for the specified source" do
|
29
|
+
expect( weather.source(:foo) ).to eq foo_response
|
126
30
|
end
|
127
31
|
|
128
|
-
it "returns
|
129
|
-
|
32
|
+
it "returns nil when nothing is found" do
|
33
|
+
expect( weather.source(:baz) ).to be_nil
|
130
34
|
end
|
131
|
-
|
132
|
-
it "returns default when disabled" do
|
133
|
-
@weather.temperature(false).c.should == 10
|
134
|
-
end
|
135
|
-
|
136
35
|
end
|
137
36
|
|
138
|
-
describe "
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
@weather.source(:yahoo).current.wind.kph = 6
|
145
|
-
end
|
146
|
-
|
147
|
-
it "returns averages" do
|
148
|
-
@weather.wind.kph.should == 8
|
37
|
+
describe "#success?" do
|
38
|
+
it "returns true when a response is successful" do
|
39
|
+
response_one = double(:response, success?: false)
|
40
|
+
response_two = double(:response, success?: true)
|
41
|
+
weather.responses = [response_one, response_two]
|
42
|
+
expect( weather ).to be_success
|
149
43
|
end
|
150
44
|
|
151
|
-
it "returns
|
152
|
-
|
45
|
+
it "returns false when no responses are successful" do
|
46
|
+
response_one = double(:response, success?: false)
|
47
|
+
response_two = double(:response, success?: false)
|
48
|
+
weather.responses = [response_one, response_two]
|
49
|
+
expect( weather ).not_to be_success
|
153
50
|
end
|
154
|
-
|
155
51
|
end
|
156
52
|
|
157
|
-
describe "
|
53
|
+
describe "#current" do
|
54
|
+
it "returns the current response for the first successful response" do
|
55
|
+
current_two = double(:current)
|
56
|
+
response_one = double(:response, success?: false)
|
57
|
+
response_two = double(:response, success?: true, current: current_two)
|
58
|
+
weather.responses = [response_one, response_two]
|
158
59
|
|
159
|
-
|
160
|
-
@weather.source(:wunderground).current.humidity = 10
|
161
|
-
@weather.source(:yahoo).current.humidity = 6
|
60
|
+
expect( weather.current ).to eq current_two
|
162
61
|
end
|
62
|
+
end
|
163
63
|
|
164
|
-
|
165
|
-
|
166
|
-
|
64
|
+
describe "#forecast" do
|
65
|
+
it "returns the forecast response for the first successful response" do
|
66
|
+
forecast_two = double(:forecast)
|
67
|
+
response_one = double(:response, success?: false)
|
68
|
+
response_two = double(:response, success?: true, forecast: forecast_two)
|
69
|
+
weather.responses = [response_one, response_two]
|
167
70
|
|
168
|
-
|
169
|
-
@weather.humidity(false).should == 10
|
71
|
+
expect( weather.forecast ).to eq forecast_two
|
170
72
|
end
|
171
|
-
|
172
73
|
end
|
173
74
|
|
174
|
-
describe "
|
75
|
+
describe "#today" do
|
76
|
+
it "returns the first forecast response for the first successful response" do
|
77
|
+
today = double(:forecast)
|
78
|
+
tommorrow = double(:forecast)
|
79
|
+
response_one = double(:response, success?: false)
|
80
|
+
response_two = double(:response, success?: true, forecast: [today, tommorrow])
|
81
|
+
weather.responses = [response_one, response_two]
|
175
82
|
|
176
|
-
|
177
|
-
@weather.source(:wunderground).current.pressure = Data::Pressure.new
|
178
|
-
@weather.source(:wunderground).current.pressure.mb = 10
|
179
|
-
@weather.source(:yahoo).current.pressure = Data::Pressure.new
|
180
|
-
@weather.source(:yahoo).current.pressure.mb = 6
|
83
|
+
expect( weather.today ).to eq today
|
181
84
|
end
|
85
|
+
end
|
182
86
|
|
183
|
-
|
184
|
-
|
185
|
-
|
87
|
+
describe "#tomorrow" do
|
88
|
+
it "returns the second forecast response for the first successful response" do
|
89
|
+
today = double(:forecast)
|
90
|
+
tommorrow = double(:forecast)
|
91
|
+
response_one = double(:response, success?: false)
|
92
|
+
response_two = double(:response, success?: true, forecast: [today, tommorrow])
|
93
|
+
weather.responses = [response_one, response_two]
|
186
94
|
|
187
|
-
|
188
|
-
@weather.pressure(false).mb.should == 10
|
95
|
+
expect( weather.tomorrow ).to eq tommorrow
|
189
96
|
end
|
190
|
-
|
191
97
|
end
|
192
98
|
|
193
|
-
describe "for
|
99
|
+
describe "#for" do
|
100
|
+
it "delegates to the first successful response" do
|
101
|
+
response_one = double(:response, success?: false, for: nil)
|
102
|
+
response_two = double(:response, success?: true, for: nil)
|
103
|
+
weather.responses = [response_one, response_two]
|
194
104
|
|
195
|
-
|
196
|
-
|
197
|
-
@weather.source(:wunderground).current.dew_point.c = 10
|
198
|
-
@weather.source(:yahoo).current.dew_point = Data::Temperature.new
|
199
|
-
@weather.source(:yahoo).current.dew_point.c = 6
|
200
|
-
end
|
105
|
+
query = build_query
|
106
|
+
weather.for(query)
|
201
107
|
|
202
|
-
|
203
|
-
@weather.dew_point.c.should == 8
|
108
|
+
expect( response_two ).to have_received(:for).with(query)
|
204
109
|
end
|
205
|
-
|
206
|
-
it "returns default when disabled" do
|
207
|
-
@weather.dew_point(false).c.should == 10
|
208
|
-
end
|
209
|
-
|
210
110
|
end
|
211
111
|
|
212
|
-
describe "
|
112
|
+
describe "#temperature" do
|
113
|
+
let(:response_one) { fake_response(temperature: Data::Temperature.new(:metric, 20)) }
|
114
|
+
let(:response_two) { fake_response(temperature: Data::Temperature.new(:metric, 30)) }
|
213
115
|
|
214
|
-
before
|
215
|
-
@weather.source(:wunderground).current.heat_index = Data::Temperature.new
|
216
|
-
@weather.source(:wunderground).current.heat_index.c = 10
|
217
|
-
@weather.source(:yahoo).current.heat_index = Data::Temperature.new
|
218
|
-
@weather.source(:yahoo).current.heat_index.c = 6
|
219
|
-
end
|
116
|
+
before { weather.responses = [response_one, response_two] }
|
220
117
|
|
221
|
-
it "returns
|
222
|
-
|
118
|
+
it "returns an average temeprature" do
|
119
|
+
expect( weather.temperature ).to eq Data::Temperature.new(:metric, 25.0)
|
223
120
|
end
|
224
121
|
|
225
|
-
it "returns
|
226
|
-
|
122
|
+
it "returns nil when there is no valid data" do
|
123
|
+
response_one.stub(success?: false)
|
124
|
+
response_two.stub(success?: false)
|
125
|
+
expect( weather.temperature ).to be_nil
|
227
126
|
end
|
228
127
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
before(:each) do
|
234
|
-
@weather.source(:wunderground).current.wind_chill = Data::Temperature.new
|
235
|
-
@weather.source(:wunderground).current.wind_chill.c = 10
|
236
|
-
@weather.source(:yahoo).current.wind_chill = Data::Temperature.new
|
237
|
-
@weather.source(:yahoo).current.wind_chill.c = 6
|
128
|
+
it "excludes unsuccessful responses" do
|
129
|
+
response_three = fake_response(success?: false, temperature: Data::Temperature.new(:metric, 10))
|
130
|
+
weather.responses << response_three
|
131
|
+
expect( weather.temperature ).to eq Data::Temperature.new(:metric, 25.0)
|
238
132
|
end
|
239
133
|
|
240
|
-
it "
|
241
|
-
|
134
|
+
it "excludes nil values" do
|
135
|
+
response_three = fake_response(temperature: nil)
|
136
|
+
weather.responses << response_three
|
137
|
+
expect( weather.temperature ).to eq Data::Temperature.new(:metric, 25.0)
|
242
138
|
end
|
243
139
|
|
244
|
-
it "returns
|
245
|
-
|
140
|
+
it "returns a weighted average temeprature" do
|
141
|
+
response_one.stub(weight: 3)
|
142
|
+
response_two.stub(weight: 1)
|
143
|
+
expect( weather.temperature ).to eq Data::Temperature.new(:metric, 22.5)
|
246
144
|
end
|
247
145
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
before(:each) do
|
253
|
-
@weather.source(:wunderground).current.visibility = Data::Distance.new
|
254
|
-
@weather.source(:wunderground).current.visibility.km = 10
|
255
|
-
@weather.source(:yahoo).current.visibility = Data::Distance.new
|
256
|
-
@weather.source(:yahoo).current.visibility.km = 6
|
146
|
+
it "respects response units" do
|
147
|
+
response_two.current.stub(temperature: Data::Temperature.new(:imperial, 68.0))
|
148
|
+
expect( weather.temperature.to_f ).to eq 20.0
|
257
149
|
end
|
258
150
|
|
259
|
-
it "
|
260
|
-
|
261
|
-
|
151
|
+
it "respects weather units" do
|
152
|
+
weather = Weather.new(:imperial)
|
153
|
+
weather.responses = [response_one, response_two]
|
262
154
|
|
263
|
-
|
264
|
-
@weather.visibility(false).km.should == 10
|
155
|
+
expect( weather.temperature.to_f ).to eq 77.0
|
265
156
|
end
|
266
|
-
|
267
|
-
end
|
268
|
-
|
269
|
-
end
|
270
|
-
|
271
|
-
describe "when answering the simple questions," do
|
272
|
-
|
273
|
-
before(:each) do
|
274
|
-
@weather = Barometer::Weather.new
|
275
|
-
@now = Data::LocalDateTime.parse("2:05 pm")
|
276
157
|
end
|
277
158
|
|
278
|
-
describe "
|
159
|
+
describe "#humidity" do
|
160
|
+
let(:response_one) { fake_response(humidity: 20.0) }
|
161
|
+
let(:response_two) { fake_response(humidity: 30.0) }
|
279
162
|
|
280
|
-
|
281
|
-
# #lambda { @weather.windy?(1,"a") }.should raise_error(ArgumentError)
|
282
|
-
# lambda { @weather.windy?(1,@now) }.should_not raise_error(ArgumentError)
|
283
|
-
# end
|
163
|
+
before { weather.responses = [response_one, response_two] }
|
284
164
|
|
285
|
-
it "
|
286
|
-
|
287
|
-
lambda { @weather.windy?(@now,1) }.should_not raise_error(ArgumentError)
|
288
|
-
lambda { @weather.windy?(@now,1.1) }.should_not raise_error(ArgumentError)
|
165
|
+
it "returns an average humidity" do
|
166
|
+
expect( weather.humidity ).to eq 25.0
|
289
167
|
end
|
290
168
|
|
291
|
-
it "returns nil when no
|
292
|
-
|
293
|
-
|
169
|
+
it "returns nil when there is no valid data" do
|
170
|
+
response_one.stub(success?: false)
|
171
|
+
response_two.stub(success?: false)
|
172
|
+
expect( weather.humidity ).to be_nil
|
294
173
|
end
|
295
174
|
|
296
|
-
it "
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
@weather.measurements << wunderground
|
301
|
-
@weather.measurements.each { |m| m.stub!(:windy?).and_return(true) }
|
302
|
-
@weather.windy?.should be_true
|
175
|
+
it "excludes unsuccessful responses" do
|
176
|
+
response_three = fake_response(success?: false, humidity: 10.0)
|
177
|
+
weather.responses << response_three
|
178
|
+
expect( weather.humidity ).to eq 25.0
|
303
179
|
end
|
304
180
|
|
305
|
-
it "
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
@weather.measurements << wunderground
|
310
|
-
@weather.measurements.each { |m| m.stub!(:windy?).and_return(false) }
|
311
|
-
@weather.windy?.should be_false
|
181
|
+
it "excludes nil values" do
|
182
|
+
response_three = fake_response(humidity: nil)
|
183
|
+
weather.responses << response_three
|
184
|
+
expect( weather.humidity ).to eq 25.0
|
312
185
|
end
|
313
186
|
|
187
|
+
it "returns a weighted average humidity" do
|
188
|
+
response_one.stub(weight: 3)
|
189
|
+
response_two.stub(weight: 1)
|
190
|
+
expect( weather.humidity ).to eq 22.5
|
191
|
+
end
|
314
192
|
end
|
315
193
|
|
316
|
-
describe "
|
194
|
+
describe "#dew_point" do
|
195
|
+
let(:response_one) { fake_response(dew_point: Data::Temperature.new(:metric, 20)) }
|
196
|
+
let(:response_two) { fake_response(dew_point: Data::Temperature.new(:metric, 30)) }
|
317
197
|
|
318
|
-
|
319
|
-
lambda { @weather.wet?(@now,"a") }.should raise_error(ArgumentError)
|
320
|
-
lambda { @weather.wet?(@now,1) }.should_not raise_error(ArgumentError)
|
321
|
-
lambda { @weather.wet?(@now,1.1) }.should_not raise_error(ArgumentError)
|
322
|
-
end
|
323
|
-
|
324
|
-
# it "requires time as a Data::LocalTime object" do
|
325
|
-
# #lambda { @weather.wet?(1,"a") }.should raise_error(ArgumentError)
|
326
|
-
# lambda { @weather.wet?(1,@now) }.should_not raise_error(ArgumentError)
|
327
|
-
# end
|
198
|
+
before { weather.responses = [response_one, response_two] }
|
328
199
|
|
329
|
-
it "returns
|
330
|
-
|
331
|
-
@weather.wet?.should be_nil
|
200
|
+
it "returns an average dew_point" do
|
201
|
+
expect( weather.dew_point ).to eq Data::Temperature.new(:metric, 25.0)
|
332
202
|
end
|
203
|
+
end
|
333
204
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
wunderground.stub!(:success?).and_return(true)
|
338
|
-
@weather.measurements << wunderground
|
339
|
-
@weather.measurements.each { |m| m.stub!(:wet?).and_return(true) }
|
340
|
-
@weather.wet?.should be_true
|
341
|
-
end
|
205
|
+
describe "#heat_index" do
|
206
|
+
let(:response_one) { fake_response(heat_index: Data::Temperature.new(:metric, 20)) }
|
207
|
+
let(:response_two) { fake_response(heat_index: Data::Temperature.new(:metric, 30)) }
|
342
208
|
|
343
|
-
|
344
|
-
wunderground = Barometer::Measurement.new(:wunderground)
|
345
|
-
wunderground.stub!(:success).and_return(true)
|
346
|
-
wunderground.stub!(:success?).and_return(true)
|
347
|
-
@weather.measurements << wunderground
|
348
|
-
@weather.measurements.each { |m| m.stub!(:wet?).and_return(false) }
|
349
|
-
@weather.wet?.should be_false
|
350
|
-
end
|
209
|
+
before { weather.responses = [response_one, response_two] }
|
351
210
|
|
211
|
+
it "returns an average heat_index" do
|
212
|
+
expect( weather.heat_index ).to eq Data::Temperature.new(:metric, 25.0)
|
213
|
+
end
|
352
214
|
end
|
353
215
|
|
354
|
-
describe "
|
216
|
+
describe "#wind_chill" do
|
217
|
+
let(:response_one) { fake_response(wind_chill: Data::Temperature.new(:metric, 20)) }
|
218
|
+
let(:response_two) { fake_response(wind_chill: Data::Temperature.new(:metric, 30)) }
|
355
219
|
|
356
|
-
|
357
|
-
#lambda { @weather.day?("a") }.should raise_error(ArgumentError)
|
358
|
-
lambda { @weather.day?(@now) }.should_not raise_error(ArgumentError)
|
359
|
-
end
|
220
|
+
before { weather.responses = [response_one, response_two] }
|
360
221
|
|
361
|
-
it "
|
362
|
-
|
363
|
-
lambda { @weather.night?(@now) }.should_not raise_error(ArgumentError)
|
222
|
+
it "returns an average wind_chill" do
|
223
|
+
expect( weather.wind_chill ).to eq Data::Temperature.new(:metric, 25.0)
|
364
224
|
end
|
225
|
+
end
|
365
226
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
@weather.night?.should be_nil
|
370
|
-
end
|
227
|
+
describe "#pressure" do
|
228
|
+
let(:response_one) { fake_response(pressure: Data::Pressure.new(:metric, 20)) }
|
229
|
+
let(:response_two) { fake_response(pressure: Data::Pressure.new(:metric, 30)) }
|
371
230
|
|
372
|
-
|
373
|
-
wunderground = Barometer::Measurement.new(:wunderground)
|
374
|
-
wunderground.stub!(:success).and_return(true)
|
375
|
-
wunderground.stub!(:success?).and_return(true)
|
376
|
-
@weather.measurements << wunderground
|
377
|
-
@weather.measurements.each { |m| m.stub!(:day?).and_return(true) }
|
378
|
-
@weather.day?.should be_true
|
379
|
-
@weather.night?.should be_false
|
380
|
-
end
|
231
|
+
before { weather.responses = [response_one, response_two] }
|
381
232
|
|
382
|
-
it "returns
|
383
|
-
|
384
|
-
wunderground.stub!(:success).and_return(true)
|
385
|
-
wunderground.stub!(:success?).and_return(true)
|
386
|
-
@weather.measurements << wunderground
|
387
|
-
@weather.measurements.each { |m| m.stub!(:day?).and_return(false) }
|
388
|
-
@weather.day?.should be_false
|
389
|
-
@weather.night?.should be_true
|
233
|
+
it "returns an average pressure" do
|
234
|
+
expect( weather.pressure ).to eq Data::Pressure.new(:metric, 25.0)
|
390
235
|
end
|
391
|
-
|
392
236
|
end
|
393
237
|
|
394
|
-
describe "
|
238
|
+
describe "#visibility" do
|
239
|
+
let(:response_one) { fake_response(visibility: Data::Distance.new(:metric, 20)) }
|
240
|
+
let(:response_two) { fake_response(visibility: Data::Distance.new(:metric, 30)) }
|
395
241
|
|
396
|
-
|
397
|
-
#lambda { @weather.sunny?("a") }.should raise_error(ArgumentError)
|
398
|
-
lambda { @weather.sunny?(@now) }.should_not raise_error(ArgumentError)
|
399
|
-
end
|
242
|
+
before { weather.responses = [response_one, response_two] }
|
400
243
|
|
401
|
-
it "returns
|
402
|
-
|
403
|
-
@weather.sunny?.should be_nil
|
244
|
+
it "returns an average visibility" do
|
245
|
+
expect( weather.visibility ).to eq Data::Distance.new(:metric, 25.0)
|
404
246
|
end
|
247
|
+
end
|
405
248
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
wunderground.stub!(:success?).and_return(true)
|
410
|
-
@weather.measurements << wunderground
|
411
|
-
@weather.measurements.each { |m| m.stub!(:day?).and_return(true) }
|
412
|
-
@weather.measurements.each { |m| m.stub!(:sunny?).and_return(true) }
|
413
|
-
@weather.sunny?.should be_true
|
414
|
-
end
|
249
|
+
describe "#wind" do
|
250
|
+
let(:response_one) { fake_response(wind: Data::Vector.new(:metric, 20)) }
|
251
|
+
let(:response_two) { fake_response(wind: Data::Vector.new(:metric, 30)) }
|
415
252
|
|
416
|
-
|
417
|
-
wunderground = Barometer::Measurement.new(:wunderground)
|
418
|
-
wunderground.stub!(:success).and_return(true)
|
419
|
-
wunderground.stub!(:success?).and_return(true)
|
420
|
-
@weather.measurements << wunderground
|
421
|
-
@weather.measurements.each { |m| m.stub!(:day?).and_return(true) }
|
422
|
-
@weather.measurements.each { |m| m.stub!(:sunny?).and_return(false) }
|
423
|
-
@weather.sunny?.should be_false
|
424
|
-
end
|
253
|
+
before { weather.responses = [response_one, response_two] }
|
425
254
|
|
426
|
-
it "returns
|
427
|
-
|
428
|
-
wunderground.stub!(:success).and_return(true)
|
429
|
-
wunderground.stub!(:success?).and_return(true)
|
430
|
-
@weather.measurements << wunderground
|
431
|
-
@weather.measurements.each { |m| m.stub!(:sunny?).and_return(true) }
|
432
|
-
@weather.measurements.each { |m| m.stub!(:day?).and_return(false) }
|
433
|
-
@weather.sunny?.should be_false
|
255
|
+
it "returns an average wind" do
|
256
|
+
expect( weather.wind ).to eq Data::Vector.new(:metric, 25.0)
|
434
257
|
end
|
435
|
-
|
436
258
|
end
|
437
|
-
|
438
259
|
end
|
439
|
-
|
440
260
|
end
|