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/geo_spec.rb
CHANGED
@@ -1,91 +1,92 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
it "responds to latitude" do
|
16
|
-
@geo.latitude.should be_nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it "responds to longitude" do
|
20
|
-
@geo.longitude.should be_nil
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
module Barometer::Data
|
4
|
+
describe Geo do
|
5
|
+
describe '#coordinates' do
|
6
|
+
it 'joins latitude and longitude' do
|
7
|
+
geo = Geo.new(
|
8
|
+
longitude: '99.99',
|
9
|
+
latitude: '88.88'
|
10
|
+
)
|
11
|
+
expect( geo.coordinates ).to eq '88.88,99.99'
|
12
|
+
end
|
21
13
|
end
|
22
14
|
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
describe '#to_s' do
|
16
|
+
it 'defaults to an empty string' do
|
17
|
+
geo = Geo.new
|
18
|
+
expect( geo.to_s ).to be_empty
|
19
|
+
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
it 'returns only the address' do
|
22
|
+
geo = Geo.new(address: 'address')
|
23
|
+
expect( geo.to_s ).to eq 'address'
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
it 'returns address + locality' do
|
27
|
+
geo = Geo.new(
|
28
|
+
address: 'address',
|
29
|
+
locality: 'locality'
|
30
|
+
)
|
31
|
+
expect( geo.to_s ).to eq 'address, locality'
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
it 'returns address + locality + code' do
|
35
|
+
geo = Geo.new(
|
36
|
+
address: 'address',
|
37
|
+
locality: 'locality',
|
38
|
+
country_code: 'code'
|
39
|
+
)
|
40
|
+
expect( geo.to_s ).to eq 'address, locality, code'
|
41
|
+
end
|
37
42
|
end
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
describe '#merge' do
|
45
|
+
it 'returns a new Geo object' do
|
46
|
+
target_geo = Geo.new
|
47
|
+
source_geo = Geo.new
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
49
|
+
geo = target_geo.merge(source_geo)
|
50
|
+
expect( geo.object_id ).not_to eq target_geo.object_id
|
51
|
+
expect( geo.object_id ).not_to eq source_geo.object_id
|
52
|
+
end
|
48
53
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
@geo.to_s.should == "address, locality"
|
56
|
-
@geo.country_code = "code"
|
57
|
-
@geo.to_s.should == "address, locality, code"
|
58
|
-
end
|
54
|
+
it 'uses original target values' do
|
55
|
+
target_geo = Geo.new(
|
56
|
+
locality: 'foo',
|
57
|
+
postal_code: '90210'
|
58
|
+
)
|
59
|
+
source_geo = Geo.new(postal_code: '10001')
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
geo = target_geo.merge(source_geo)
|
62
|
+
expect( geo.locality ).to eq 'foo'
|
63
|
+
expect( geo.postal_code ).to eq '90210'
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
66
|
+
it 'leaves blank target values' do
|
67
|
+
target_geo = Geo.new(postal_code: '')
|
68
|
+
source_geo = Geo.new(postal_code: '10001')
|
69
69
|
|
70
|
-
|
70
|
+
geo = target_geo.merge(source_geo)
|
71
|
+
expect( geo.postal_code ).to eq ''
|
72
|
+
end
|
71
73
|
|
72
|
-
|
74
|
+
it 'updates nil target values' do
|
75
|
+
target_geo = Geo.new(country: nil)
|
76
|
+
source_geo = Geo.new(country: 'Foo Bar')
|
73
77
|
|
74
|
-
|
75
|
-
|
76
|
-
|
78
|
+
geo = target_geo.merge(source_geo)
|
79
|
+
expect( geo.country ).to eq 'Foo Bar'
|
80
|
+
end
|
77
81
|
|
78
|
-
|
82
|
+
it 'updates unset target values' do
|
83
|
+
target_geo = Geo.new
|
84
|
+
source_geo = Geo.new(latitude: 12.34, longitude: -56.78)
|
79
85
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
lambda { @geo.build_from_hash }.should_not raise_error(ArgumentError)
|
84
|
-
lambda { @geo.build_from_hash(location) }.should_not raise_error(ArgumentError)
|
86
|
+
geo = target_geo.merge(source_geo)
|
87
|
+
expect( geo.latitude ).to eq 12.34
|
88
|
+
expect( geo.longitude ).to eq -56.78
|
85
89
|
end
|
86
|
-
|
87
90
|
end
|
88
|
-
|
89
91
|
end
|
90
|
-
|
91
92
|
end
|
data/spec/data/location_spec.rb
CHANGED
@@ -1,70 +1,75 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
it "responds to name" do
|
16
|
-
@location.name.should be_nil
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
module Barometer::Data
|
4
|
+
describe Location do
|
5
|
+
describe '#coordinates' do
|
6
|
+
it 'joins longitude and latitude' do
|
7
|
+
location = Location.new(
|
8
|
+
longitude: '99.99',
|
9
|
+
latitude: '88.88'
|
10
|
+
)
|
11
|
+
expect( location.coordinates ).to eq '88.88,99.99'
|
12
|
+
end
|
17
13
|
end
|
18
14
|
|
19
|
-
|
20
|
-
|
15
|
+
describe '#to_s' do
|
16
|
+
it 'defaults to an empty string' do
|
17
|
+
location = Location.new
|
18
|
+
expect( location.to_s ).to be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns only the name' do
|
22
|
+
location = Location.new(name: 'name')
|
23
|
+
expect( location.to_s ).to eq 'name'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns name + city' do
|
27
|
+
location = Location.new(
|
28
|
+
name: 'name',
|
29
|
+
city: 'city'
|
30
|
+
)
|
31
|
+
expect( location.to_s ).to eq 'name, city'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns name + city + country_code' do
|
35
|
+
location = Location.new(
|
36
|
+
name: 'name',
|
37
|
+
city: 'city',
|
38
|
+
country_code: 'country_code'
|
39
|
+
)
|
40
|
+
expect( location.to_s ).to eq 'name, city, country_code'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns name + city + country' do
|
44
|
+
location = Location.new(
|
45
|
+
name: 'name',
|
46
|
+
city: 'city',
|
47
|
+
country_code: 'country_code',
|
48
|
+
country: 'country'
|
49
|
+
)
|
50
|
+
expect( location.to_s ).to eq 'name, city, country'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns name + city + state_code + country' do
|
54
|
+
location = Location.new(
|
55
|
+
name: 'name',
|
56
|
+
city: 'city',
|
57
|
+
country: 'country',
|
58
|
+
state_code: 'state_code'
|
59
|
+
)
|
60
|
+
expect( location.to_s ).to eq 'name, city, state_code, country'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns name + city + state_name + country' do
|
64
|
+
location = Location.new(
|
65
|
+
name: 'name',
|
66
|
+
city: 'city',
|
67
|
+
country: 'country',
|
68
|
+
state_code: 'state_code',
|
69
|
+
state_name: 'state_name'
|
70
|
+
)
|
71
|
+
expect( location.to_s ).to eq 'name, city, state_name, country'
|
72
|
+
end
|
21
73
|
end
|
22
|
-
|
23
|
-
it "responds to state_name" do
|
24
|
-
@location.state_name.should be_nil
|
25
|
-
end
|
26
|
-
|
27
|
-
it "responds to state_code" do
|
28
|
-
@location.state_code.should be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it "responds to country" do
|
32
|
-
@location.country.should be_nil
|
33
|
-
end
|
34
|
-
|
35
|
-
it "responds to country_code" do
|
36
|
-
@location.country_code.should be_nil
|
37
|
-
end
|
38
|
-
|
39
|
-
it "responds to zip_code" do
|
40
|
-
@location.zip_code.should be_nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it "responds to latitude" do
|
44
|
-
@location.latitude.should be_nil
|
45
|
-
end
|
46
|
-
|
47
|
-
it "responds to longitude" do
|
48
|
-
@location.longitude.should be_nil
|
49
|
-
end
|
50
|
-
|
51
|
-
it "responds to coordinates" do
|
52
|
-
@location.longitude = "99.99"
|
53
|
-
@location.latitude = "88.88"
|
54
|
-
@location.coordinates.should == [@location.latitude, @location.longitude].join(',')
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should print a string" do
|
58
|
-
@location = Data::Location.new
|
59
|
-
@location.to_s.should == ""
|
60
|
-
@location.name = "name"
|
61
|
-
@location.to_s.should == "name"
|
62
|
-
@location.city = "city"
|
63
|
-
@location.to_s.should == "name, city"
|
64
|
-
@location.country_code = "code"
|
65
|
-
@location.to_s.should == "name, city, code"
|
66
|
-
end
|
67
|
-
|
68
74
|
end
|
69
|
-
|
70
75
|
end
|
data/spec/data/pressure_spec.rb
CHANGED
@@ -1,336 +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
|
-
@in = 21.31
|
51
|
-
@mb = 721.64
|
52
|
-
end
|
53
|
-
|
54
|
-
it "requires a value, that is either Integer or Float" do
|
55
|
-
Data::Pressure.mb_to_in(nil).should be_nil
|
56
|
-
Data::Pressure.in_to_mb(nil).should be_nil
|
57
|
-
|
58
|
-
not_float_or_integer = "string"
|
59
|
-
Data::Pressure.mb_to_in(not_float_or_integer).should be_nil
|
60
|
-
Data::Pressure.in_to_mb(not_float_or_integer).should be_nil
|
61
|
-
end
|
62
|
-
|
63
|
-
it "converts MB to IN" do
|
64
|
-
((Data::Pressure.mb_to_in(@mb)*100).round/100.0).should == @in
|
65
|
-
end
|
66
|
-
|
67
|
-
it "converts IN to MB" do
|
68
|
-
((Data::Pressure.in_to_mb(@in)*100).round/100.0).should == @mb
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "updating" do
|
74
|
-
|
75
|
-
before(:each) do
|
76
|
-
@pressure = Data::Pressure.new
|
77
|
-
@in = 21.31
|
78
|
-
@mb = 721.64
|
79
|
-
end
|
80
|
-
|
81
|
-
it "nils IN if new MB converts to a IN that changes more then 1 unit" do
|
82
|
-
@pressure.inches = (@in + 1.1)
|
83
|
-
@pressure.update_inches(@mb)
|
84
|
-
@pressure.inches.should be_nil
|
85
|
-
end
|
86
|
-
|
87
|
-
it "doesn't update IN if new MB converts to a IN that does not change more then 1 unit" do
|
88
|
-
@pressure.inches = (@in + 0.9)
|
89
|
-
@pressure.update_inches(@mb)
|
90
|
-
@pressure.inches.should == (@in + 0.9)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "doesn't set IN if not already set" do
|
94
|
-
@pressure.inches.should be_nil
|
95
|
-
@pressure.millibars.should be_nil
|
96
|
-
@pressure.update_inches(@mb)
|
97
|
-
@pressure.inches.should be_nil
|
98
|
-
@pressure.millibars.should be_nil
|
99
|
-
end
|
100
|
-
|
101
|
-
it "nils MB if new IN converts to a MB that changes more then 1 unit" do
|
102
|
-
@pressure.millibars = (@mb + 1.1)
|
103
|
-
@pressure.update_millibars(@in)
|
104
|
-
@pressure.millibars.should be_nil
|
105
|
-
end
|
106
|
-
|
107
|
-
it "doesn't update MB if new IN converts to a MB that does not change more then 1 unit" do
|
108
|
-
@pressure.millibars = (@mb + 0.9)
|
109
|
-
@pressure.update_millibars(@in)
|
110
|
-
@pressure.millibars.should == (@mb + 0.9)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "doesn't set MB if not already set" do
|
114
|
-
@pressure.inches.should be_nil
|
115
|
-
@pressure.millibars.should be_nil
|
116
|
-
@pressure.update_millibars(@in)
|
117
|
-
@pressure.inches.should be_nil
|
118
|
-
@pressure.millibars.should be_nil
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "storing" do
|
124
|
-
|
125
|
-
before(:each) do
|
126
|
-
@pressure = Data::Pressure.new
|
127
|
-
@in = 21.31
|
128
|
-
@mb = 721.64
|
129
|
-
end
|
130
|
-
|
131
|
-
it "doesn't update MB if nil value (or equivalent)" do
|
132
|
-
@pressure.millibars.should be_nil
|
133
|
-
@pressure.mb = nil
|
134
|
-
@pressure.millibars.should be_nil
|
135
|
-
@pressure.mb = "na"
|
136
|
-
@pressure.millibars.should be_nil
|
137
|
-
end
|
138
|
-
|
139
|
-
it "stores MB and resets IN" do
|
140
|
-
@pressure.millibars.should be_nil
|
141
|
-
@pressure.inches = (@in + 1.1)
|
142
|
-
@pressure.mb = @mb
|
143
|
-
@pressure.millibars.should == @mb
|
144
|
-
@pressure.inches.should be_nil
|
145
|
-
end
|
146
|
-
|
147
|
-
it "doesn't update IN if nil value (or equivalent)" do
|
148
|
-
@pressure.inches.should be_nil
|
149
|
-
@pressure.in = nil
|
150
|
-
@pressure.inches.should be_nil
|
151
|
-
@pressure.in = "na"
|
152
|
-
@pressure.inches.should be_nil
|
153
|
-
end
|
154
|
-
|
155
|
-
it "stores IN and resets MB" do
|
156
|
-
@pressure.inches.should be_nil
|
157
|
-
@pressure.millibars = (@mb + 1.1)
|
158
|
-
@pressure.in = @in
|
159
|
-
@pressure.inches.should == @in
|
160
|
-
@pressure.millibars.should be_nil
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
describe "retrieving" do
|
166
|
-
|
167
|
-
before(:each) do
|
168
|
-
@pressure = Data::Pressure.new
|
169
|
-
@in = 21.31
|
170
|
-
@mb = 721.64
|
171
|
-
end
|
172
|
-
|
173
|
-
it "returns MB if it exists" do
|
174
|
-
@pressure.mb = @mb
|
175
|
-
@pressure.millibars.should == @mb
|
176
|
-
@pressure.mb(false).should == @mb
|
177
|
-
end
|
178
|
-
|
179
|
-
it "auto converts from IN if MB is nil and IN exists" do
|
180
|
-
@pressure.in = @in
|
181
|
-
@pressure.inches.should == @in
|
182
|
-
@pressure.millibars.should be_nil
|
183
|
-
@pressure.mb(false).should == @mb
|
184
|
-
end
|
185
|
-
|
186
|
-
it "allows a float to be returned for MB" do
|
187
|
-
mb = 721.12
|
188
|
-
@pressure.mb = mb
|
189
|
-
@pressure.millibars.should == mb
|
190
|
-
@pressure.mb(true).should == mb.to_i
|
191
|
-
@pressure.mb(false).should == mb.to_f
|
192
|
-
end
|
193
|
-
|
194
|
-
it "allows only 2 decimal precision for MB" do
|
195
|
-
mb = 721.1234
|
196
|
-
@pressure.mb = mb
|
197
|
-
@pressure.millibars.should == mb
|
198
|
-
@pressure.mb(false).should == 721.12
|
199
|
-
end
|
200
|
-
|
201
|
-
it "returns IN if it exists" do
|
202
|
-
@pressure.in = @in
|
203
|
-
@pressure.inches.should == @in
|
204
|
-
@pressure.in(false).should == @in
|
205
|
-
end
|
206
|
-
|
207
|
-
it "auto converts from MB if IN is nil and MB exists" do
|
208
|
-
@pressure.mb = @mb
|
209
|
-
@pressure.millibars.should == @mb
|
210
|
-
@pressure.inches.should be_nil
|
211
|
-
@pressure.in(false).should == @in
|
212
|
-
end
|
213
|
-
|
214
|
-
it "allows a float to be returned for IN" do
|
215
|
-
inches = 21.12
|
216
|
-
@pressure.in = inches
|
217
|
-
@pressure.inches.should == inches
|
218
|
-
@pressure.in(true).should == inches.to_i
|
219
|
-
@pressure.in(false).should == inches.to_f
|
220
|
-
end
|
221
|
-
|
222
|
-
it "allows only 2 decimal precision for IN" do
|
223
|
-
inches = 21.1234
|
224
|
-
@pressure.in = inches
|
225
|
-
@pressure.inches.should == inches
|
226
|
-
@pressure.in(false).should == 21.12
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
describe "operators" do
|
232
|
-
|
233
|
-
before(:each) do
|
234
|
-
@in = 21.31
|
235
|
-
@mb = 721.64
|
236
|
-
@pressure_low = Data::Pressure.new
|
237
|
-
@pressure_low.mb = (@mb - 1.0)
|
238
|
-
@pressure_high = Data::Pressure.new
|
239
|
-
@pressure_high.mb = (@mb + 1.0)
|
240
|
-
@pressure = Data::Pressure.new
|
241
|
-
@pressure.mb = @mb
|
242
|
-
@pressure_same = Data::Pressure.new
|
243
|
-
@pressure_same.mb = @mb
|
244
|
-
end
|
245
|
-
|
246
|
-
it "defines <=>" do
|
247
|
-
Data::Pressure.method_defined?("<=>").should be_true
|
248
|
-
(@pressure_low <=> @pressure_high).should == -1
|
249
|
-
(@pressure_high <=> @pressure_low).should == 1
|
250
|
-
(@pressure <=> @pressure_same).should == 0
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
module Barometer::Data
|
4
|
+
describe Pressure do
|
5
|
+
describe '.initialize' do
|
6
|
+
it 'sets mb' do
|
7
|
+
distance = Pressure.new(721.64, nil)
|
8
|
+
expect( distance.mb ).to eq 721.64
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'sets in' do
|
12
|
+
distance = Pressure.new(nil, 21.31)
|
13
|
+
expect( distance.in ).to eq 21.31
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'defaults to metric' do
|
17
|
+
distance = Pressure.new(721.64)
|
18
|
+
expect( distance ).to be_metric
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#in' do
|
23
|
+
it 'returns known value as in' do
|
24
|
+
distance = Pressure.new(:imperial, 21)
|
25
|
+
expect( distance.in ).to eq 21
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#mb' do
|
30
|
+
it 'returns known value as mb' do
|
31
|
+
distance = Pressure.new(:metric, 721)
|
32
|
+
expect( distance.mb ).to eq 721
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#units' do
|
37
|
+
context 'when distance is metric' do
|
38
|
+
it 'returns mb' do
|
39
|
+
distance = Pressure.new(:metric, 721.0, 21.0)
|
40
|
+
expect( distance.units ).to eq 'mb'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when distance is imperial' do
|
45
|
+
it 'returns in' do
|
46
|
+
distance = Pressure.new(:imperial, 721.0, 21.0)
|
47
|
+
expect( distance.units ).to eq 'in'
|
48
|
+
end
|
49
|
+
end
|
251
50
|
end
|
252
|
-
|
253
|
-
it "defines <" do
|
254
|
-
Data::Pressure.method_defined?("<").should be_true
|
255
|
-
@pressure_low.should < @pressure_high
|
256
|
-
@pressure_high.should_not < @pressure_low
|
257
|
-
@pressure.should_not < @pressure_same
|
258
|
-
end
|
259
|
-
|
260
|
-
it "defines >" do
|
261
|
-
Data::Pressure.method_defined?(">").should be_true
|
262
|
-
@pressure_low.should_not > @pressure_high
|
263
|
-
@pressure_high.should > @pressure_low
|
264
|
-
@pressure.should_not > @pressure_same
|
265
|
-
end
|
266
|
-
|
267
|
-
it "defines ==" do
|
268
|
-
Data::Pressure.method_defined?("==").should be_true
|
269
|
-
@pressure_low.should_not == @pressure_high
|
270
|
-
@pressure.should == @pressure_same
|
271
|
-
end
|
272
|
-
|
273
|
-
it "defines <=" do
|
274
|
-
Data::Pressure.method_defined?("<=").should be_true
|
275
|
-
@pressure_low.should <= @pressure_high
|
276
|
-
@pressure_high.should_not <= @pressure_low
|
277
|
-
@pressure.should <= @pressure_same
|
278
|
-
end
|
279
|
-
|
280
|
-
it "defines >=" do
|
281
|
-
Data::Pressure.method_defined?(">=").should be_true
|
282
|
-
@pressure_low.should_not >= @pressure_high
|
283
|
-
@pressure_high.should >= @pressure_low
|
284
|
-
@pressure.should >= @pressure_same
|
285
|
-
end
|
286
|
-
|
287
51
|
end
|
288
|
-
|
289
|
-
describe "changing units" do
|
290
|
-
|
291
|
-
before(:each) do
|
292
|
-
@in = 21.31
|
293
|
-
@mb = 721.64
|
294
|
-
@pressure = Data::Pressure.new
|
295
|
-
@pressure.mb = @mb
|
296
|
-
end
|
297
|
-
|
298
|
-
it "returns just the integer value (no units)" do
|
299
|
-
@pressure.metric?.should be_true
|
300
|
-
@pressure.to_i.should == @mb.to_i
|
301
|
-
|
302
|
-
@pressure.imperial!
|
303
|
-
@pressure.metric?.should be_false
|
304
|
-
@pressure.to_i.should == @in.to_i
|
305
|
-
end
|
306
|
-
|
307
|
-
it "returns just the float value (no units)" do
|
308
|
-
@pressure.metric?.should be_true
|
309
|
-
@pressure.to_f.should == @mb.to_f
|
310
|
-
|
311
|
-
@pressure.imperial!
|
312
|
-
@pressure.metric?.should be_false
|
313
|
-
@pressure.to_f.should == @in.to_f
|
314
|
-
end
|
315
|
-
|
316
|
-
it "returns just the integer value with units" do
|
317
|
-
@pressure.metric?.should be_true
|
318
|
-
@pressure.to_s.should == "#{@mb.to_i} #{Data::Pressure::METRIC_UNITS}"
|
319
|
-
|
320
|
-
@pressure.imperial!
|
321
|
-
@pressure.metric?.should be_false
|
322
|
-
@pressure.to_s.should == "#{@in.to_i} #{Data::Pressure::IMPERIAL_UNITS}"
|
323
|
-
end
|
324
|
-
|
325
|
-
it "returns just the units" do
|
326
|
-
@pressure.metric?.should be_true
|
327
|
-
@pressure.units.should == Data::Pressure::METRIC_UNITS
|
328
|
-
|
329
|
-
@pressure.imperial!
|
330
|
-
@pressure.metric?.should be_false
|
331
|
-
@pressure.units.should == Data::Pressure::IMPERIAL_UNITS
|
332
|
-
end
|
333
|
-
|
334
|
-
end
|
335
|
-
|
336
52
|
end
|