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,239 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe "Data::LocalTime" do
|
4
|
-
|
5
|
-
describe "when initialized" do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@time = Data::LocalTime.new
|
9
|
-
end
|
10
|
-
|
11
|
-
it "responds to hour" do
|
12
|
-
@time.hour.should == 0
|
13
|
-
end
|
14
|
-
|
15
|
-
it "responds to min" do
|
16
|
-
@time.min.should == 0
|
17
|
-
end
|
18
|
-
|
19
|
-
it "responds to sec" do
|
20
|
-
@time.sec.should == 0
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "conversion" do
|
26
|
-
|
27
|
-
before(:each) do
|
28
|
-
@h = 12
|
29
|
-
@m = 11
|
30
|
-
@s = 10
|
31
|
-
@time = Data::LocalTime.new(@h,@m,@s)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "converts to a Time object" do
|
35
|
-
@time.is_a?(Data::LocalTime)
|
36
|
-
@time.to_t.is_a?(Time).should be_true
|
37
|
-
@time.hour.should == @h
|
38
|
-
@time.min.should == @m
|
39
|
-
@time.sec.should == @s
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "parsing" do
|
45
|
-
|
46
|
-
before(:each) do
|
47
|
-
@h = 12
|
48
|
-
@m = 11
|
49
|
-
@s = 10
|
50
|
-
@time = Data::LocalTime.new(@h,@m,@s)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "parses a Time object" do
|
54
|
-
time = Time.local(2009,1,1,@h,@m,@s)
|
55
|
-
@time.parse(time)
|
56
|
-
@time.hour.should == @h
|
57
|
-
@time.min.should == @m
|
58
|
-
@time.sec.should == @s
|
59
|
-
end
|
60
|
-
|
61
|
-
it "parses a DateTime object" do
|
62
|
-
time = DateTime.new(2009,1,1,@h,@m,@s)
|
63
|
-
@time.parse(time)
|
64
|
-
@time.hour.should == @h
|
65
|
-
@time.min.should == @m
|
66
|
-
@time.sec.should == @s
|
67
|
-
end
|
68
|
-
|
69
|
-
it "parses a String" do
|
70
|
-
time = "#{@h}:#{@m}:#{@s}"
|
71
|
-
@time.parse(time)
|
72
|
-
@time.hour.should == @h
|
73
|
-
@time.min.should == @m
|
74
|
-
@time.sec.should == @s
|
75
|
-
end
|
76
|
-
|
77
|
-
it "parses a String (using class method)" do
|
78
|
-
time = "#{@h}:#{@m}:#{@s}"
|
79
|
-
time = Data::LocalTime.parse(time)
|
80
|
-
time.hour.should == @h
|
81
|
-
time.min.should == @m
|
82
|
-
time.sec.should == @s
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "storing" do
|
88
|
-
|
89
|
-
before(:each) do
|
90
|
-
@h = 12
|
91
|
-
@m = 11
|
92
|
-
@s = 10
|
93
|
-
@time = Data::LocalTime.new(@h,@m,@s)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "requires Fixnum (accepts nil)" do
|
97
|
-
invalid_data = "s"
|
98
|
-
valid_data = 1
|
99
|
-
lambda { @time.hour = invalid_data }.should raise_error(ArgumentError)
|
100
|
-
lambda { @time.hour = valid_data }.should_not raise_error(ArgumentError)
|
101
|
-
lambda { @time.hour = nil }.should_not raise_error(ArgumentError)
|
102
|
-
lambda { @time.min = invalid_data }.should raise_error(ArgumentError)
|
103
|
-
lambda { @time.min = valid_data }.should_not raise_error(ArgumentError)
|
104
|
-
lambda { @time.min = nil }.should_not raise_error(ArgumentError)
|
105
|
-
lambda { @time.sec = invalid_data }.should raise_error(ArgumentError)
|
106
|
-
lambda { @time.sec = valid_data }.should_not raise_error(ArgumentError)
|
107
|
-
lambda { @time.sec = nil }.should_not raise_error(ArgumentError)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "rolls over seconds" do
|
111
|
-
time = Data::LocalTime.new(0,0,60)
|
112
|
-
time.sec.should == 0
|
113
|
-
time.min.should == 1
|
114
|
-
end
|
115
|
-
|
116
|
-
it "rolls over minutes" do
|
117
|
-
time = Data::LocalTime.new(0,60,0)
|
118
|
-
time.min.should == 0
|
119
|
-
time.hour.should == 1
|
120
|
-
end
|
121
|
-
|
122
|
-
it "rolls over hours" do
|
123
|
-
time = Data::LocalTime.new(24,0,0)
|
124
|
-
time.sec.should == 0
|
125
|
-
time.min.should == 0
|
126
|
-
time.hour.should == 0
|
127
|
-
end
|
128
|
-
|
129
|
-
it "rolls over everything" do
|
130
|
-
time = Data::LocalTime.new(50,600,601)
|
131
|
-
time.sec.should == 1
|
132
|
-
time.min.should == 10
|
133
|
-
time.hour.should == 12
|
134
|
-
end
|
135
|
-
|
136
|
-
it "add seconds" do
|
137
|
-
time = Data::LocalTime.new(0,0,0)
|
138
|
-
time = time + 61
|
139
|
-
time.sec.should == 1
|
140
|
-
time.min.should == 1
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
describe "retrieving" do
|
146
|
-
|
147
|
-
before(:each) do
|
148
|
-
@h = 6
|
149
|
-
@m = 30
|
150
|
-
@s = 20
|
151
|
-
@time = Data::LocalTime.new(@h,@m,@s)
|
152
|
-
end
|
153
|
-
|
154
|
-
it "returns pretty string" do
|
155
|
-
@time.to_s.should == "06:30 am"
|
156
|
-
@time.to_s(true).should == "06:30:20 am"
|
157
|
-
end
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
describe "comparators" do
|
162
|
-
|
163
|
-
before(:each) do
|
164
|
-
@time_low = Data::LocalTime.new(0,0,1)
|
165
|
-
@time_mid = Data::LocalTime.new(12,0,0)
|
166
|
-
@time_high = Data::LocalTime.new(23,59,59)
|
167
|
-
end
|
168
|
-
|
169
|
-
it "defines <=>" do
|
170
|
-
Data::LocalTime.method_defined?("<=>").should be_true
|
171
|
-
(@time_low <=> @time_high).should == -1
|
172
|
-
(@time_high <=> @time_low).should == 1
|
173
|
-
(@time_mid <=> @time_mid).should == 0
|
174
|
-
end
|
175
|
-
|
176
|
-
it "compares to a Time object" do
|
177
|
-
time = Time.local(2009,1,1,12,0,0)
|
178
|
-
(@time_low <=> time).should == -1
|
179
|
-
(@time_high <=> time).should == 1
|
180
|
-
(@time_mid <=> time).should == 0
|
181
|
-
end
|
182
|
-
|
183
|
-
it "compares to a DateTime object" do
|
184
|
-
time = DateTime.new(2009,1,1,12,0,0)
|
185
|
-
(@time_low <=> time).should == -1
|
186
|
-
(@time_high <=> time).should == 1
|
187
|
-
(@time_mid <=> time).should == 0
|
188
|
-
end
|
189
|
-
|
190
|
-
it "compares to a String object" do
|
191
|
-
time = "12:00:00"
|
192
|
-
(@time_low <=> time).should == -1
|
193
|
-
(@time_high <=> time).should == 1
|
194
|
-
(@time_mid <=> time).should == 0
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "math" do
|
200
|
-
|
201
|
-
it "counts the total seconds" do
|
202
|
-
Data::LocalTime.new(0,0,1).total_seconds.should == 1
|
203
|
-
Data::LocalTime.new(0,1,0).total_seconds.should == (1*60)
|
204
|
-
Data::LocalTime.new(1,0,0).total_seconds.should == (1*60*60)
|
205
|
-
end
|
206
|
-
|
207
|
-
it "provides a difference" do
|
208
|
-
a = Data::LocalTime.new(0,0,1)
|
209
|
-
b = Data::LocalTime.new(1,0,0)
|
210
|
-
diff = (1*60*60) - 1
|
211
|
-
a.diff(b).should == diff
|
212
|
-
b.diff(a).should == diff
|
213
|
-
end
|
214
|
-
|
215
|
-
it "adds time" do
|
216
|
-
a = Data::LocalTime.new(0,0,1)
|
217
|
-
b = Data::LocalTime.new(1,0,0)
|
218
|
-
c = (a + b)
|
219
|
-
c.is_a?(Data::LocalTime).should be_true
|
220
|
-
c.should == Data::LocalTime.new(1,0,1)
|
221
|
-
|
222
|
-
b = Data::LocalTime.new(1,0,0)
|
223
|
-
(b + 1).should == Data::LocalTime.new(1,0,1)
|
224
|
-
end
|
225
|
-
|
226
|
-
it "subtracts time" do
|
227
|
-
a = Data::LocalTime.new(0,0,1)
|
228
|
-
b = Data::LocalTime.new(1,0,0)
|
229
|
-
c = (b - a)
|
230
|
-
c.is_a?(Data::LocalTime).should be_true
|
231
|
-
c.should == Data::LocalTime.new(0,59,59)
|
232
|
-
|
233
|
-
b = Data::LocalTime.new(1,0,0)
|
234
|
-
(b - 1).should == Data::LocalTime.new(0,59,59)
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
end
|
data/spec/data/speed_spec.rb
DELETED
@@ -1,374 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe "Speed" do
|
4
|
-
|
5
|
-
describe "when initialized" do
|
6
|
-
|
7
|
-
it "defines METRIC_UNITS" do
|
8
|
-
Data::Speed.const_defined?("METRIC_UNITS").should be_true
|
9
|
-
Data::Speed::METRIC_UNITS.should == "kph"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "defines IMPERIAL_UNITS" do
|
13
|
-
Data::Speed.const_defined?("IMPERIAL_UNITS").should be_true
|
14
|
-
Data::Speed::IMPERIAL_UNITS.should == "mph"
|
15
|
-
end
|
16
|
-
|
17
|
-
before(:each) do
|
18
|
-
@speed = Data::Speed.new
|
19
|
-
end
|
20
|
-
|
21
|
-
it "responds to kilometers" do
|
22
|
-
@speed.kilometers.should be_nil
|
23
|
-
end
|
24
|
-
|
25
|
-
it "responds to miles" do
|
26
|
-
@speed.miles.should be_nil
|
27
|
-
end
|
28
|
-
|
29
|
-
it "responds to degrees" do
|
30
|
-
@speed.degrees.should be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it "responds to direction" do
|
34
|
-
@speed.direction.should be_nil
|
35
|
-
end
|
36
|
-
|
37
|
-
it "responds to metric_default" do
|
38
|
-
lambda { @speed.metric_default = 5 }.should_not raise_error(NotImplementedError)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "responds to imperial_default" do
|
42
|
-
lambda { @speed.imperial_default = 5 }.should_not raise_error(NotImplementedError)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "responds to nil?" do
|
46
|
-
@speed.nil?.should be_true
|
47
|
-
@speed.kph = 5
|
48
|
-
@speed.nil?.should be_false
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "conversion" do
|
54
|
-
|
55
|
-
# For all conversions
|
56
|
-
# 16.09 km/h = 10.0 mph
|
57
|
-
before(:each) do
|
58
|
-
@m = 10.0
|
59
|
-
@km = 16.09
|
60
|
-
end
|
61
|
-
|
62
|
-
it "requires a value, that is either Integer or Float" do
|
63
|
-
Data::Speed.km_to_m(nil).should be_nil
|
64
|
-
Data::Speed.m_to_km(nil).should be_nil
|
65
|
-
|
66
|
-
not_float_or_integer = "string"
|
67
|
-
Data::Speed.km_to_m(not_float_or_integer).should be_nil
|
68
|
-
Data::Speed.m_to_km(not_float_or_integer).should be_nil
|
69
|
-
end
|
70
|
-
|
71
|
-
it "converts km/h to mph" do
|
72
|
-
# to get equality, we need to tone down the precision
|
73
|
-
((Data::Speed.km_to_m(@km)*10).round/10.0).should == @m
|
74
|
-
end
|
75
|
-
|
76
|
-
it "converts mph to km/h" do
|
77
|
-
Data::Speed.m_to_km(@m).should == @km
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "updating" do
|
83
|
-
|
84
|
-
before(:each) do
|
85
|
-
@speed = Data::Speed.new
|
86
|
-
@m = 10.0
|
87
|
-
@km = 16.09
|
88
|
-
end
|
89
|
-
|
90
|
-
it "nils M if new KM converts to a M that changes more then 1 unit" do
|
91
|
-
@speed.miles = (@m + 1.1)
|
92
|
-
@speed.update_miles(@km)
|
93
|
-
@speed.miles.should be_nil
|
94
|
-
end
|
95
|
-
|
96
|
-
it "doesn't update M if new KM converts to a M that does not change more then 1 unit" do
|
97
|
-
@speed.miles = (@m + 0.9)
|
98
|
-
@speed.update_miles(@km)
|
99
|
-
@speed.miles.should == (@m + 0.9)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "doesn't set M if not already set" do
|
103
|
-
@speed.miles.should be_nil
|
104
|
-
@speed.kilometers.should be_nil
|
105
|
-
@speed.update_miles(@km)
|
106
|
-
@speed.miles.should be_nil
|
107
|
-
@speed.kilometers.should be_nil
|
108
|
-
end
|
109
|
-
|
110
|
-
it "nils KM if new M converts to a KM that changes more then 1 unit" do
|
111
|
-
@speed.kilometers = (@km + 1.1)
|
112
|
-
@speed.update_kilometers(@m)
|
113
|
-
@speed.kilometers.should be_nil
|
114
|
-
end
|
115
|
-
|
116
|
-
it "doesn't update KM if new M converts to a KM that does not change more then 1 unit" do
|
117
|
-
@speed.kilometers = (@km + 0.9)
|
118
|
-
@speed.update_kilometers(@m)
|
119
|
-
@speed.kilometers.should == (@km + 0.9)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "doesn't set KM if not already set" do
|
123
|
-
@speed.miles.should be_nil
|
124
|
-
@speed.kilometers.should be_nil
|
125
|
-
@speed.update_kilometers(@m)
|
126
|
-
@speed.miles.should be_nil
|
127
|
-
@speed.kilometers.should be_nil
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
describe "storing" do
|
133
|
-
|
134
|
-
before(:each) do
|
135
|
-
@speed = Data::Speed.new
|
136
|
-
@m = 10.0
|
137
|
-
@km = 16.09
|
138
|
-
end
|
139
|
-
|
140
|
-
it "doesn't update KM if nil value (or equivalent)" do
|
141
|
-
@speed.kilometers.should be_nil
|
142
|
-
@speed.kph = nil
|
143
|
-
@speed.kilometers.should be_nil
|
144
|
-
@speed.kph = "na"
|
145
|
-
@speed.kilometers.should be_nil
|
146
|
-
end
|
147
|
-
|
148
|
-
it "stores KM and resets M" do
|
149
|
-
@speed.kilometers.should be_nil
|
150
|
-
@speed.miles = (@m + 1.1)
|
151
|
-
@speed.kph = @km
|
152
|
-
@speed.kilometers.should == @km
|
153
|
-
@speed.miles.should be_nil
|
154
|
-
end
|
155
|
-
|
156
|
-
it "doesn't update M if nil value (or equivalent)" do
|
157
|
-
@speed.miles.should be_nil
|
158
|
-
@speed.mph = nil
|
159
|
-
@speed.miles.should be_nil
|
160
|
-
@speed.mph = "na"
|
161
|
-
@speed.miles.should be_nil
|
162
|
-
end
|
163
|
-
|
164
|
-
it "stores M, resets KM" do
|
165
|
-
@speed.miles.should be_nil
|
166
|
-
@speed.kilometers = (@km + 1.1)
|
167
|
-
@speed.mph = @m
|
168
|
-
@speed.miles.should == @m
|
169
|
-
@speed.kilometers.should be_nil
|
170
|
-
end
|
171
|
-
|
172
|
-
it "doesn't update direction if nil value (or equivalent)" do
|
173
|
-
@speed.direction.should be_nil
|
174
|
-
@speed.direction = nil
|
175
|
-
@speed.direction.should be_nil
|
176
|
-
@speed.direction = "na"
|
177
|
-
@speed.direction.should_not be_nil
|
178
|
-
end
|
179
|
-
|
180
|
-
it "stores direction" do
|
181
|
-
@speed.direction.should be_nil
|
182
|
-
@speed.direction = "SSW"
|
183
|
-
@speed.direction.should == "SSW"
|
184
|
-
end
|
185
|
-
|
186
|
-
it "doesn't update degrees if nil value (or equivalent)" do
|
187
|
-
@speed.degrees.should be_nil
|
188
|
-
@speed.degrees = nil
|
189
|
-
@speed.degrees.should be_nil
|
190
|
-
@speed.degrees = "na"
|
191
|
-
@speed.degrees.should be_nil
|
192
|
-
end
|
193
|
-
|
194
|
-
it "stores degrees" do
|
195
|
-
@speed.degrees.should be_nil
|
196
|
-
@speed.degrees = 90.0
|
197
|
-
@speed.degrees.should == 90.0
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
|
202
|
-
describe "retrieving" do
|
203
|
-
|
204
|
-
before(:each) do
|
205
|
-
@speed = Data::Speed.new
|
206
|
-
@m = 10.0
|
207
|
-
@km = 16.09
|
208
|
-
end
|
209
|
-
|
210
|
-
it "returns KM if it exists" do
|
211
|
-
@speed.kph = @km
|
212
|
-
@speed.kilometers.should == @km
|
213
|
-
@speed.kph(false).should == @km
|
214
|
-
end
|
215
|
-
|
216
|
-
it "auto converts from M if KM is nil and M exists" do
|
217
|
-
@speed.mph = @m
|
218
|
-
@speed.miles.should == @m
|
219
|
-
@speed.kilometers.should be_nil
|
220
|
-
@speed.kph(false).should == @km
|
221
|
-
end
|
222
|
-
|
223
|
-
it "allows a float to be returned for KM" do
|
224
|
-
km = 16.12
|
225
|
-
@speed.kph = km
|
226
|
-
@speed.kilometers.should == km
|
227
|
-
@speed.kph(true).should == km.to_i
|
228
|
-
@speed.kph(false).should == km.to_f
|
229
|
-
end
|
230
|
-
|
231
|
-
it "allows only 2 decimal precision for KM" do
|
232
|
-
km = 16.1234
|
233
|
-
@speed.kph = km
|
234
|
-
@speed.kilometers.should == km
|
235
|
-
@speed.kph(false).should == 16.12
|
236
|
-
end
|
237
|
-
|
238
|
-
it "returns M if it exists" do
|
239
|
-
@speed.mph = @m
|
240
|
-
@speed.miles.should == @m
|
241
|
-
@speed.mph.should == @m
|
242
|
-
end
|
243
|
-
|
244
|
-
it "auto converts from KM if M is nil and KM exists" do
|
245
|
-
@speed.kph = @km
|
246
|
-
@speed.kilometers.should == @km
|
247
|
-
@speed.miles.should be_nil
|
248
|
-
# to get equality, we need to tone down the precision
|
249
|
-
((@speed.mph*10).round/10.0).should == @m
|
250
|
-
end
|
251
|
-
|
252
|
-
it "allows a float to be returned for M" do
|
253
|
-
m = 10.12
|
254
|
-
@speed.mph = m
|
255
|
-
@speed.miles.should == m
|
256
|
-
@speed.mph(true).should == m.to_i
|
257
|
-
@speed.mph(false).should == m.to_f
|
258
|
-
end
|
259
|
-
|
260
|
-
it "allows only 2 decimal precision for M" do
|
261
|
-
m = 10.1234
|
262
|
-
@speed.mph = m
|
263
|
-
@speed.miles.should == m
|
264
|
-
@speed.mph(false).should == 10.12
|
265
|
-
end
|
266
|
-
|
267
|
-
end
|
268
|
-
|
269
|
-
describe "operators" do
|
270
|
-
|
271
|
-
before(:each) do
|
272
|
-
@m = 10.0
|
273
|
-
@km = 16.09
|
274
|
-
@speed_low = Data::Speed.new
|
275
|
-
@speed_low.kph = (@km - 1.0)
|
276
|
-
@speed_high = Data::Speed.new
|
277
|
-
@speed_high.kph = (@km + 1.0)
|
278
|
-
@speed = Data::Speed.new
|
279
|
-
@speed.kph = @km
|
280
|
-
@speed_same = Data::Speed.new
|
281
|
-
@speed_same.kph = @km
|
282
|
-
end
|
283
|
-
|
284
|
-
it "defines <=>" do
|
285
|
-
Data::Speed.method_defined?("<=>").should be_true
|
286
|
-
(@speed_low <=> @speed_high).should == -1
|
287
|
-
(@speed_high <=> @speed_low).should == 1
|
288
|
-
(@speed <=> @speed_same).should == 0
|
289
|
-
end
|
290
|
-
|
291
|
-
it "defines <" do
|
292
|
-
Data::Speed.method_defined?("<").should be_true
|
293
|
-
@speed_low.should < @speed_high
|
294
|
-
@speed_high.should_not < @speed_low
|
295
|
-
@speed.should_not < @speed_same
|
296
|
-
end
|
297
|
-
|
298
|
-
it "defines >" do
|
299
|
-
Data::Speed.method_defined?(">").should be_true
|
300
|
-
@speed_low.should_not > @speed_high
|
301
|
-
@speed_high.should > @speed_low
|
302
|
-
@speed.should_not > @speed_same
|
303
|
-
end
|
304
|
-
|
305
|
-
it "defines ==" do
|
306
|
-
Data::Speed.method_defined?("==").should be_true
|
307
|
-
@speed_low.should_not == @speed_high
|
308
|
-
@speed.should == @speed_same
|
309
|
-
end
|
310
|
-
|
311
|
-
it "defines <=" do
|
312
|
-
Data::Speed.method_defined?("<=").should be_true
|
313
|
-
@speed_low.should <= @speed_high
|
314
|
-
@speed_high.should_not <= @speed_low
|
315
|
-
@speed.should <= @speed_same
|
316
|
-
end
|
317
|
-
|
318
|
-
it "defines >=" do
|
319
|
-
Data::Speed.method_defined?(">=").should be_true
|
320
|
-
@speed_low.should_not >= @speed_high
|
321
|
-
@speed_high.should >= @speed_low
|
322
|
-
@speed.should >= @speed_same
|
323
|
-
end
|
324
|
-
|
325
|
-
end
|
326
|
-
|
327
|
-
describe "changing units" do
|
328
|
-
|
329
|
-
before(:each) do
|
330
|
-
@m = 10.51
|
331
|
-
@km = ((Data::Speed.m_to_km(@m)*100).round/100.0)
|
332
|
-
@speed = Data::Speed.new
|
333
|
-
@speed.mph = @m
|
334
|
-
end
|
335
|
-
|
336
|
-
it "returns just the integer value (no units)" do
|
337
|
-
@speed.metric?.should be_true
|
338
|
-
@speed.to_i.should == @km.to_i
|
339
|
-
|
340
|
-
@speed.imperial!
|
341
|
-
@speed.metric?.should be_false
|
342
|
-
@speed.to_i.should == @m.to_i
|
343
|
-
end
|
344
|
-
|
345
|
-
it "returns just the float value (no units)" do
|
346
|
-
@speed.metric?.should be_true
|
347
|
-
@speed.to_f.should == @km.to_f
|
348
|
-
|
349
|
-
@speed.imperial!
|
350
|
-
@speed.metric?.should be_false
|
351
|
-
@speed.to_f.should == @m.to_f
|
352
|
-
end
|
353
|
-
|
354
|
-
it "returns just the integer value with units" do
|
355
|
-
@speed.metric?.should be_true
|
356
|
-
@speed.to_s.should == "#{@km.to_i} #{Data::Speed::METRIC_UNITS}"
|
357
|
-
|
358
|
-
@speed.imperial!
|
359
|
-
@speed.metric?.should be_false
|
360
|
-
@speed.to_s.should == "#{@m.to_i} #{Data::Speed::IMPERIAL_UNITS}"
|
361
|
-
end
|
362
|
-
|
363
|
-
it "returns just the units" do
|
364
|
-
@speed.metric?.should be_true
|
365
|
-
@speed.units.should == Data::Speed::METRIC_UNITS
|
366
|
-
|
367
|
-
@speed.imperial!
|
368
|
-
@speed.metric?.should be_false
|
369
|
-
@speed.units.should == Data::Speed::IMPERIAL_UNITS
|
370
|
-
end
|
371
|
-
|
372
|
-
end
|
373
|
-
|
374
|
-
end
|