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/data/sun_spec.rb
CHANGED
@@ -1,102 +1,78 @@
|
|
1
|
-
|
1
|
+
require_relative '../spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module Barometer::Data
|
4
|
+
describe Sun do
|
5
|
+
let(:local_time_set) { Time.now + (60*60*8) }
|
6
|
+
let(:local_time_rise) { Time.now }
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@local_time_set = Data::LocalTime.new.parse(Time.now + (60*60*8))
|
11
|
-
end
|
12
|
-
|
13
|
-
it "responds to rise" do
|
14
|
-
@sun.respond_to?("rise").should be_true
|
15
|
-
end
|
16
|
-
|
17
|
-
it "responds to set" do
|
18
|
-
@sun.respond_to?("set").should be_true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "sets sunrise" do
|
22
|
-
sun = Data::Sun.new(@local_time_rise,@local_time_set)
|
23
|
-
sun.rise.should == @local_time_rise
|
24
|
-
end
|
25
|
-
|
26
|
-
it "sets sunset" do
|
27
|
-
sun = Data::Sun.new(@local_time_rise,@local_time_set)
|
28
|
-
sun.set.should == @local_time_set
|
29
|
-
end
|
30
|
-
|
31
|
-
it "requires Data::LocalTime for sunrise" do
|
32
|
-
lambda { Data::Sun.new("",@local_time_set) }.should raise_error(ArgumentError)
|
33
|
-
lambda { Data::Sun.new(@local_time_rise,@local_time_set) }.should_not raise_error(ArgumentError)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "requires Data::LocalTime for sunset" do
|
37
|
-
lambda { Data::Sun.new(@local_time_rise,"") }.should raise_error(ArgumentError)
|
38
|
-
lambda { Data::Sun.new(@local_time_rise,@local_time_set) }.should_not raise_error(ArgumentError)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "responds to nil?" do
|
42
|
-
@sun.nil?.should be_true
|
43
|
-
sun = Data::Sun.new(@local_time_rise, @local_time_set)
|
44
|
-
sun.nil?.should be_false
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
8
|
+
describe '#nil?' do
|
9
|
+
it 'returns true if nothing is set' do
|
10
|
+
sun = Sun.new(rise: nil, set: nil)
|
11
|
+
expect( sun ).to be_nil
|
12
|
+
end
|
48
13
|
|
49
|
-
|
14
|
+
it 'returns false if sunrise is set' do
|
15
|
+
sun = Sun.new(rise: local_time_rise, set: nil)
|
16
|
+
expect( sun ).not_to be_nil
|
17
|
+
end
|
50
18
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
@late_time = Data::LocalTime.new.parse(now + (60*60*8))
|
19
|
+
it 'returns false if sunset is set' do
|
20
|
+
sun = Sun.new(rise: nil, set: local_time_set)
|
21
|
+
expect( sun ).not_to be_nil
|
22
|
+
end
|
56
23
|
end
|
57
24
|
|
58
|
-
describe
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
25
|
+
describe 'comparisons' do
|
26
|
+
let(:now) { Time.local(2009,5,5,11,40,00) }
|
27
|
+
let(:early_time) { now - (60*60*8) }
|
28
|
+
let(:mid_time) { now }
|
29
|
+
let(:late_time) { now + (60*60*8) }
|
30
|
+
|
31
|
+
describe '#after_rise?' do
|
32
|
+
it 'returns true when after sun rise' do
|
33
|
+
sun = Sun.new(rise: early_time, set: late_time)
|
34
|
+
expect( sun.after_rise?(mid_time) ).to be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns false when before sun rise' do
|
38
|
+
sun = Sun.new(rise: mid_time, set: late_time)
|
39
|
+
expect( sun.after_rise?(early_time) ).to be_false
|
40
|
+
end
|
65
41
|
end
|
66
42
|
|
67
|
-
|
68
|
-
sun
|
69
|
-
|
70
|
-
|
43
|
+
describe '#before_set?' do
|
44
|
+
it 'returns true when before sun set' do
|
45
|
+
sun = Sun.new(rise: early_time, set: late_time)
|
46
|
+
expect( sun.before_set?(mid_time) ).to be_true
|
47
|
+
end
|
71
48
|
|
72
|
-
|
73
|
-
|
74
|
-
|
49
|
+
it 'returns false when before sun set' do
|
50
|
+
sun = Sun.new(rise: early_time, set: mid_time)
|
51
|
+
expect( sun.before_set?(late_time) ).to be_false
|
52
|
+
end
|
75
53
|
end
|
76
|
-
|
77
54
|
end
|
78
55
|
|
79
|
-
describe
|
80
|
-
|
81
|
-
|
82
|
-
sun
|
83
|
-
lambda { sun.before_set? }.should raise_error(ArgumentError)
|
84
|
-
lambda { sun.before_set?("invalid") }.should raise_error(ArgumentError)
|
85
|
-
lambda { sun.before_set?(@mid_time) }.should_not raise_error(ArgumentError)
|
56
|
+
describe '#to_s' do
|
57
|
+
it 'defaults as blank' do
|
58
|
+
sun = Sun.new()
|
59
|
+
expect( sun.to_s ).to be_blank
|
86
60
|
end
|
87
61
|
|
88
|
-
it
|
89
|
-
sun =
|
90
|
-
sun.
|
62
|
+
it 'returns the sunrise time' do
|
63
|
+
sun = Sun.new(rise: local_time_rise)
|
64
|
+
expect( sun.to_s ).to eq "rise: #{local_time_rise.strftime('%H:%M')}"
|
91
65
|
end
|
92
66
|
|
93
|
-
it
|
94
|
-
sun =
|
95
|
-
sun.
|
67
|
+
it 'returns the sunset time' do
|
68
|
+
sun = Sun.new(rise: nil, set: local_time_set)
|
69
|
+
expect( sun.to_s ).to eq "set: #{local_time_set.strftime('%H:%M')}"
|
96
70
|
end
|
97
71
|
|
72
|
+
it 'returns both times' do
|
73
|
+
sun = Sun.new(rise: local_time_rise, set: local_time_set)
|
74
|
+
expect( sun.to_s ).to eq "rise: #{local_time_rise.strftime('%H:%M')}, set: #{local_time_set.strftime('%H:%M')}"
|
75
|
+
end
|
98
76
|
end
|
99
|
-
|
100
77
|
end
|
101
|
-
|
102
78
|
end
|
@@ -1,396 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# For all conversions
|
52
|
-
# 20.0 C = 293.15 K = 68.0 F
|
53
|
-
before(:each) do
|
54
|
-
@f = 68.0
|
55
|
-
@c = 20.0
|
56
|
-
@k = 293.15
|
57
|
-
end
|
58
|
-
|
59
|
-
it "requires a value, that is either Integer or Float" do
|
60
|
-
Data::Temperature.c_to_k(nil).should be_nil
|
61
|
-
Data::Temperature.c_to_f(nil).should be_nil
|
62
|
-
Data::Temperature.f_to_k(nil).should be_nil
|
63
|
-
Data::Temperature.f_to_c(nil).should be_nil
|
64
|
-
Data::Temperature.k_to_c(nil).should be_nil
|
65
|
-
Data::Temperature.k_to_f(nil).should be_nil
|
66
|
-
|
67
|
-
not_float_or_integer = "string"
|
68
|
-
Data::Temperature.c_to_k(not_float_or_integer).should be_nil
|
69
|
-
Data::Temperature.c_to_f(not_float_or_integer).should be_nil
|
70
|
-
Data::Temperature.f_to_k(not_float_or_integer).should be_nil
|
71
|
-
Data::Temperature.f_to_c(not_float_or_integer).should be_nil
|
72
|
-
Data::Temperature.k_to_c(not_float_or_integer).should be_nil
|
73
|
-
Data::Temperature.k_to_f(not_float_or_integer).should be_nil
|
74
|
-
end
|
75
|
-
|
76
|
-
it "converts C to K" do
|
77
|
-
# 0 C = 273.15 K
|
78
|
-
Data::Temperature.c_to_k(@c).should == @k
|
79
|
-
end
|
80
|
-
|
81
|
-
it "converts C to F" do
|
82
|
-
# Tf = (9/5)*Tc+32
|
83
|
-
Data::Temperature.c_to_f(@c).should == @f
|
84
|
-
end
|
85
|
-
|
86
|
-
it "converts F to C" do
|
87
|
-
# Tc = (5/9)*(Tf-32)
|
88
|
-
Data::Temperature.f_to_c(@f).should == @c
|
89
|
-
end
|
90
|
-
|
91
|
-
it "converts F to K" do
|
92
|
-
Data::Temperature.f_to_k(@f).should == @k
|
93
|
-
end
|
94
|
-
|
95
|
-
it "converts K to C" do
|
96
|
-
Data::Temperature.k_to_c(@k).should == @c
|
97
|
-
end
|
98
|
-
|
99
|
-
it "converts K to F" do
|
100
|
-
Data::Temperature.k_to_f(@k).should == @f
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "updating" do
|
106
|
-
|
107
|
-
before(:each) do
|
108
|
-
@temp = Data::Temperature.new
|
109
|
-
@f = 68.0
|
110
|
-
@c = 20.0
|
111
|
-
end
|
112
|
-
|
113
|
-
it "nils F if new C converts to a F that changes more then 1 degree" do
|
114
|
-
@temp.fahrenheit = (@f + 1.1)
|
115
|
-
@temp.update_fahrenheit(@c)
|
116
|
-
@temp.fahrenheit.should be_nil
|
117
|
-
end
|
118
|
-
|
119
|
-
it "doesn't update F if new C converts to a F that does not change more then 1 degree" do
|
120
|
-
@temp.fahrenheit = (@f + 0.9)
|
121
|
-
@temp.update_fahrenheit(@c)
|
122
|
-
@temp.fahrenheit.should == (@f + 0.9)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "doesn't set F if not already set" do
|
126
|
-
@temp.fahrenheit.should be_nil
|
127
|
-
@temp.celsius.should be_nil
|
128
|
-
@temp.update_fahrenheit(@c)
|
129
|
-
@temp.fahrenheit.should be_nil
|
130
|
-
@temp.celsius.should be_nil
|
131
|
-
end
|
132
|
-
|
133
|
-
it "nils C if new F converts to a C that changes more then 1 degree" do
|
134
|
-
@temp.celsius = (@c + 1.1)
|
135
|
-
@temp.update_celsius(@f)
|
136
|
-
@temp.celsius.should be_nil
|
137
|
-
end
|
138
|
-
|
139
|
-
it "doesn't update C if new F converts to a C that does not change more then 1 degree" do
|
140
|
-
@temp.celsius = (@c + 0.9)
|
141
|
-
@temp.update_celsius(@f)
|
142
|
-
@temp.celsius.should == (@c + 0.9)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "doesn't set C if not already set" do
|
146
|
-
@temp.fahrenheit.should be_nil
|
147
|
-
@temp.celsius.should be_nil
|
148
|
-
@temp.update_celsius(@f)
|
149
|
-
@temp.fahrenheit.should be_nil
|
150
|
-
@temp.celsius.should be_nil
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "storing" do
|
156
|
-
|
157
|
-
before(:each) do
|
158
|
-
@temp = Data::Temperature.new
|
159
|
-
@f = 68.0
|
160
|
-
@c = 20.0
|
161
|
-
@k = 293.15
|
162
|
-
end
|
163
|
-
|
164
|
-
it "doesn't update C if nil value (or equivalent)" do
|
165
|
-
@temp.celsius.should be_nil
|
166
|
-
@temp.c = nil
|
167
|
-
@temp.celsius.should be_nil
|
168
|
-
@temp.c = "na"
|
169
|
-
@temp.celsius.should be_nil
|
170
|
-
end
|
171
|
-
|
172
|
-
it "stores C, convert to K and reset F" do
|
173
|
-
@temp.celsius.should be_nil
|
174
|
-
@temp.fahrenheit = (@f + 1.1)
|
175
|
-
@temp.kelvin.should be_nil
|
176
|
-
@temp.c = @c
|
177
|
-
@temp.celsius.should == @c
|
178
|
-
@temp.kelvin.should == @k
|
179
|
-
@temp.fahrenheit.should be_nil
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
module Barometer::Data
|
4
|
+
describe Temperature do
|
5
|
+
describe '.initialize' do
|
6
|
+
it 'sets C' do
|
7
|
+
temperature = Temperature.new(20.0, nil)
|
8
|
+
expect( temperature.c ).to eq 20.0
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'sets F' do
|
12
|
+
temperature = Temperature.new(nil, 68.0)
|
13
|
+
expect( temperature.f ).to eq 68.0
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'defaults to metric' do
|
17
|
+
temperature = Temperature.new(20)
|
18
|
+
expect( temperature ).to be_metric
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#f' do
|
23
|
+
it 'returns known value as F' do
|
24
|
+
temperature = Temperature.new(:imperial, 68)
|
25
|
+
expect( temperature.f ).to eq 68
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#c' do
|
30
|
+
it 'returns known value as C' do
|
31
|
+
temperature = Temperature.new(:metric, 20)
|
32
|
+
expect( temperature.c ).to eq 20
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#units' do
|
37
|
+
context 'when temperature is metric' do
|
38
|
+
it 'returns C' do
|
39
|
+
temperature = Temperature.new(:metric, 20.0)
|
40
|
+
expect( temperature.units ).to eq 'C'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when temperature is imperial' do
|
45
|
+
it 'returns F' do
|
46
|
+
temperature = Temperature.new(:imperial, 68.0)
|
47
|
+
expect( temperature.units ).to eq 'F'
|
48
|
+
end
|
49
|
+
end
|
180
50
|
end
|
181
|
-
|
182
|
-
it "doesn't update F if nil value (or equivalent)" do
|
183
|
-
@temp.fahrenheit.should be_nil
|
184
|
-
@temp.f = nil
|
185
|
-
@temp.fahrenheit.should be_nil
|
186
|
-
@temp.f = "na"
|
187
|
-
@temp.fahrenheit.should be_nil
|
188
|
-
end
|
189
|
-
|
190
|
-
it "stores F, convert to K and reset C" do
|
191
|
-
@temp.fahrenheit.should be_nil
|
192
|
-
@temp.celsius = (@c + 1.1)
|
193
|
-
@temp.kelvin.should be_nil
|
194
|
-
@temp.f = @f
|
195
|
-
@temp.fahrenheit.should == @f
|
196
|
-
@temp.kelvin.should == @k
|
197
|
-
@temp.celsius.should be_nil
|
198
|
-
end
|
199
|
-
|
200
|
-
it "doesn't update K if nil value (or equivalent)" do
|
201
|
-
@temp.kelvin.should be_nil
|
202
|
-
@temp.k = nil
|
203
|
-
@temp.kelvin.should be_nil
|
204
|
-
@temp.k = "na"
|
205
|
-
@temp.kelvin.should be_nil
|
206
|
-
end
|
207
|
-
|
208
|
-
it "stores K, convert to F and C" do
|
209
|
-
@temp.celsius.should be_nil
|
210
|
-
@temp.fahrenheit.should be_nil
|
211
|
-
@temp.kelvin.should be_nil
|
212
|
-
@temp.k = @k
|
213
|
-
@temp.celsius.should == @c
|
214
|
-
@temp.fahrenheit.should == @f
|
215
|
-
@temp.kelvin.should == @k
|
216
|
-
end
|
217
|
-
|
218
51
|
end
|
219
|
-
|
220
|
-
describe "retrieving" do
|
221
|
-
|
222
|
-
before(:each) do
|
223
|
-
@temp = Data::Temperature.new
|
224
|
-
@f = 68.0
|
225
|
-
@c = 20.0
|
226
|
-
@k = 293.15
|
227
|
-
end
|
228
|
-
|
229
|
-
it "returns C if it exists" do
|
230
|
-
@temp.c = @c
|
231
|
-
@temp.celsius.should == @c
|
232
|
-
@temp.c.should == @c
|
233
|
-
end
|
234
|
-
|
235
|
-
it "auto converts from K if C is nil and K exists" do
|
236
|
-
@temp.f = @f
|
237
|
-
@temp.fahrenheit.should == @f
|
238
|
-
@temp.kelvin.should == @k
|
239
|
-
@temp.celsius.should be_nil
|
240
|
-
@temp.c.should == @c
|
241
|
-
end
|
242
|
-
|
243
|
-
it "allows a float to be returned for C" do
|
244
|
-
c = 20.12
|
245
|
-
@temp.c = c
|
246
|
-
@temp.celsius.should == c
|
247
|
-
@temp.c(true).should == c.to_i
|
248
|
-
@temp.c(false).should == c.to_f
|
249
|
-
end
|
250
|
-
|
251
|
-
it "allows only 2 decimal precision for C" do
|
252
|
-
c = 20.1234
|
253
|
-
@temp.c = c
|
254
|
-
@temp.celsius.should == c
|
255
|
-
@temp.c(false).should == 20.12
|
256
|
-
end
|
257
|
-
|
258
|
-
it "returns F if it exists" do
|
259
|
-
@temp.f = @f
|
260
|
-
@temp.fahrenheit.should == @f
|
261
|
-
@temp.f.should == @f
|
262
|
-
end
|
263
|
-
|
264
|
-
it "auto converts from K if F is nil and K exists" do
|
265
|
-
@temp.c = @c
|
266
|
-
@temp.celsius.should == @c
|
267
|
-
@temp.kelvin.should == @k
|
268
|
-
@temp.fahrenheit.should be_nil
|
269
|
-
@temp.f.should == @f
|
270
|
-
end
|
271
|
-
|
272
|
-
it "allows a float to be returned for F" do
|
273
|
-
f = 68.12
|
274
|
-
@temp.f = f
|
275
|
-
@temp.fahrenheit.should == f
|
276
|
-
@temp.f(true).should == f.to_i
|
277
|
-
@temp.f(false).should == f.to_f
|
278
|
-
end
|
279
|
-
|
280
|
-
it "allows only 2 decimal precision for F" do
|
281
|
-
f = 68.1234
|
282
|
-
@temp.f = f
|
283
|
-
@temp.fahrenheit.should == f
|
284
|
-
@temp.f(false).should == 68.12
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|
288
|
-
|
289
|
-
describe "operators" do
|
290
|
-
|
291
|
-
before(:each) do
|
292
|
-
@f = 68.0
|
293
|
-
@c = 20.0
|
294
|
-
@k = 293.15
|
295
|
-
@temp_low = Data::Temperature.new
|
296
|
-
@temp_low.k = (@k - 1.0)
|
297
|
-
@temp_high = Data::Temperature.new
|
298
|
-
@temp_high.k = (@k + 1.0)
|
299
|
-
@temp = Data::Temperature.new
|
300
|
-
@temp.k = @k
|
301
|
-
@temp_same = Data::Temperature.new
|
302
|
-
@temp_same.k = @k
|
303
|
-
end
|
304
|
-
|
305
|
-
it "defines <=>" do
|
306
|
-
Data::Temperature.method_defined?("<=>").should be_true
|
307
|
-
(@temp_low <=> @temp_high).should == -1
|
308
|
-
(@temp_high <=> @temp_low).should == 1
|
309
|
-
(@temp <=> @temp_same).should == 0
|
310
|
-
end
|
311
|
-
|
312
|
-
it "defines <" do
|
313
|
-
Data::Temperature.method_defined?("<").should be_true
|
314
|
-
@temp_low.should < @temp_high
|
315
|
-
@temp_high.should_not < @temp_low
|
316
|
-
@temp.should_not < @temp_same
|
317
|
-
end
|
318
|
-
|
319
|
-
it "defines >" do
|
320
|
-
Data::Temperature.method_defined?(">").should be_true
|
321
|
-
@temp_low.should_not > @temp_high
|
322
|
-
@temp_high.should > @temp_low
|
323
|
-
@temp.should_not > @temp_same
|
324
|
-
end
|
325
|
-
|
326
|
-
it "defines ==" do
|
327
|
-
Data::Temperature.method_defined?("==").should be_true
|
328
|
-
@temp_low.should_not == @temp_high
|
329
|
-
@temp.should == @temp_same
|
330
|
-
end
|
331
|
-
|
332
|
-
it "defines <=" do
|
333
|
-
Data::Temperature.method_defined?("<=").should be_true
|
334
|
-
@temp_low.should <= @temp_high
|
335
|
-
@temp_high.should_not <= @temp_low
|
336
|
-
@temp.should <= @temp_same
|
337
|
-
end
|
338
|
-
|
339
|
-
it "defines >=" do
|
340
|
-
Data::Temperature.method_defined?(">=").should be_true
|
341
|
-
@temp_low.should_not >= @temp_high
|
342
|
-
@temp_high.should >= @temp_low
|
343
|
-
@temp.should >= @temp_same
|
344
|
-
end
|
345
|
-
|
346
|
-
end
|
347
|
-
|
348
|
-
describe "changing units" do
|
349
|
-
|
350
|
-
before(:each) do
|
351
|
-
@c = 20.5
|
352
|
-
@f = Data::Temperature.c_to_f(@c)
|
353
|
-
@k = Data::Temperature.c_to_k(@c)
|
354
|
-
@temp = Data::Temperature.new
|
355
|
-
@temp.k = @k
|
356
|
-
end
|
357
|
-
|
358
|
-
it "returns just the integer value (no units)" do
|
359
|
-
@temp.metric?.should be_true
|
360
|
-
@temp.to_i.should == @c.to_i
|
361
|
-
|
362
|
-
@temp.imperial!
|
363
|
-
@temp.metric?.should be_false
|
364
|
-
@temp.to_i.should == @f.to_i
|
365
|
-
end
|
366
|
-
|
367
|
-
it "returns just the float value (no units)" do
|
368
|
-
@temp.metric?.should be_true
|
369
|
-
@temp.to_f.should == @c.to_f
|
370
|
-
|
371
|
-
@temp.imperial!
|
372
|
-
@temp.metric?.should be_false
|
373
|
-
@temp.to_f.should == @f.to_f
|
374
|
-
end
|
375
|
-
|
376
|
-
it "returns just the integer value with units" do
|
377
|
-
@temp.metric?.should be_true
|
378
|
-
@temp.to_s.should == "#{@c.to_i} #{Data::Temperature::METRIC_UNITS}"
|
379
|
-
|
380
|
-
@temp.imperial!
|
381
|
-
@temp.metric?.should be_false
|
382
|
-
@temp.to_s.should == "#{@f.to_i} #{Data::Temperature::IMPERIAL_UNITS}"
|
383
|
-
end
|
384
|
-
|
385
|
-
it "returns just the units" do
|
386
|
-
@temp.metric?.should be_true
|
387
|
-
@temp.units.should == Data::Temperature::METRIC_UNITS
|
388
|
-
|
389
|
-
@temp.imperial!
|
390
|
-
@temp.metric?.should be_false
|
391
|
-
@temp.units.should == Data::Temperature::IMPERIAL_UNITS
|
392
|
-
end
|
393
|
-
|
394
|
-
end
|
395
|
-
|
396
52
|
end
|