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
@@ -1,150 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Barometer::Measurement::ResultArray do
|
4
|
-
describe "instance methods" do
|
5
|
-
before(:each) do
|
6
|
-
@array = Barometer::Measurement::ResultArray.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "'<<'" do
|
10
|
-
it "requires Barometer::Measurement::Result" do
|
11
|
-
lambda { @array << "invalid" }.should raise_error(ArgumentError)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "adds ForecastMeasurement" do
|
15
|
-
@array.size.should == 0
|
16
|
-
forecast = Barometer::Measurement::Result.new
|
17
|
-
@array << forecast
|
18
|
-
@array.size.should == 1
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "when searching forecasts using 'for'" do
|
23
|
-
before(:each) do
|
24
|
-
1.upto(4) do |i|
|
25
|
-
forecast_measurement = Barometer::Measurement::Result.new
|
26
|
-
forecast_measurement.date = Date.parse((Time.now + (i * 60 * 60 * 24)).to_s)
|
27
|
-
@array << forecast_measurement
|
28
|
-
end
|
29
|
-
@array.size.should == 4
|
30
|
-
|
31
|
-
@tommorrow = (Time.now + (60 * 60 * 24))
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns nil when there are no forecasts" do
|
35
|
-
@array = Barometer::Measurement::ResultArray.new
|
36
|
-
@array.size.should == 0
|
37
|
-
@array.for(@tommorrow).should be_nil
|
38
|
-
end
|
39
|
-
|
40
|
-
it "finds the date using a String" do
|
41
|
-
tommorrow = @tommorrow.to_s
|
42
|
-
tommorrow.class.should == String
|
43
|
-
@array.for(tommorrow).should == @array.first
|
44
|
-
end
|
45
|
-
|
46
|
-
it "finds the date using a Date" do
|
47
|
-
tommorrow = Date.parse(@tommorrow.to_s)
|
48
|
-
tommorrow.class.should == Date
|
49
|
-
@array.for(tommorrow).should == @array.first
|
50
|
-
end
|
51
|
-
|
52
|
-
it "finds the date using a DateTime" do
|
53
|
-
tommorrow = DateTime.parse(@tommorrow.to_s)
|
54
|
-
tommorrow.class.should == DateTime
|
55
|
-
@array.for(tommorrow).should == @array.first
|
56
|
-
end
|
57
|
-
|
58
|
-
it "finds the date using a Time" do
|
59
|
-
@tommorrow.class.should == Time
|
60
|
-
@array.for(@tommorrow).should == @array.first
|
61
|
-
end
|
62
|
-
|
63
|
-
it "finds the date using Data::LocalDateTime" do
|
64
|
-
tommorrow = Data::LocalDateTime.parse(@tommorrow.to_s)
|
65
|
-
tommorrow.class.should == Data::LocalDateTime
|
66
|
-
@array.for(tommorrow).should == @array.first
|
67
|
-
end
|
68
|
-
|
69
|
-
it "finds nothing when there is not a match" do
|
70
|
-
yesterday = (Time.now - (60 * 60 * 24))
|
71
|
-
yesterday.class.should == Time
|
72
|
-
@array.for(yesterday).should be_nil
|
73
|
-
end
|
74
|
-
|
75
|
-
it "finds using '[]'" do
|
76
|
-
tommorrow = @tommorrow.to_s
|
77
|
-
tommorrow.class.should == String
|
78
|
-
@array[tommorrow].should == @array.first
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "simple questions" do
|
84
|
-
before(:each) do
|
85
|
-
@array = Barometer::Measurement::ResultArray.new
|
86
|
-
@now = Time.utc(2009,5,5,10,30,25)
|
87
|
-
|
88
|
-
@sun_icons = %w(sunny)
|
89
|
-
|
90
|
-
0.upto(1) do |i|
|
91
|
-
forecast_measurement = Barometer::Measurement::Result.new
|
92
|
-
forecast_measurement.date = Date.parse((@now + (i * 60 * 60 * 24)).to_s)
|
93
|
-
wind = Data::Speed.new
|
94
|
-
wind << (i * 5)
|
95
|
-
forecast_measurement.wind = wind
|
96
|
-
forecast_measurement.sun = Data::Sun.new(
|
97
|
-
Data::LocalTime.parse("9:00 am"), Data::LocalTime.parse("3:00 pm"))
|
98
|
-
forecast_measurement.icon = "sunny"
|
99
|
-
forecast_measurement.pop = 40
|
100
|
-
forecast_measurement.humidity = 95
|
101
|
-
@array << forecast_measurement
|
102
|
-
end
|
103
|
-
@array.size.should == 2
|
104
|
-
@tommorrow = (@now + (60 * 60 * 24))
|
105
|
-
@yesterday = (@now - (60 * 60 * 24))
|
106
|
-
@earlier = (@now - (60 * 60 * 3))
|
107
|
-
@later = (@now + (60 * 60 * 6))
|
108
|
-
end
|
109
|
-
|
110
|
-
it "answers windy?" do
|
111
|
-
@array.windy?(@tommorrow).should be_false
|
112
|
-
@array.windy?(@tommorrow,1).should be_true
|
113
|
-
@array.windy?(@yesterday).should be_nil
|
114
|
-
end
|
115
|
-
|
116
|
-
it "answers day?" do
|
117
|
-
@array.day?(@yesterday).should be_nil
|
118
|
-
@array.day?(@earlier).should be_false
|
119
|
-
@array.day?(@later).should be_false
|
120
|
-
@array.day?(@tommorrow).should be_true
|
121
|
-
@array.day?(@now).should be_true
|
122
|
-
end
|
123
|
-
|
124
|
-
it "answers sunny?" do
|
125
|
-
@array.sunny?(@tommorrow,%w(rain)).should be_false
|
126
|
-
@array.sunny?(@tommorrow,@sun_icons).should be_true
|
127
|
-
@array.sunny?(@yesterday).should be_nil
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "wet?" do
|
131
|
-
it "answers via pop" do
|
132
|
-
@array.wet?(@tommorrow).should be_false
|
133
|
-
@array.wet?(@tommorrow,nil,50).should be_false
|
134
|
-
@array.wet?(@tommorrow,nil,30).should be_true
|
135
|
-
end
|
136
|
-
|
137
|
-
it "answers via humidity" do
|
138
|
-
@array.wet?(@tommorrow).should be_false
|
139
|
-
@array.wet?(@tommorrow,nil,50,99).should be_false
|
140
|
-
@array.wet?(@tommorrow,nil,50,90).should be_true
|
141
|
-
end
|
142
|
-
|
143
|
-
it "answers via icon" do
|
144
|
-
@array.wet?(@tommorrow,%w(rain)).should be_false
|
145
|
-
# pretend that "sun" means wet
|
146
|
-
@array.wet?(@tommorrow,@sun_icons).should be_true
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
@@ -1,632 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Barometer::Measurement::Result do
|
4
|
-
describe "when initialized" do
|
5
|
-
before(:each) do
|
6
|
-
@result = Barometer::Measurement::Result.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "responds to temperature" do
|
10
|
-
@result.temperature.should be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it "responds to dew_point" do
|
14
|
-
@result.dew_point.should be_nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it "responds to heat_index" do
|
18
|
-
@result.heat_index.should be_nil
|
19
|
-
end
|
20
|
-
|
21
|
-
it "responds to wind_chill" do
|
22
|
-
@result.wind_chill.should be_nil
|
23
|
-
end
|
24
|
-
|
25
|
-
it "responds to pressure" do
|
26
|
-
@result.pressure.should be_nil
|
27
|
-
end
|
28
|
-
|
29
|
-
it "responds to visibility" do
|
30
|
-
@result.pressure.should be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it "responds to current_at" do
|
34
|
-
@result.current_at.should be_nil
|
35
|
-
end
|
36
|
-
|
37
|
-
it "responds to updated_at" do
|
38
|
-
@result.updated_at.should be_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it "responds to date" do
|
42
|
-
@result.date.should be_nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it "responds to low" do
|
46
|
-
@result.low.should be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it "responds to high" do
|
50
|
-
@result.high.should be_nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it "responds to pop" do
|
54
|
-
@result.pop.should be_nil
|
55
|
-
end
|
56
|
-
|
57
|
-
it "responds to valid_start_date" do
|
58
|
-
@result.valid_start_date.should be_nil
|
59
|
-
end
|
60
|
-
|
61
|
-
it "responds to valid_end_date" do
|
62
|
-
@result.valid_end_date.should be_nil
|
63
|
-
end
|
64
|
-
|
65
|
-
it "responds to description" do
|
66
|
-
@result.description.should be_nil
|
67
|
-
end
|
68
|
-
|
69
|
-
it "responds to humidity" do
|
70
|
-
@result.humidity.should be_nil
|
71
|
-
end
|
72
|
-
|
73
|
-
it "responds to icon" do
|
74
|
-
@result.icon.should be_nil
|
75
|
-
end
|
76
|
-
|
77
|
-
it "responds to condition" do
|
78
|
-
@result.condition.should be_nil
|
79
|
-
end
|
80
|
-
|
81
|
-
it "responds to wind" do
|
82
|
-
@result.wind.should be_nil
|
83
|
-
end
|
84
|
-
|
85
|
-
it "responds to sun" do
|
86
|
-
@result.sun.should be_nil
|
87
|
-
end
|
88
|
-
|
89
|
-
it "responds to metric" do
|
90
|
-
@result.metric.should be_true
|
91
|
-
end
|
92
|
-
|
93
|
-
it "responds to metric?" do
|
94
|
-
@result.metric?.should be_true
|
95
|
-
@result.metric = false
|
96
|
-
@result.metric?.should be_false
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "when writing data" do
|
101
|
-
before(:each) do
|
102
|
-
@result = Barometer::Measurement::Result.new
|
103
|
-
end
|
104
|
-
|
105
|
-
it "only accepts Data::Temperature for temperature" do
|
106
|
-
invalid_data = 1
|
107
|
-
invalid_data.class.should_not == Data::Temperature
|
108
|
-
lambda { @result.temperature = invalid_data }.should raise_error(ArgumentError)
|
109
|
-
|
110
|
-
valid_data = Data::Temperature.new
|
111
|
-
valid_data.class.should == Data::Temperature
|
112
|
-
lambda { @result.temperature = valid_data }.should_not raise_error(ArgumentError)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "only accepts Data::Temperature for dew_point" do
|
116
|
-
invalid_data = 1
|
117
|
-
invalid_data.class.should_not == Data::Temperature
|
118
|
-
lambda { @result.dew_point = invalid_data }.should raise_error(ArgumentError)
|
119
|
-
|
120
|
-
valid_data = Data::Temperature.new
|
121
|
-
valid_data.class.should == Data::Temperature
|
122
|
-
lambda { @result.dew_point = valid_data }.should_not raise_error(ArgumentError)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "only accepts Data::Temperature for heat_index" do
|
126
|
-
invalid_data = 1
|
127
|
-
invalid_data.class.should_not == Data::Temperature
|
128
|
-
lambda { @result.heat_index = invalid_data }.should raise_error(ArgumentError)
|
129
|
-
|
130
|
-
valid_data = Data::Temperature.new
|
131
|
-
valid_data.class.should == Data::Temperature
|
132
|
-
lambda { @result.heat_index = valid_data }.should_not raise_error(ArgumentError)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "only accepts Data::Temperature for wind_chill" do
|
136
|
-
invalid_data = 1
|
137
|
-
invalid_data.class.should_not == Data::Temperature
|
138
|
-
lambda { @result.wind_chill = invalid_data }.should raise_error(ArgumentError)
|
139
|
-
|
140
|
-
valid_data = Data::Temperature.new
|
141
|
-
valid_data.class.should == Data::Temperature
|
142
|
-
lambda { @result.wind_chill = valid_data }.should_not raise_error(ArgumentError)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "only accepts Data::Pressure for pressure" do
|
146
|
-
invalid_data = 1
|
147
|
-
invalid_data.class.should_not == Data::Pressure
|
148
|
-
lambda { @result.pressure = invalid_data }.should raise_error(ArgumentError)
|
149
|
-
|
150
|
-
valid_data = Data::Pressure.new
|
151
|
-
valid_data.class.should == Data::Pressure
|
152
|
-
lambda { @result.pressure = valid_data }.should_not raise_error(ArgumentError)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "only accepts Data::Distance for visibility" do
|
156
|
-
invalid_data = 1
|
157
|
-
invalid_data.class.should_not == Data::Distance
|
158
|
-
lambda { @result.visibility = invalid_data }.should raise_error(ArgumentError)
|
159
|
-
|
160
|
-
valid_data = Data::Distance.new
|
161
|
-
valid_data.class.should == Data::Distance
|
162
|
-
lambda { @result.visibility = valid_data }.should_not raise_error(ArgumentError)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
|
166
|
-
invalid_data = 1
|
167
|
-
invalid_data.class.should_not == Data::LocalTime
|
168
|
-
invalid_data.class.should_not == Data::LocalDateTime
|
169
|
-
lambda { @result.current_at = invalid_data }.should raise_error(ArgumentError)
|
170
|
-
|
171
|
-
valid_data = Data::LocalTime.new
|
172
|
-
valid_data.class.should == Data::LocalTime
|
173
|
-
lambda { @result.current_at = valid_data }.should_not raise_error(ArgumentError)
|
174
|
-
|
175
|
-
valid_data = Data::LocalDateTime.new(2009,1,1)
|
176
|
-
valid_data.class.should == Data::LocalDateTime
|
177
|
-
lambda { @result.current_at = valid_data }.should_not raise_error(ArgumentError)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
|
181
|
-
invalid_data = 1
|
182
|
-
invalid_data.class.should_not == Data::LocalTime
|
183
|
-
invalid_data.class.should_not == Data::LocalDateTime
|
184
|
-
lambda { @result.updated_at = invalid_data }.should raise_error(ArgumentError)
|
185
|
-
|
186
|
-
valid_data = Data::LocalTime.new
|
187
|
-
valid_data.class.should == Data::LocalTime
|
188
|
-
lambda { @result.updated_at = valid_data }.should_not raise_error(ArgumentError)
|
189
|
-
|
190
|
-
valid_data = Data::LocalDateTime.new(2009,1,1)
|
191
|
-
valid_data.class.should == Data::LocalDateTime
|
192
|
-
lambda { @result.updated_at = valid_data }.should_not raise_error(ArgumentError)
|
193
|
-
end
|
194
|
-
|
195
|
-
it "only accepts Date for date" do
|
196
|
-
invalid_data = 1
|
197
|
-
invalid_data.class.should_not == Date
|
198
|
-
lambda { @result.date = invalid_data }.should raise_error(ArgumentError)
|
199
|
-
|
200
|
-
valid_data = Date.new
|
201
|
-
valid_data.class.should == Date
|
202
|
-
lambda { @result.date = valid_data }.should_not raise_error(ArgumentError)
|
203
|
-
end
|
204
|
-
|
205
|
-
it "only accepts Data::Temperature for high" do
|
206
|
-
invalid_data = 1
|
207
|
-
invalid_data.class.should_not == Data::Temperature
|
208
|
-
lambda { @result.high = invalid_data }.should raise_error(ArgumentError)
|
209
|
-
|
210
|
-
valid_data = Data::Temperature.new
|
211
|
-
valid_data.class.should == Data::Temperature
|
212
|
-
lambda { @result.high = valid_data }.should_not raise_error(ArgumentError)
|
213
|
-
end
|
214
|
-
|
215
|
-
it "only accepts Data::Temperature for low" do
|
216
|
-
invalid_data = 1
|
217
|
-
invalid_data.class.should_not == Data::Temperature
|
218
|
-
lambda { @result.low = invalid_data }.should raise_error(ArgumentError)
|
219
|
-
|
220
|
-
valid_data = Data::Temperature.new
|
221
|
-
valid_data.class.should == Data::Temperature
|
222
|
-
lambda { @result.low = valid_data }.should_not raise_error(ArgumentError)
|
223
|
-
end
|
224
|
-
|
225
|
-
it "only accepts Fixnum for pop" do
|
226
|
-
invalid_data = "test"
|
227
|
-
invalid_data.class.should_not == Fixnum
|
228
|
-
lambda { @result.pop = invalid_data }.should raise_error(ArgumentError)
|
229
|
-
|
230
|
-
valid_data = 50
|
231
|
-
valid_data.class.should == Fixnum
|
232
|
-
lambda { @result.pop = valid_data }.should_not raise_error(ArgumentError)
|
233
|
-
end
|
234
|
-
|
235
|
-
it "only accepts Data::LocalDateTime for valid_start_date" do
|
236
|
-
invalid_data = 1
|
237
|
-
invalid_data.class.should_not == Data::LocalDateTime
|
238
|
-
lambda { @result.valid_start_date = invalid_data }.should raise_error(ArgumentError)
|
239
|
-
|
240
|
-
valid_data = Data::LocalDateTime.new(2009,1,1)
|
241
|
-
valid_data.class.should == Data::LocalDateTime
|
242
|
-
lambda { @result.valid_start_date = valid_data }.should_not raise_error(ArgumentError)
|
243
|
-
end
|
244
|
-
|
245
|
-
it "only accepts Data::LocalDateTime for valid_end_date" do
|
246
|
-
invalid_data = 1
|
247
|
-
invalid_data.class.should_not == Data::LocalDateTime
|
248
|
-
lambda { @result.valid_end_date = invalid_data }.should raise_error(ArgumentError)
|
249
|
-
|
250
|
-
valid_data = Data::LocalDateTime.new(2009,1,1)
|
251
|
-
valid_data.class.should == Data::LocalDateTime
|
252
|
-
lambda { @result.valid_end_date = valid_data }.should_not raise_error(ArgumentError)
|
253
|
-
end
|
254
|
-
|
255
|
-
it "sets valid_start_date and valid_end_date if given date" do
|
256
|
-
forecast = Barometer::Measurement::Result.new
|
257
|
-
forecast.valid_start_date.should be_nil
|
258
|
-
forecast.valid_end_date.should be_nil
|
259
|
-
date = Date.new(2009,05,05)
|
260
|
-
forecast.date = date
|
261
|
-
forecast.valid_start_date.should_not be_nil
|
262
|
-
forecast.valid_start_date.year.should == date.year
|
263
|
-
forecast.valid_start_date.month.should == date.month
|
264
|
-
forecast.valid_start_date.day.should == date.day
|
265
|
-
forecast.valid_start_date.hour.should == 0
|
266
|
-
forecast.valid_start_date.min.should == 0
|
267
|
-
forecast.valid_start_date.sec.should == 0
|
268
|
-
|
269
|
-
forecast.valid_end_date.should_not be_nil
|
270
|
-
forecast.valid_end_date.year.should == date.year
|
271
|
-
forecast.valid_end_date.month.should == date.month
|
272
|
-
forecast.valid_end_date.day.should == date.day
|
273
|
-
forecast.valid_end_date.hour.should == 23
|
274
|
-
forecast.valid_end_date.min.should == 59
|
275
|
-
forecast.valid_end_date.sec.should == 59
|
276
|
-
end
|
277
|
-
|
278
|
-
it "returns true if the valid_date range includes the given date" do
|
279
|
-
forecast = Barometer::Measurement::Result.new
|
280
|
-
forecast.date = Date.new(2009,05,05)
|
281
|
-
forecast.for_datetime?(Data::LocalDateTime.new(2009,5,5,12,0,0)).should be_true
|
282
|
-
end
|
283
|
-
|
284
|
-
it "returns false if the valid_date range excludes the given date" do
|
285
|
-
forecast = Barometer::Measurement::Result.new
|
286
|
-
forecast.date = Date.new(2009,05,05)
|
287
|
-
forecast.for_datetime?(Data::LocalDateTime.new(2009,5,4,12,0,0)).should be_false
|
288
|
-
end
|
289
|
-
|
290
|
-
it "only accepts Fixnum or Float for humidity" do
|
291
|
-
invalid_data = "invalid"
|
292
|
-
invalid_data.class.should_not == Fixnum
|
293
|
-
invalid_data.class.should_not == Float
|
294
|
-
lambda { @result.humidity = invalid_data }.should raise_error(ArgumentError)
|
295
|
-
|
296
|
-
valid_data = 1.to_i
|
297
|
-
valid_data.class.should == Fixnum
|
298
|
-
lambda { @result.humidity = valid_data }.should_not raise_error(ArgumentError)
|
299
|
-
|
300
|
-
valid_data = 1.0.to_f
|
301
|
-
valid_data.class.should == Float
|
302
|
-
lambda { @result.humidity = valid_data }.should_not raise_error(ArgumentError)
|
303
|
-
end
|
304
|
-
|
305
|
-
it "only accepts String for icon" do
|
306
|
-
invalid_data = 1
|
307
|
-
invalid_data.class.should_not == String
|
308
|
-
lambda { @result.icon = invalid_data }.should raise_error(ArgumentError)
|
309
|
-
|
310
|
-
valid_data = "valid"
|
311
|
-
valid_data.class.should == String
|
312
|
-
lambda { @result.icon = valid_data }.should_not raise_error(ArgumentError)
|
313
|
-
end
|
314
|
-
|
315
|
-
it "only accepts String for condition" do
|
316
|
-
invalid_data = 1
|
317
|
-
invalid_data.class.should_not == String
|
318
|
-
lambda { @result.condition = invalid_data }.should raise_error(ArgumentError)
|
319
|
-
|
320
|
-
valid_data = "valid"
|
321
|
-
valid_data.class.should == String
|
322
|
-
lambda { @result.condition = valid_data }.should_not raise_error(ArgumentError)
|
323
|
-
end
|
324
|
-
|
325
|
-
it "only accepts Data::Speed for wind" do
|
326
|
-
invalid_data = 1
|
327
|
-
invalid_data.class.should_not == Data::Speed
|
328
|
-
lambda { @result.wind = invalid_data }.should raise_error(ArgumentError)
|
329
|
-
|
330
|
-
valid_data = Data::Speed.new
|
331
|
-
valid_data.class.should == Data::Speed
|
332
|
-
lambda { @result.wind = valid_data }.should_not raise_error(ArgumentError)
|
333
|
-
end
|
334
|
-
|
335
|
-
it "only accepts Data::Sun for sun" do
|
336
|
-
invalid_data = 1
|
337
|
-
invalid_data.class.should_not == Data::Sun
|
338
|
-
lambda { @result.sun = invalid_data }.should raise_error(ArgumentError)
|
339
|
-
|
340
|
-
valid_data = Data::Sun.new
|
341
|
-
valid_data.class.should == Data::Sun
|
342
|
-
lambda { @result.sun = valid_data }.should_not raise_error(ArgumentError)
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
describe "method missing" do
|
347
|
-
before(:each) do
|
348
|
-
@result = Barometer::Measurement::Result.new
|
349
|
-
end
|
350
|
-
|
351
|
-
it "responds to method + ?" do
|
352
|
-
valid_method = "humidity"
|
353
|
-
@result.respond_to?(valid_method).should be_true
|
354
|
-
lambda { @result.send(valid_method + "?") }.should_not raise_error(NoMethodError)
|
355
|
-
end
|
356
|
-
|
357
|
-
it "ignores non_method + ?" do
|
358
|
-
invalid_method = "humid"
|
359
|
-
@result.respond_to?(invalid_method).should be_false
|
360
|
-
lambda { @result.send(invalid_method + "?") }.should raise_error(NoMethodError)
|
361
|
-
end
|
362
|
-
|
363
|
-
it "returns true if set" do
|
364
|
-
@result.humidity = 10
|
365
|
-
@result.humidity.should_not be_nil
|
366
|
-
@result.humidity?.should be_true
|
367
|
-
end
|
368
|
-
|
369
|
-
it "returns false if not set" do
|
370
|
-
@result.humidity.should be_nil
|
371
|
-
@result.humidity?.should be_false
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
describe "answer simple questions, like" do
|
376
|
-
before(:each) do
|
377
|
-
@result = Barometer::Measurement::Result.new
|
378
|
-
@result.temperature = Data::Temperature.new
|
379
|
-
@result.temperature << 5
|
380
|
-
@dew_point = Data::Temperature.new
|
381
|
-
@dew_point << 10
|
382
|
-
end
|
383
|
-
|
384
|
-
describe "windy?" do
|
385
|
-
before(:each) do
|
386
|
-
@wind = Data::Speed.new
|
387
|
-
@wind << 11
|
388
|
-
end
|
389
|
-
|
390
|
-
it "requires real threshold number (or nil)" do
|
391
|
-
lambda { @result.windy?("invalid") }.should raise_error(ArgumentError)
|
392
|
-
lambda { @result.windy? }.should_not raise_error(ArgumentError)
|
393
|
-
lambda { @result.windy?(10) }.should_not raise_error(ArgumentError)
|
394
|
-
end
|
395
|
-
|
396
|
-
it "returns nil when no wind" do
|
397
|
-
@result.wind?.should be_false
|
398
|
-
@result.windy?.should be_nil
|
399
|
-
@result.wind = @wind
|
400
|
-
@result.wind?.should be_true
|
401
|
-
@result.windy?.should_not be_nil
|
402
|
-
end
|
403
|
-
|
404
|
-
it "return true when current wind over threshold" do
|
405
|
-
@result.wind = @wind
|
406
|
-
@result.windy?.should be_true
|
407
|
-
@result.windy?(10).should be_true
|
408
|
-
end
|
409
|
-
|
410
|
-
it "return false when current wind under threshold" do
|
411
|
-
@result.wind = @wind
|
412
|
-
@result.windy?(15).should be_false
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
describe "day?" do
|
417
|
-
before(:each) do
|
418
|
-
@early_time = Data::LocalTime.parse("6:00 am")
|
419
|
-
@mid_time = Data::LocalTime.parse("11:00 am")
|
420
|
-
@late_time = Data::LocalTime.parse("8:00 pm")
|
421
|
-
@sun = Data::Sun.new(@early_time, @late_time)
|
422
|
-
|
423
|
-
end
|
424
|
-
|
425
|
-
it "requires Data::LocalTime object" do
|
426
|
-
@result.sun = @sun
|
427
|
-
lambda { @result.day?("invalid") }.should raise_error(ArgumentError)
|
428
|
-
lambda { @result.day? }.should raise_error(ArgumentError)
|
429
|
-
lambda { @result.day?(@mid_time) }.should_not raise_error(ArgumentError)
|
430
|
-
end
|
431
|
-
|
432
|
-
it "returns nil when no sun" do
|
433
|
-
@result.sun?.should be_false
|
434
|
-
@result.day?(@mid_time).should be_nil
|
435
|
-
@result.sun = @sun
|
436
|
-
@result.sun?.should be_true
|
437
|
-
@result.day?(@mid_time).should_not be_nil
|
438
|
-
end
|
439
|
-
|
440
|
-
it "return true when time between rise and set" do
|
441
|
-
@result.sun = @sun
|
442
|
-
@result.day?(@mid_time).should be_true
|
443
|
-
end
|
444
|
-
|
445
|
-
it "return false when time before rise or after set" do
|
446
|
-
sun = Data::Sun.new(@mid_time, @late_time)
|
447
|
-
@result.sun = sun
|
448
|
-
@result.day?(@early_time).should be_false
|
449
|
-
|
450
|
-
sun = Data::Sun.new(@early_time, @mid_time)
|
451
|
-
@result.sun = sun
|
452
|
-
@result.day?(@late_time).should be_false
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
describe "wet?" do
|
457
|
-
describe "wet_by_humidity?" do
|
458
|
-
it "requires real threshold number (or nil)" do
|
459
|
-
lambda { @result.send("_wet_by_humidity?","invalid") }.should raise_error(ArgumentError)
|
460
|
-
lambda { @result.send("_wet_by_humidity?") }.should_not raise_error(ArgumentError)
|
461
|
-
lambda { @result.send("_wet_by_humidity?",99) }.should_not raise_error(ArgumentError)
|
462
|
-
end
|
463
|
-
|
464
|
-
it "returns nil when no humidity" do
|
465
|
-
@result.humidity?.should be_false
|
466
|
-
@result.send("_wet_by_humidity?").should be_nil
|
467
|
-
@result.wet?(nil,99).should be_nil
|
468
|
-
@result.humidity = 100
|
469
|
-
@result.humidity?.should be_true
|
470
|
-
@result.send("_wet_by_humidity?").should_not be_nil
|
471
|
-
@result.wet?(nil,99).should_not be_nil
|
472
|
-
end
|
473
|
-
|
474
|
-
it "return true when current humidity over threshold" do
|
475
|
-
@result.humidity = 100
|
476
|
-
@result.send("_wet_by_humidity?").should be_true
|
477
|
-
@result.send("_wet_by_humidity?",99).should be_true
|
478
|
-
@result.wet?(nil,99).should be_true
|
479
|
-
end
|
480
|
-
|
481
|
-
it "return false when current humidity under threshold" do
|
482
|
-
@result.humidity = 98
|
483
|
-
@result.send("_wet_by_humidity?",99).should be_false
|
484
|
-
@result.wet?(nil,99).should be_false
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
describe "wet_by_icon?" do
|
489
|
-
before(:each) do
|
490
|
-
@wet_icons = %w(rain thunderstorm)
|
491
|
-
end
|
492
|
-
|
493
|
-
it "requires Array (or nil)" do
|
494
|
-
lambda { @result.send("_wet_by_icon?","invalid") }.should raise_error(ArgumentError)
|
495
|
-
lambda { @result.send("_wet_by_icon?") }.should_not raise_error(ArgumentError)
|
496
|
-
lambda { @result.send("_wet_by_icon?",@wet_icons) }.should_not raise_error(ArgumentError)
|
497
|
-
end
|
498
|
-
|
499
|
-
it "returns nil when no icon or Array" do
|
500
|
-
@result.icon?.should be_false
|
501
|
-
@result.send("_wet_by_icon?",@wet_icons).should be_nil
|
502
|
-
@result.wet?(@wet_icons).should be_nil
|
503
|
-
@result.icon = "rain"
|
504
|
-
@result.icon?.should be_true
|
505
|
-
@result.send("_wet_by_icon?").should be_nil
|
506
|
-
@result.send("_wet_by_icon?",@wet_icons).should_not be_nil
|
507
|
-
@result.wet?(@wet_icons).should_not be_nil
|
508
|
-
end
|
509
|
-
|
510
|
-
it "return true when current icon indicates wet" do
|
511
|
-
@result.icon = "rain"
|
512
|
-
@result.send("_wet_by_icon?",@wet_icons).should be_true
|
513
|
-
@result.wet?(@wet_icons).should be_true
|
514
|
-
end
|
515
|
-
|
516
|
-
it "return false when current icon does NOT indicate wet" do
|
517
|
-
@result.icon = "sun"
|
518
|
-
@result.send("_wet_by_icon?",@wet_icons).should be_false
|
519
|
-
@result.wet?(@wet_icons).should be_false
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
describe "wet_by_dewpoint?" do
|
524
|
-
it "returns nil when no dewpoint" do
|
525
|
-
@result.dew_point?.should be_false
|
526
|
-
@result.send("_wet_by_dewpoint?").should be_nil
|
527
|
-
@result.wet?.should be_nil
|
528
|
-
@result.dew_point = @dew_point
|
529
|
-
@result.dew_point?.should be_true
|
530
|
-
@result.send("_wet_by_dewpoint?").should_not be_nil
|
531
|
-
@result.wet?.should_not be_nil
|
532
|
-
end
|
533
|
-
|
534
|
-
it "return true when current dewpoint over temperature" do
|
535
|
-
@result.dew_point = @dew_point
|
536
|
-
@result.send("_wet_by_dewpoint?").should be_true
|
537
|
-
@result.wet?.should be_true
|
538
|
-
end
|
539
|
-
|
540
|
-
it "return false when current dewpoint under temperature" do
|
541
|
-
@result.temperature << 15
|
542
|
-
@result.dew_point = @dew_point
|
543
|
-
@result.send("_wet_by_dewpoint?").should be_false
|
544
|
-
@result.wet?.should be_false
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
|
-
describe "wet_by_pop?" do
|
549
|
-
it "requires real threshold number (or nil)" do
|
550
|
-
lambda { @result.send("_wet_by_pop?","invalid") }.should raise_error(ArgumentError)
|
551
|
-
lambda { @result.send("_wet_by_pop?") }.should_not raise_error(ArgumentError)
|
552
|
-
lambda { @result.send("_wet_by_pop?",50) }.should_not raise_error(ArgumentError)
|
553
|
-
end
|
554
|
-
|
555
|
-
it "returns nil when no pop" do
|
556
|
-
@result.pop?.should be_false
|
557
|
-
@result.send("_wet_by_pop?",50).should be_nil
|
558
|
-
@result.wet?.should be_nil
|
559
|
-
@result.pop = 60
|
560
|
-
@result.pop?.should be_true
|
561
|
-
@result.send("_wet_by_pop?",50).should_not be_nil
|
562
|
-
@result.wet?.should_not be_nil
|
563
|
-
end
|
564
|
-
|
565
|
-
it "return true when current pop over threshold" do
|
566
|
-
@result.pop = 60
|
567
|
-
@result.send("_wet_by_pop?",50).should be_true
|
568
|
-
@result.wet?.should be_true
|
569
|
-
end
|
570
|
-
|
571
|
-
it "return false when current pop under threshold" do
|
572
|
-
@result.pop = 40
|
573
|
-
@result.send("_wet_by_pop?",50).should be_false
|
574
|
-
@result.wet?.should be_false
|
575
|
-
end
|
576
|
-
end
|
577
|
-
end
|
578
|
-
|
579
|
-
describe "sunny?" do
|
580
|
-
describe "sunny_by_icon?" do
|
581
|
-
before(:each) do
|
582
|
-
@sunny_icons = %w(sunny clear)
|
583
|
-
@early_time = Data::LocalTime.parse("6:00 am")
|
584
|
-
@mid_time = Data::LocalTime.parse("11:00 am")
|
585
|
-
@late_time = Data::LocalTime.parse("8:00 pm")
|
586
|
-
@sun = Data::Sun.new(@early_time, @late_time)
|
587
|
-
|
588
|
-
@result.sun = @sun
|
589
|
-
end
|
590
|
-
|
591
|
-
it "requires Array (or nil)" do
|
592
|
-
lambda { @result.send("_sunny_by_icon?","invalid") }.should raise_error(ArgumentError)
|
593
|
-
lambda { @result.send("_sunny_by_icon?") }.should_not raise_error(ArgumentError)
|
594
|
-
lambda { @result.send("_sunny_by_icon?",@sunny_icons) }.should_not raise_error(ArgumentError)
|
595
|
-
end
|
596
|
-
|
597
|
-
it "returns nil when no icon or Array" do
|
598
|
-
@result.icon?.should be_false
|
599
|
-
@result.send("_sunny_by_icon?",@sunny_icons).should be_nil
|
600
|
-
@result.sunny?(@mid_time,@sunny_icons).should be_nil
|
601
|
-
@result.icon = "sunny"
|
602
|
-
@result.icon?.should be_true
|
603
|
-
@result.send("_sunny_by_icon?").should be_nil
|
604
|
-
@result.send("_sunny_by_icon?",@sunny_icons).should_not be_nil
|
605
|
-
@result.sun?(@mid_time,@sunny_icons).should_not be_nil
|
606
|
-
end
|
607
|
-
|
608
|
-
it "returns true when current icon indicates sunny" do
|
609
|
-
@result.icon = "sunny"
|
610
|
-
@result.send("_sunny_by_icon?",@sunny_icons).should be_true
|
611
|
-
@result.sunny?(@mid_time,@sunny_icons).should be_true
|
612
|
-
end
|
613
|
-
|
614
|
-
it "returns false when current icon does NOT indicate sunny" do
|
615
|
-
@result.icon = "rain"
|
616
|
-
@result.send("_sunny_by_icon?",@sunny_icons).should be_false
|
617
|
-
@result.sunny?(@mid_time,@sunny_icons).should be_false
|
618
|
-
end
|
619
|
-
|
620
|
-
it "returns false when night" do
|
621
|
-
@result.icon = "sunny"
|
622
|
-
@result.send("_sunny_by_icon?",@sunny_icons).should be_true
|
623
|
-
@result.sunny?(@mid_time,@sunny_icons).should be_true
|
624
|
-
|
625
|
-
@sun = Data::Sun.new(@mid_time, @late_time)
|
626
|
-
@result.sun = @sun
|
627
|
-
@result.sunny?(@early_time,@sunny_icons).should be_false
|
628
|
-
end
|
629
|
-
end
|
630
|
-
end
|
631
|
-
end
|
632
|
-
end
|