barometer 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (321) hide show
  1. data/.gitignore +2 -0
  2. data/.pelusa.yml +7 -0
  3. data/.travis.yml +6 -3
  4. data/Gemfile +11 -1
  5. data/README.md +89 -244
  6. data/Rakefile +1 -1
  7. data/barometer.gemspec +22 -24
  8. data/lib/barometer.rb +14 -65
  9. data/lib/barometer/base.rb +35 -65
  10. data/lib/barometer/data.rb +15 -20
  11. data/lib/barometer/data/attribute.rb +19 -0
  12. data/lib/barometer/data/attributes/distance.rb +11 -0
  13. data/lib/barometer/data/attributes/float.rb +11 -0
  14. data/lib/barometer/data/attributes/integer.rb +11 -0
  15. data/lib/barometer/data/attributes/location.rb +11 -0
  16. data/lib/barometer/data/attributes/pressure.rb +11 -0
  17. data/lib/barometer/data/attributes/sun.rb +15 -0
  18. data/lib/barometer/data/attributes/temperature.rb +11 -0
  19. data/lib/barometer/data/attributes/time.rb +11 -0
  20. data/lib/barometer/data/attributes/vector.rb +11 -0
  21. data/lib/barometer/data/attributes/zone.rb +11 -0
  22. data/lib/barometer/data/convertable_units.rb +145 -0
  23. data/lib/barometer/data/coordinates.rb +16 -0
  24. data/lib/barometer/data/distance.rb +14 -133
  25. data/lib/barometer/data/geo.rb +22 -59
  26. data/lib/barometer/data/location.rb +14 -20
  27. data/lib/barometer/data/pressure.rb +14 -135
  28. data/lib/barometer/data/sun.rb +24 -24
  29. data/lib/barometer/data/temperature.rb +14 -169
  30. data/lib/barometer/data/vector.rb +44 -0
  31. data/lib/barometer/data/zone.rb +109 -112
  32. data/lib/barometer/query.rb +23 -161
  33. data/lib/barometer/query/base.rb +88 -0
  34. data/lib/barometer/query/converter.rb +64 -0
  35. data/lib/barometer/query/converters/from_coordinates_to_noaa_station_id.rb +30 -0
  36. data/lib/barometer/query/converters/from_geocode_to_coordinates.rb +28 -0
  37. data/lib/barometer/query/converters/from_short_zipcode_to_zipcode.rb +28 -0
  38. data/lib/barometer/query/converters/from_weather_id_to_geocode.rb +30 -0
  39. data/lib/barometer/query/converters/from_woe_id_or_ipv4_to_geocode.rb +32 -0
  40. data/lib/barometer/query/converters/to_geocode.rb +30 -0
  41. data/lib/barometer/query/converters/to_weather_id.rb +30 -0
  42. data/lib/barometer/query/converters/to_woe_id.rb +30 -0
  43. data/lib/barometer/query/format.rb +59 -0
  44. data/lib/barometer/query/formats/base.rb +22 -0
  45. data/lib/barometer/query/formats/coordinates.rb +14 -0
  46. data/lib/barometer/query/formats/geocode.rb +15 -0
  47. data/lib/barometer/query/formats/icao.rb +35 -0
  48. data/lib/barometer/query/formats/ipv4_address.rb +19 -0
  49. data/lib/barometer/query/formats/noaa_station_id.rb +15 -0
  50. data/lib/barometer/query/formats/postalcode.rb +20 -0
  51. data/lib/barometer/query/formats/short_zipcode.rb +15 -0
  52. data/lib/barometer/{translations → query/formats/translations}/icao_country_codes.yml +0 -0
  53. data/lib/barometer/{translations → query/formats/translations}/weather_country_codes.yml +0 -0
  54. data/lib/barometer/query/formats/unknown.rb +14 -0
  55. data/lib/barometer/query/formats/weather_id.rb +33 -0
  56. data/lib/barometer/query/formats/woe_id.rb +28 -0
  57. data/lib/barometer/query/formats/zipcode.rb +15 -0
  58. data/lib/barometer/query/service.rb +13 -0
  59. data/lib/barometer/query/services/apis/geonames_timezone.rb +26 -0
  60. data/lib/barometer/query/services/apis/google_geocode.rb +35 -0
  61. data/lib/barometer/query/services/apis/noaa_station.rb +31 -0
  62. data/lib/barometer/query/services/apis/weather_id.rb +35 -0
  63. data/lib/barometer/query/services/apis/wunderground_timezone.rb +26 -0
  64. data/lib/barometer/query/services/apis/yahoo_placefinder.rb +35 -0
  65. data/lib/barometer/query/services/apis/yahoo_weather.rb +31 -0
  66. data/lib/barometer/query/services/from_weather_id.rb +64 -0
  67. data/lib/barometer/query/services/geonames_timezone.rb +18 -0
  68. data/lib/barometer/query/services/google_geocode.rb +106 -0
  69. data/lib/barometer/query/services/noaa_station_id.rb +28 -0
  70. data/lib/barometer/query/services/to_weather_id.rb +25 -0
  71. data/lib/barometer/query/services/to_woe_id.rb +29 -0
  72. data/lib/barometer/query/services/wunderground_timezone.rb +18 -0
  73. data/lib/barometer/query/services/yahoo_geocode.rb +69 -0
  74. data/lib/barometer/response.rb +12 -0
  75. data/lib/barometer/response/base.rb +57 -0
  76. data/lib/barometer/response/current.rb +27 -0
  77. data/lib/barometer/response/prediction.rb +41 -0
  78. data/lib/barometer/response/prediction_collection.rb +48 -0
  79. data/lib/barometer/utils.rb +17 -0
  80. data/lib/barometer/utils/address.rb +33 -0
  81. data/lib/barometer/utils/api.rb +30 -0
  82. data/lib/barometer/utils/config_reader.rb +40 -0
  83. data/lib/barometer/utils/get.rb +17 -0
  84. data/lib/barometer/utils/json_reader.rb +22 -0
  85. data/lib/barometer/utils/payload.rb +100 -0
  86. data/lib/barometer/utils/payload_request.rb +37 -0
  87. data/lib/barometer/utils/post.rb +24 -0
  88. data/lib/barometer/utils/time.rb +78 -0
  89. data/lib/barometer/{translations → utils/translations}/zone_codes.yml +0 -0
  90. data/lib/barometer/utils/versioned_registration.rb +70 -0
  91. data/lib/barometer/utils/xml_reader.rb +27 -0
  92. data/lib/barometer/utils/zone_code_lookup.rb +30 -0
  93. data/lib/barometer/version.rb +1 -1
  94. data/lib/barometer/weather.rb +44 -173
  95. data/lib/barometer/weather_service.rb +41 -0
  96. data/lib/barometer/weather_services/base.rb +50 -0
  97. data/lib/barometer/weather_services/forecast_io.rb +36 -0
  98. data/lib/barometer/weather_services/forecast_io/api.rb +22 -0
  99. data/lib/barometer/weather_services/forecast_io/query.rb +38 -0
  100. data/lib/barometer/weather_services/forecast_io/response.rb +31 -0
  101. data/lib/barometer/weather_services/forecast_io/response/current_weather.rb +78 -0
  102. data/lib/barometer/weather_services/forecast_io/response/forecasted_weather.rb +74 -0
  103. data/lib/barometer/weather_services/forecast_io/response/location.rb +19 -0
  104. data/lib/barometer/weather_services/forecast_io/response/timezone.rb +25 -0
  105. data/lib/barometer/weather_services/noaa.rb +21 -305
  106. data/lib/barometer/weather_services/noaa/current_api.rb +25 -0
  107. data/lib/barometer/weather_services/noaa/current_query.rb +30 -0
  108. data/lib/barometer/weather_services/noaa/current_response.rb +29 -0
  109. data/lib/barometer/weather_services/noaa/forecast_api.rb +25 -0
  110. data/lib/barometer/weather_services/noaa/forecast_query.rb +39 -0
  111. data/lib/barometer/weather_services/noaa/forecast_response.rb +28 -0
  112. data/lib/barometer/weather_services/noaa/response/current_location.rb +42 -0
  113. data/lib/barometer/weather_services/noaa/response/current_station.rb +46 -0
  114. data/lib/barometer/weather_services/noaa/response/current_weather.rb +82 -0
  115. data/lib/barometer/weather_services/noaa/response/forecasted_weather.rb +90 -0
  116. data/lib/barometer/weather_services/noaa/response/location.rb +19 -0
  117. data/lib/barometer/weather_services/noaa/response/timezone.rb +15 -0
  118. data/lib/barometer/weather_services/response.rb +9 -0
  119. data/lib/barometer/weather_services/response/location.rb +42 -0
  120. data/lib/barometer/weather_services/response/time_zone.rb +19 -0
  121. data/lib/barometer/weather_services/weather_bug.rb +24 -280
  122. data/lib/barometer/weather_services/weather_bug/current_api.rb +26 -0
  123. data/lib/barometer/weather_services/weather_bug/current_response.rb +33 -0
  124. data/lib/barometer/weather_services/weather_bug/forecast_api.rb +26 -0
  125. data/lib/barometer/weather_services/weather_bug/forecast_response.rb +29 -0
  126. data/lib/barometer/weather_services/weather_bug/query.rb +42 -0
  127. data/lib/barometer/weather_services/weather_bug/response/current_weather.rb +82 -0
  128. data/lib/barometer/weather_services/weather_bug/response/forecasted_weather.rb +67 -0
  129. data/lib/barometer/weather_services/weather_bug/response/location.rb +23 -0
  130. data/lib/barometer/weather_services/weather_bug/response/station.rb +43 -0
  131. data/lib/barometer/weather_services/weather_bug/response/sun.rb +32 -0
  132. data/lib/barometer/weather_services/weather_bug/response/time_helper.rb +52 -0
  133. data/lib/barometer/weather_services/weather_bug/response/timezone.rb +15 -0
  134. data/lib/barometer/weather_services/wunderground_v1.rb +32 -0
  135. data/lib/barometer/weather_services/wunderground_v1/current_api.rb +21 -0
  136. data/lib/barometer/weather_services/wunderground_v1/current_response.rb +31 -0
  137. data/lib/barometer/weather_services/wunderground_v1/forecast_api.rb +21 -0
  138. data/lib/barometer/weather_services/wunderground_v1/forecast_response.rb +33 -0
  139. data/lib/barometer/weather_services/wunderground_v1/query.rb +30 -0
  140. data/lib/barometer/weather_services/wunderground_v1/response/current_weather.rb +92 -0
  141. data/lib/barometer/weather_services/wunderground_v1/response/forecasted_weather.rb +87 -0
  142. data/lib/barometer/weather_services/wunderground_v1/response/full_timezone.rb +22 -0
  143. data/lib/barometer/weather_services/wunderground_v1/response/location.rb +43 -0
  144. data/lib/barometer/weather_services/wunderground_v1/response/station.rb +39 -0
  145. data/lib/barometer/weather_services/wunderground_v1/response/sun.rb +53 -0
  146. data/lib/barometer/weather_services/wunderground_v1/response/timezone.rb +15 -0
  147. data/lib/barometer/weather_services/yahoo.rb +16 -198
  148. data/lib/barometer/weather_services/yahoo/api.rb +21 -0
  149. data/lib/barometer/weather_services/yahoo/query.rb +42 -0
  150. data/lib/barometer/weather_services/yahoo/response.rb +39 -0
  151. data/lib/barometer/weather_services/yahoo/response/current_weather.rb +86 -0
  152. data/lib/barometer/weather_services/yahoo/response/forecasted_weather.rb +71 -0
  153. data/lib/barometer/weather_services/yahoo/response/location.rb +47 -0
  154. data/lib/barometer/weather_services/yahoo/response/sun.rb +43 -0
  155. data/lib/barometer/weather_services/yahoo/response/timezone.rb +15 -0
  156. data/spec/barometer_spec.rb +18 -120
  157. data/spec/base_spec.rb +114 -0
  158. data/spec/cassettes/Converter_FromCoordinatesToNoaaStationId.json +1 -0
  159. data/spec/cassettes/Converter_FromWeatherIdToGeocode.json +1 -0
  160. data/spec/cassettes/Converter_FromWoeIdOrIpv4ToGeocode.json +1 -0
  161. data/spec/cassettes/Converter_ToGeocode.json +1 -0
  162. data/spec/cassettes/Converter_ToWeatherId.json +1 -0
  163. data/spec/cassettes/Converter_ToWoeId.json +1 -0
  164. data/spec/cassettes/Service_FromWeatherId.json +1 -0
  165. data/spec/cassettes/Service_GoogleGeocode.json +1 -0
  166. data/spec/cassettes/Service_NoaaStation.json +1 -0
  167. data/spec/cassettes/Service_ToWeatherId.json +1 -0
  168. data/spec/cassettes/Service_ToWoeId.json +1 -0
  169. data/spec/cassettes/Service_YahooGeocode.json +1 -0
  170. data/spec/cassettes/WeatherService_ForecastIo.json +1 -0
  171. data/spec/cassettes/WeatherService_Noaa.json +1 -1
  172. data/spec/cassettes/WeatherService_WeatherBug.json +1 -1
  173. data/spec/cassettes/WeatherService_WundergroundV1.json +1 -0
  174. data/spec/cassettes/WeatherService_Yahoo.json +1 -1
  175. data/spec/data/attributes/distance_spec.rb +60 -0
  176. data/spec/data/attributes/location_spec.rb +41 -0
  177. data/spec/data/attributes/pressure_spec.rb +60 -0
  178. data/spec/data/attributes/sun_spec.rb +33 -0
  179. data/spec/data/attributes/temperature_spec.rb +60 -0
  180. data/spec/data/attributes/time_spec.rb +58 -0
  181. data/spec/data/attributes/vector_spec.rb +43 -0
  182. data/spec/data/attributes/zone_spec.rb +34 -0
  183. data/spec/data/convertable_units_spec.rb +299 -0
  184. data/spec/data/coordinates_spec.rb +15 -0
  185. data/spec/data/distance_spec.rb +49 -333
  186. data/spec/data/geo_spec.rb +72 -71
  187. data/spec/data/location_spec.rb +70 -65
  188. data/spec/data/pressure_spec.rb +49 -333
  189. data/spec/data/sun_spec.rb +57 -81
  190. data/spec/data/temperature_spec.rb +49 -393
  191. data/spec/data/vector_spec.rb +100 -0
  192. data/spec/data/zone_spec.rb +199 -266
  193. data/spec/query/base_spec.rb +296 -0
  194. data/spec/query/converter_spec.rb +98 -0
  195. data/spec/query/converters/from_coordinates_to_noaa_station_id_spec.rb +35 -0
  196. data/spec/query/converters/from_geocode_to_coordinates_spec.rb +25 -0
  197. data/spec/query/converters/from_short_zipcode_to_zipcode_spec.rb +31 -0
  198. data/spec/query/converters/from_weather_id_to_geocode_spec.rb +40 -0
  199. data/spec/query/converters/from_woe_id_or_ipv4_to_geocode_spec.rb +51 -0
  200. data/spec/query/converters/to_geocode_spec.rb +99 -0
  201. data/spec/query/converters/to_weather_id_spec.rb +35 -0
  202. data/spec/query/converters/to_woe_id_spec.rb +74 -0
  203. data/spec/query/formats/base_spec.rb +15 -0
  204. data/spec/query/formats/coordinates_spec.rb +13 -0
  205. data/spec/query/formats/geocode_spec.rb +9 -0
  206. data/spec/query/formats/icao_spec.rb +20 -0
  207. data/spec/query/formats/ipv4_address_spec.rb +33 -0
  208. data/spec/query/formats/noaa_station_id_spec.rb +9 -0
  209. data/spec/query/formats/postalcode_spec.rb +18 -0
  210. data/spec/query/formats/short_zipcode_spec.rb +18 -0
  211. data/spec/query/formats/unknown_spec.rb +9 -0
  212. data/spec/query/formats/weather_id_spec.rb +31 -0
  213. data/spec/query/formats/woe_id_spec.rb +45 -0
  214. data/spec/query/formats/zipcode_spec.rb +18 -0
  215. data/spec/query/formats_spec.rb +55 -0
  216. data/spec/query/services/from_weather_id_spec.rb +54 -0
  217. data/spec/query/services/google_geocode_spec.rb +60 -0
  218. data/spec/query/services/noaa_station_id_spec.rb +23 -0
  219. data/spec/query/services/to_weather_id_spec.rb +23 -0
  220. data/spec/query/services/to_woe_id_spec.rb +51 -0
  221. data/spec/query/services/yahoo_geocode_spec.rb +72 -0
  222. data/spec/response/base_spec.rb +103 -0
  223. data/spec/response/current_spec.rb +33 -0
  224. data/spec/response/predicition_spec.rb +65 -0
  225. data/spec/response/prediction_collection_spec.rb +97 -0
  226. data/spec/spec_helper.rb +14 -12
  227. data/spec/support/key_file_parser.rb +22 -0
  228. data/spec/support/matchers/formats.rb +36 -0
  229. data/spec/support/matchers/have_data.rb +46 -0
  230. data/spec/support/matchers/have_field.rb +128 -0
  231. data/spec/support/matchers/have_forecast.rb +46 -0
  232. data/spec/support/matchers/path.rb +23 -0
  233. data/spec/support/query_factory.rb +20 -0
  234. data/spec/utils/address_spec.rb +67 -0
  235. data/spec/utils/config_reader_spec.rb +157 -0
  236. data/spec/utils/get_spec.rb +22 -0
  237. data/spec/utils/payload_request_spec.rb +69 -0
  238. data/spec/utils/payload_spec.rb +168 -0
  239. data/spec/utils/post_spec.rb +20 -0
  240. data/spec/utils/time_spec.rb +93 -0
  241. data/spec/utils/versioned_registration_spec.rb +105 -0
  242. data/spec/weather_services/base_spec.rb +116 -0
  243. data/spec/weather_services/forecast_io_spec.rb +71 -0
  244. data/spec/weather_services/noaa/current_response_spec.rb +22 -0
  245. data/spec/weather_services/noaa/forecast_response_spec.rb +33 -0
  246. data/spec/weather_services/noaa_spec.rb +68 -166
  247. data/spec/weather_services/weather_bug/current_response_spec.rb +64 -0
  248. data/spec/weather_services/weather_bug/forecast_response_spec.rb +23 -0
  249. data/spec/weather_services/weather_bug_spec.rb +62 -202
  250. data/spec/weather_services/wunderground_v1/current_response_spec.rb +19 -0
  251. data/spec/weather_services/wunderground_v1/forecast_response_spec.rb +62 -0
  252. data/spec/weather_services/wunderground_v1_spec.rb +78 -0
  253. data/spec/weather_services/yahoo/response_spec.rb +73 -0
  254. data/spec/weather_services/yahoo_spec.rb +52 -135
  255. data/spec/weather_services_spec.rb +103 -0
  256. data/spec/weather_spec.rb +167 -347
  257. metadata +342 -123
  258. data/.document +0 -5
  259. data/TODO +0 -60
  260. data/bin/barometer +0 -441
  261. data/lib/barometer/data/local_datetime.rb +0 -145
  262. data/lib/barometer/data/local_time.rb +0 -134
  263. data/lib/barometer/data/speed.rb +0 -158
  264. data/lib/barometer/data/units.rb +0 -49
  265. data/lib/barometer/formats.rb +0 -13
  266. data/lib/barometer/formats/coordinates.rb +0 -57
  267. data/lib/barometer/formats/format.rb +0 -64
  268. data/lib/barometer/formats/geocode.rb +0 -60
  269. data/lib/barometer/formats/icao.rb +0 -37
  270. data/lib/barometer/formats/postalcode.rb +0 -22
  271. data/lib/barometer/formats/short_zipcode.rb +0 -17
  272. data/lib/barometer/formats/weather_id.rb +0 -92
  273. data/lib/barometer/formats/woe_id.rb +0 -150
  274. data/lib/barometer/formats/zipcode.rb +0 -31
  275. data/lib/barometer/key_file_parser.rb +0 -20
  276. data/lib/barometer/measurements/measurement.rb +0 -202
  277. data/lib/barometer/measurements/result.rb +0 -207
  278. data/lib/barometer/measurements/result_array.rb +0 -75
  279. data/lib/barometer/services.rb +0 -19
  280. data/lib/barometer/weather_services/service.rb +0 -189
  281. data/lib/barometer/weather_services/wunderground.rb +0 -264
  282. data/lib/barometer/web_services/geocode.rb +0 -34
  283. data/lib/barometer/web_services/noaa_station_id.rb +0 -53
  284. data/lib/barometer/web_services/placemaker.rb +0 -95
  285. data/lib/barometer/web_services/timezone.rb +0 -38
  286. data/lib/barometer/web_services/weather_id.rb +0 -50
  287. data/lib/barometer/web_services/web_service.rb +0 -29
  288. data/spec/cassettes/Barometer.json +0 -1
  289. data/spec/cassettes/Query.json +0 -1
  290. data/spec/cassettes/Query_Format_Coordinates.json +0 -1
  291. data/spec/cassettes/Query_Format_Geocode.json +0 -1
  292. data/spec/cassettes/Query_Format_WeatherID.json +0 -1
  293. data/spec/cassettes/Query_Format_WoeID.json +0 -1
  294. data/spec/cassettes/WeatherService.json +0 -1
  295. data/spec/cassettes/WeatherService_Wunderground.json +0 -1
  296. data/spec/cassettes/WebService_Geocode.json +0 -1
  297. data/spec/cassettes/WebService_NoaaStation.json +0 -1
  298. data/spec/data/local_datetime_spec.rb +0 -274
  299. data/spec/data/local_time_spec.rb +0 -239
  300. data/spec/data/speed_spec.rb +0 -374
  301. data/spec/data/units_spec.rb +0 -101
  302. data/spec/formats/coordinates_spec.rb +0 -166
  303. data/spec/formats/format_spec.rb +0 -74
  304. data/spec/formats/geocode_spec.rb +0 -163
  305. data/spec/formats/icao_spec.rb +0 -55
  306. data/spec/formats/postalcode_spec.rb +0 -53
  307. data/spec/formats/short_zipcode_spec.rb +0 -47
  308. data/spec/formats/weather_id_spec.rb +0 -182
  309. data/spec/formats/woe_id_spec.rb +0 -211
  310. data/spec/formats/zipcode_spec.rb +0 -103
  311. data/spec/key_file_parser_spec.rb +0 -28
  312. data/spec/measurements/measurement_spec.rb +0 -381
  313. data/spec/measurements/result_array_spec.rb +0 -150
  314. data/spec/measurements/result_spec.rb +0 -632
  315. data/spec/query_spec.rb +0 -498
  316. data/spec/weather_services/services_spec.rb +0 -135
  317. data/spec/weather_services/wunderground_spec.rb +0 -179
  318. data/spec/web_services/geocode_spec.rb +0 -31
  319. data/spec/web_services/noaa_station_id_spec.rb +0 -33
  320. data/spec/web_services/placemaker_spec.rb +0 -41
  321. data/spec/web_services/web_services_spec.rb +0 -20
@@ -1,91 +1,92 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Data::Geo" do
4
-
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @geo = Data::Geo.new
9
- end
10
-
11
- it "responds to query" do
12
- @geo.query.should be_nil
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
- it "responds to country_code" do
24
- @geo.country_code.should be_nil
25
- end
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
- it "responds to locality" do
28
- @geo.locality.should be_nil
29
- end
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
- it "responds to region" do
32
- @geo.region.should be_nil
33
- end
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
- it "responds to country" do
36
- @geo.country.should be_nil
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
- it "responds to address" do
40
- @geo.address.should be_nil
41
- end
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
- it "responds to coordinates" do
44
- @geo.longitude = "99.99"
45
- @geo.latitude = "88.88"
46
- @geo.coordinates.should == [@geo.latitude, @geo.longitude].join(',')
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
- it "should print a string" do
50
- @geo = Data::Geo.new
51
- @geo.to_s.should == ""
52
- @geo.address = "address"
53
- @geo.to_s.should == "address"
54
- @geo.locality = "locality"
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
- it "requires Hash object" do
61
- lambda { Data::Geo.new(1) }.should raise_error(ArgumentError)
62
- lambda { Data::Geo.new(Hash.new) }.should_not raise_error(ArgumentError)
63
- end
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
- it "returns a Barometer::Geo object" do
66
- geo = Data::Geo.new(Hash.new)
67
- geo.is_a?(Data::Geo).should be_true
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
- end
70
+ geo = target_geo.merge(source_geo)
71
+ expect( geo.postal_code ).to eq ''
72
+ end
71
73
 
72
- describe "when converting" do
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
- before(:each) do
75
- @geo = Data::Geo.new
76
- end
78
+ geo = target_geo.merge(source_geo)
79
+ expect( geo.country ).to eq 'Foo Bar'
80
+ end
77
81
 
78
- describe "from HTTParty" do
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
- it "accepts HTTParty::Response object" do
81
- location = Hash.new
82
- lambda { @geo.build_from_hash(1) }.should raise_error(ArgumentError)
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
@@ -1,70 +1,75 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Location" do
4
-
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @location = Data::Location.new
9
- end
10
-
11
- it "responds to id" do
12
- @location.id.should be_nil
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
- it "responds to city" do
20
- @location.city.should be_nil
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
@@ -1,336 +1,52 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Pressure" do
4
-
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @pressure = Data::Pressure.new
9
- end
10
-
11
- it "defines METRIC_UNITS" do
12
- Data::Pressure.const_defined?("METRIC_UNITS").should be_true
13
- Data::Pressure::METRIC_UNITS.should == "mb"
14
- end
15
-
16
- it "defines IMPERIAL_UNITS" do
17
- Data::Pressure.const_defined?("IMPERIAL_UNITS").should be_true
18
- Data::Pressure::IMPERIAL_UNITS.should == "in"
19
- end
20
-
21
- it "responds to millibars" do
22
- @pressure.millibars.should be_nil
23
- end
24
-
25
- it "responds to inches" do
26
- @pressure.inches.should be_nil
27
- end
28
-
29
- it "responds to metric_default" do
30
- lambda { @pressure.metric_default = 5 }.should_not raise_error(NotImplementedError)
31
- end
32
-
33
- it "responds to imperial_default" do
34
- lambda { @pressure.imperial_default = 5 }.should_not raise_error(NotImplementedError)
35
- end
36
-
37
- it "responds to nil?" do
38
- @pressure.nil?.should be_true
39
- @pressure.mb = 5
40
- @pressure.nil?.should be_false
41
- end
42
-
43
- end
44
-
45
- describe "conversion" do
46
-
47
- # For all conversions
48
- # 721.64 mb = 21.31 in
49
- before(:each) do
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