barometer 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,440 +1,260 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Barometer::Weather do
4
-
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @weather = Barometer::Weather.new
9
- end
10
-
11
- it "responds to measurements (and sets default value)" do
12
- @weather.measurements.should == []
13
- end
14
-
15
- it "responds to current" do
16
- @weather.respond_to?("current").should be_true
17
- end
18
-
19
- it "responds to forecast" do
20
- @weather.respond_to?("forecast").should be_true
21
- end
22
-
23
- it "responds to today" do
24
- @weather.respond_to?("today").should be_true
25
- end
26
-
27
- it "responds to tommorrow" do
28
- @weather.respond_to?("tomorrow").should be_true
29
- end
30
-
31
- it "responds to for" do
32
- @weather.respond_to?("for").should be_true
33
- end
34
-
35
- end
36
-
37
- describe "with measurements" do
38
-
39
- before(:each) do
40
- @weather = Barometer::Weather.new
41
- @wunderground = Barometer::Measurement.new(:wunderground)
42
- @wunderground.stub!(:success).and_return(true)
43
- @wunderground.stub!(:success?).and_return(true)
44
- @yahoo = Barometer::Measurement.new(:yahoo)
45
- @yahoo.stub!(:success).and_return(true)
46
- @yahoo.stub!(:success?).and_return(true)
47
- @google = Barometer::Measurement.new(:google)
48
- @weather.measurements << @wunderground
49
- @weather.measurements << @yahoo
50
- @weather.measurements << @google
51
- end
52
-
53
- it "retrieves a source measurement" do
54
- lambda { @weather.source(1) }.should raise_error(ArgumentError)
55
- lambda { @weather.source("valid") }.should_not raise_error(ArgumentError)
56
- lambda { @weather.source(:valid) }.should_not raise_error(ArgumentError)
57
- @weather.source(:does_not_exist).should be_nil
58
- @weather.source(:wunderground).should == @wunderground
1
+ require 'spec_helper'
2
+
3
+ module Barometer
4
+ describe Weather do
5
+ def fake_response(args)
6
+ success = args.delete(:success?)
7
+ weight = args.delete(:weight) || 1
8
+
9
+ double(:response,
10
+ success?: success.nil? ? true : success,
11
+ weight: weight,
12
+ current: double(:current, args)
13
+ )
59
14
  end
60
15
 
61
- it "lists the sources of measurements (that were successful)" do
62
- sources = @weather.sources
63
- sources.should_not be_nil
64
- @wunderground.success?.should be_true
65
- sources.include?(:wunderground).should be_true
66
- @yahoo.success?.should be_true
67
- sources.include?(:yahoo).should be_true
68
- @google.success?.should be_false
69
- sources.include?(:google).should be_false
70
- end
71
-
72
- it "returns the default source" do
73
- @weather.default.should == @wunderground
74
- end
16
+ let(:weather) { Weather.new }
75
17
 
76
- end
77
-
78
- describe "when calculating averages" do
79
-
80
- before(:each) do
81
- @weather = Barometer::Weather.new
82
- @wunderground = Barometer::Measurement.new(:wunderground)
83
- @wunderground.current = Barometer::Measurement::Result.new
84
- @wunderground.stub!(:success).and_return(true)
85
- @wunderground.stub!(:success?).and_return(true)
86
- @yahoo = Barometer::Measurement.new(:yahoo)
87
- @yahoo.current = Barometer::Measurement::Result.new
88
- @yahoo.stub!(:success).and_return(true)
89
- @yahoo.stub!(:success?).and_return(true)
90
- @google = Barometer::Measurement.new(:google)
91
- @weather.measurements << @wunderground
92
- @weather.measurements << @yahoo
93
- @weather.measurements << @google
18
+ describe ".new" do
19
+ specify { expect( weather.responses ).to be_empty }
94
20
  end
95
21
 
96
- it "doesn't include nil values" do
97
- @weather.source(:wunderground).current.temperature = Data::Temperature.new
98
- @weather.source(:wunderground).current.temperature.c = 10
99
-
100
- @weather.temperature.c.should == 10
22
+ describe "#source" do
23
+ let(:bar_response) { double(:response, source: :bar) }
24
+ let(:foo_response) { double(:response, source: :foo) }
101
25
 
102
- @weather.source(:yahoo).current.temperature = Data::Temperature.new
103
- @weather.source(:yahoo).current.temperature.c = nil
26
+ before { weather.responses = [foo_response, bar_response] }
104
27
 
105
- @weather.temperature.c.should == 10
106
- end
107
-
108
- it "respects the measurement weight" do
109
- @weather.source(:wunderground).current.temperature = Data::Temperature.new
110
- @weather.source(:wunderground).current.temperature.c = 10
111
- @weather.source(:yahoo).current.temperature = Data::Temperature.new
112
- @weather.source(:yahoo).current.temperature.c = 4
113
-
114
- @weather.measurements.first.weight = 2
115
-
116
- @weather.temperature.c.should == 8
117
- end
118
-
119
- describe "for temperature" do
120
-
121
- before(:each) do
122
- @weather.source(:wunderground).current.temperature = Data::Temperature.new
123
- @weather.source(:wunderground).current.temperature.c = 10
124
- @weather.source(:yahoo).current.temperature = Data::Temperature.new
125
- @weather.source(:yahoo).current.temperature.c = 6
28
+ it "returns the response for the specified source" do
29
+ expect( weather.source(:foo) ).to eq foo_response
126
30
  end
127
31
 
128
- it "returns averages" do
129
- @weather.temperature.c.should == 8
32
+ it "returns nil when nothing is found" do
33
+ expect( weather.source(:baz) ).to be_nil
130
34
  end
131
-
132
- it "returns default when disabled" do
133
- @weather.temperature(false).c.should == 10
134
- end
135
-
136
35
  end
137
36
 
138
- describe "for wind" do
139
-
140
- before(:each) do
141
- @weather.source(:wunderground).current.wind = Data::Speed.new
142
- @weather.source(:wunderground).current.wind.kph = 10
143
- @weather.source(:yahoo).current.wind = Data::Speed.new
144
- @weather.source(:yahoo).current.wind.kph = 6
145
- end
146
-
147
- it "returns averages" do
148
- @weather.wind.kph.should == 8
37
+ describe "#success?" do
38
+ it "returns true when a response is successful" do
39
+ response_one = double(:response, success?: false)
40
+ response_two = double(:response, success?: true)
41
+ weather.responses = [response_one, response_two]
42
+ expect( weather ).to be_success
149
43
  end
150
44
 
151
- it "returns default when disabled" do
152
- @weather.wind(false).kph.should == 10
45
+ it "returns false when no responses are successful" do
46
+ response_one = double(:response, success?: false)
47
+ response_two = double(:response, success?: false)
48
+ weather.responses = [response_one, response_two]
49
+ expect( weather ).not_to be_success
153
50
  end
154
-
155
51
  end
156
52
 
157
- describe "for humidity" do
53
+ describe "#current" do
54
+ it "returns the current response for the first successful response" do
55
+ current_two = double(:current)
56
+ response_one = double(:response, success?: false)
57
+ response_two = double(:response, success?: true, current: current_two)
58
+ weather.responses = [response_one, response_two]
158
59
 
159
- before(:each) do
160
- @weather.source(:wunderground).current.humidity = 10
161
- @weather.source(:yahoo).current.humidity = 6
60
+ expect( weather.current ).to eq current_two
162
61
  end
62
+ end
163
63
 
164
- it "returns averages" do
165
- @weather.humidity.should == 8
166
- end
64
+ describe "#forecast" do
65
+ it "returns the forecast response for the first successful response" do
66
+ forecast_two = double(:forecast)
67
+ response_one = double(:response, success?: false)
68
+ response_two = double(:response, success?: true, forecast: forecast_two)
69
+ weather.responses = [response_one, response_two]
167
70
 
168
- it "returns default when disabled" do
169
- @weather.humidity(false).should == 10
71
+ expect( weather.forecast ).to eq forecast_two
170
72
  end
171
-
172
73
  end
173
74
 
174
- describe "for pressure" do
75
+ describe "#today" do
76
+ it "returns the first forecast response for the first successful response" do
77
+ today = double(:forecast)
78
+ tommorrow = double(:forecast)
79
+ response_one = double(:response, success?: false)
80
+ response_two = double(:response, success?: true, forecast: [today, tommorrow])
81
+ weather.responses = [response_one, response_two]
175
82
 
176
- before(:each) do
177
- @weather.source(:wunderground).current.pressure = Data::Pressure.new
178
- @weather.source(:wunderground).current.pressure.mb = 10
179
- @weather.source(:yahoo).current.pressure = Data::Pressure.new
180
- @weather.source(:yahoo).current.pressure.mb = 6
83
+ expect( weather.today ).to eq today
181
84
  end
85
+ end
182
86
 
183
- it "returns averages" do
184
- @weather.pressure.mb.should == 8
185
- end
87
+ describe "#tomorrow" do
88
+ it "returns the second forecast response for the first successful response" do
89
+ today = double(:forecast)
90
+ tommorrow = double(:forecast)
91
+ response_one = double(:response, success?: false)
92
+ response_two = double(:response, success?: true, forecast: [today, tommorrow])
93
+ weather.responses = [response_one, response_two]
186
94
 
187
- it "returns default when disabled" do
188
- @weather.pressure(false).mb.should == 10
95
+ expect( weather.tomorrow ).to eq tommorrow
189
96
  end
190
-
191
97
  end
192
98
 
193
- describe "for dew_point" do
99
+ describe "#for" do
100
+ it "delegates to the first successful response" do
101
+ response_one = double(:response, success?: false, for: nil)
102
+ response_two = double(:response, success?: true, for: nil)
103
+ weather.responses = [response_one, response_two]
194
104
 
195
- before(:each) do
196
- @weather.source(:wunderground).current.dew_point = Data::Temperature.new
197
- @weather.source(:wunderground).current.dew_point.c = 10
198
- @weather.source(:yahoo).current.dew_point = Data::Temperature.new
199
- @weather.source(:yahoo).current.dew_point.c = 6
200
- end
105
+ query = build_query
106
+ weather.for(query)
201
107
 
202
- it "returns averages" do
203
- @weather.dew_point.c.should == 8
108
+ expect( response_two ).to have_received(:for).with(query)
204
109
  end
205
-
206
- it "returns default when disabled" do
207
- @weather.dew_point(false).c.should == 10
208
- end
209
-
210
110
  end
211
111
 
212
- describe "for heat_index" do
112
+ describe "#temperature" do
113
+ let(:response_one) { fake_response(temperature: Data::Temperature.new(:metric, 20)) }
114
+ let(:response_two) { fake_response(temperature: Data::Temperature.new(:metric, 30)) }
213
115
 
214
- before(:each) do
215
- @weather.source(:wunderground).current.heat_index = Data::Temperature.new
216
- @weather.source(:wunderground).current.heat_index.c = 10
217
- @weather.source(:yahoo).current.heat_index = Data::Temperature.new
218
- @weather.source(:yahoo).current.heat_index.c = 6
219
- end
116
+ before { weather.responses = [response_one, response_two] }
220
117
 
221
- it "returns averages" do
222
- @weather.heat_index.c.should == 8
118
+ it "returns an average temeprature" do
119
+ expect( weather.temperature ).to eq Data::Temperature.new(:metric, 25.0)
223
120
  end
224
121
 
225
- it "returns default when disabled" do
226
- @weather.heat_index(false).c.should == 10
122
+ it "returns nil when there is no valid data" do
123
+ response_one.stub(success?: false)
124
+ response_two.stub(success?: false)
125
+ expect( weather.temperature ).to be_nil
227
126
  end
228
127
 
229
- end
230
-
231
- describe "for wind_chill" do
232
-
233
- before(:each) do
234
- @weather.source(:wunderground).current.wind_chill = Data::Temperature.new
235
- @weather.source(:wunderground).current.wind_chill.c = 10
236
- @weather.source(:yahoo).current.wind_chill = Data::Temperature.new
237
- @weather.source(:yahoo).current.wind_chill.c = 6
128
+ it "excludes unsuccessful responses" do
129
+ response_three = fake_response(success?: false, temperature: Data::Temperature.new(:metric, 10))
130
+ weather.responses << response_three
131
+ expect( weather.temperature ).to eq Data::Temperature.new(:metric, 25.0)
238
132
  end
239
133
 
240
- it "returns averages" do
241
- @weather.wind_chill.c.should == 8
134
+ it "excludes nil values" do
135
+ response_three = fake_response(temperature: nil)
136
+ weather.responses << response_three
137
+ expect( weather.temperature ).to eq Data::Temperature.new(:metric, 25.0)
242
138
  end
243
139
 
244
- it "returns default when disabled" do
245
- @weather.wind_chill(false).c.should == 10
140
+ it "returns a weighted average temeprature" do
141
+ response_one.stub(weight: 3)
142
+ response_two.stub(weight: 1)
143
+ expect( weather.temperature ).to eq Data::Temperature.new(:metric, 22.5)
246
144
  end
247
145
 
248
- end
249
-
250
- describe "for visibility" do
251
-
252
- before(:each) do
253
- @weather.source(:wunderground).current.visibility = Data::Distance.new
254
- @weather.source(:wunderground).current.visibility.km = 10
255
- @weather.source(:yahoo).current.visibility = Data::Distance.new
256
- @weather.source(:yahoo).current.visibility.km = 6
146
+ it "respects response units" do
147
+ response_two.current.stub(temperature: Data::Temperature.new(:imperial, 68.0))
148
+ expect( weather.temperature.to_f ).to eq 20.0
257
149
  end
258
150
 
259
- it "returns averages" do
260
- @weather.visibility.km.should == 8
261
- end
151
+ it "respects weather units" do
152
+ weather = Weather.new(:imperial)
153
+ weather.responses = [response_one, response_two]
262
154
 
263
- it "returns default when disabled" do
264
- @weather.visibility(false).km.should == 10
155
+ expect( weather.temperature.to_f ).to eq 77.0
265
156
  end
266
-
267
- end
268
-
269
- end
270
-
271
- describe "when answering the simple questions," do
272
-
273
- before(:each) do
274
- @weather = Barometer::Weather.new
275
- @now = Data::LocalDateTime.parse("2:05 pm")
276
157
  end
277
158
 
278
- describe "windy?" do
159
+ describe "#humidity" do
160
+ let(:response_one) { fake_response(humidity: 20.0) }
161
+ let(:response_two) { fake_response(humidity: 30.0) }
279
162
 
280
- # it "requires time as a Data::LocalTime object" do
281
- # #lambda { @weather.windy?(1,"a") }.should raise_error(ArgumentError)
282
- # lambda { @weather.windy?(1,@now) }.should_not raise_error(ArgumentError)
283
- # end
163
+ before { weather.responses = [response_one, response_two] }
284
164
 
285
- it "requires threshold as a number" do
286
- lambda { @weather.windy?(@now,"a") }.should raise_error(ArgumentError)
287
- lambda { @weather.windy?(@now,1) }.should_not raise_error(ArgumentError)
288
- lambda { @weather.windy?(@now,1.1) }.should_not raise_error(ArgumentError)
165
+ it "returns an average humidity" do
166
+ expect( weather.humidity ).to eq 25.0
289
167
  end
290
168
 
291
- it "returns nil when no measurements" do
292
- @weather.measurements.should be_empty
293
- @weather.windy?.should be_nil
169
+ it "returns nil when there is no valid data" do
170
+ response_one.stub(success?: false)
171
+ response_two.stub(success?: false)
172
+ expect( weather.humidity ).to be_nil
294
173
  end
295
174
 
296
- it "returns true if a measurement returns true" do
297
- wunderground = Barometer::Measurement.new(:wunderground)
298
- wunderground.stub!(:success).and_return(true)
299
- wunderground.stub!(:success?).and_return(true)
300
- @weather.measurements << wunderground
301
- @weather.measurements.each { |m| m.stub!(:windy?).and_return(true) }
302
- @weather.windy?.should be_true
175
+ it "excludes unsuccessful responses" do
176
+ response_three = fake_response(success?: false, humidity: 10.0)
177
+ weather.responses << response_three
178
+ expect( weather.humidity ).to eq 25.0
303
179
  end
304
180
 
305
- it "returns false if a measurement returns false" do
306
- wunderground = Barometer::Measurement.new(:wunderground)
307
- wunderground.stub!(:success).and_return(true)
308
- wunderground.stub!(:success?).and_return(true)
309
- @weather.measurements << wunderground
310
- @weather.measurements.each { |m| m.stub!(:windy?).and_return(false) }
311
- @weather.windy?.should be_false
181
+ it "excludes nil values" do
182
+ response_three = fake_response(humidity: nil)
183
+ weather.responses << response_three
184
+ expect( weather.humidity ).to eq 25.0
312
185
  end
313
186
 
187
+ it "returns a weighted average humidity" do
188
+ response_one.stub(weight: 3)
189
+ response_two.stub(weight: 1)
190
+ expect( weather.humidity ).to eq 22.5
191
+ end
314
192
  end
315
193
 
316
- describe "wet?" do
194
+ describe "#dew_point" do
195
+ let(:response_one) { fake_response(dew_point: Data::Temperature.new(:metric, 20)) }
196
+ let(:response_two) { fake_response(dew_point: Data::Temperature.new(:metric, 30)) }
317
197
 
318
- it "requires threshold as a number" do
319
- lambda { @weather.wet?(@now,"a") }.should raise_error(ArgumentError)
320
- lambda { @weather.wet?(@now,1) }.should_not raise_error(ArgumentError)
321
- lambda { @weather.wet?(@now,1.1) }.should_not raise_error(ArgumentError)
322
- end
323
-
324
- # it "requires time as a Data::LocalTime object" do
325
- # #lambda { @weather.wet?(1,"a") }.should raise_error(ArgumentError)
326
- # lambda { @weather.wet?(1,@now) }.should_not raise_error(ArgumentError)
327
- # end
198
+ before { weather.responses = [response_one, response_two] }
328
199
 
329
- it "returns nil when no measurements" do
330
- @weather.measurements.should be_empty
331
- @weather.wet?.should be_nil
200
+ it "returns an average dew_point" do
201
+ expect( weather.dew_point ).to eq Data::Temperature.new(:metric, 25.0)
332
202
  end
203
+ end
333
204
 
334
- it "returns true if a measurement returns true" do
335
- wunderground = Barometer::Measurement.new(:wunderground)
336
- wunderground.stub!(:success).and_return(true)
337
- wunderground.stub!(:success?).and_return(true)
338
- @weather.measurements << wunderground
339
- @weather.measurements.each { |m| m.stub!(:wet?).and_return(true) }
340
- @weather.wet?.should be_true
341
- end
205
+ describe "#heat_index" do
206
+ let(:response_one) { fake_response(heat_index: Data::Temperature.new(:metric, 20)) }
207
+ let(:response_two) { fake_response(heat_index: Data::Temperature.new(:metric, 30)) }
342
208
 
343
- it "returns false if a measurement returns false" do
344
- wunderground = Barometer::Measurement.new(:wunderground)
345
- wunderground.stub!(:success).and_return(true)
346
- wunderground.stub!(:success?).and_return(true)
347
- @weather.measurements << wunderground
348
- @weather.measurements.each { |m| m.stub!(:wet?).and_return(false) }
349
- @weather.wet?.should be_false
350
- end
209
+ before { weather.responses = [response_one, response_two] }
351
210
 
211
+ it "returns an average heat_index" do
212
+ expect( weather.heat_index ).to eq Data::Temperature.new(:metric, 25.0)
213
+ end
352
214
  end
353
215
 
354
- describe "day? and night?" do
216
+ describe "#wind_chill" do
217
+ let(:response_one) { fake_response(wind_chill: Data::Temperature.new(:metric, 20)) }
218
+ let(:response_two) { fake_response(wind_chill: Data::Temperature.new(:metric, 30)) }
355
219
 
356
- it "requires time as a Data::LocalTime object" do
357
- #lambda { @weather.day?("a") }.should raise_error(ArgumentError)
358
- lambda { @weather.day?(@now) }.should_not raise_error(ArgumentError)
359
- end
220
+ before { weather.responses = [response_one, response_two] }
360
221
 
361
- it "requires time as a Data::LocalTime object" do
362
- #lambda { @weather.night?("a") }.should raise_error(ArgumentError)
363
- lambda { @weather.night?(@now) }.should_not raise_error(ArgumentError)
222
+ it "returns an average wind_chill" do
223
+ expect( weather.wind_chill ).to eq Data::Temperature.new(:metric, 25.0)
364
224
  end
225
+ end
365
226
 
366
- it "returns nil when no measurements" do
367
- @weather.measurements.should be_empty
368
- @weather.day?.should be_nil
369
- @weather.night?.should be_nil
370
- end
227
+ describe "#pressure" do
228
+ let(:response_one) { fake_response(pressure: Data::Pressure.new(:metric, 20)) }
229
+ let(:response_two) { fake_response(pressure: Data::Pressure.new(:metric, 30)) }
371
230
 
372
- it "returns true if a measurement returns true (night is opposite)" do
373
- wunderground = Barometer::Measurement.new(:wunderground)
374
- wunderground.stub!(:success).and_return(true)
375
- wunderground.stub!(:success?).and_return(true)
376
- @weather.measurements << wunderground
377
- @weather.measurements.each { |m| m.stub!(:day?).and_return(true) }
378
- @weather.day?.should be_true
379
- @weather.night?.should be_false
380
- end
231
+ before { weather.responses = [response_one, response_two] }
381
232
 
382
- it "returns false if a measurement returns false (night is opposite)" do
383
- wunderground = Barometer::Measurement.new(:wunderground)
384
- wunderground.stub!(:success).and_return(true)
385
- wunderground.stub!(:success?).and_return(true)
386
- @weather.measurements << wunderground
387
- @weather.measurements.each { |m| m.stub!(:day?).and_return(false) }
388
- @weather.day?.should be_false
389
- @weather.night?.should be_true
233
+ it "returns an average pressure" do
234
+ expect( weather.pressure ).to eq Data::Pressure.new(:metric, 25.0)
390
235
  end
391
-
392
236
  end
393
237
 
394
- describe "sunny?" do
238
+ describe "#visibility" do
239
+ let(:response_one) { fake_response(visibility: Data::Distance.new(:metric, 20)) }
240
+ let(:response_two) { fake_response(visibility: Data::Distance.new(:metric, 30)) }
395
241
 
396
- it "requires time as a Data::LocalTime object" do
397
- #lambda { @weather.sunny?("a") }.should raise_error(ArgumentError)
398
- lambda { @weather.sunny?(@now) }.should_not raise_error(ArgumentError)
399
- end
242
+ before { weather.responses = [response_one, response_two] }
400
243
 
401
- it "returns nil when no measurements" do
402
- @weather.measurements.should be_empty
403
- @weather.sunny?.should be_nil
244
+ it "returns an average visibility" do
245
+ expect( weather.visibility ).to eq Data::Distance.new(:metric, 25.0)
404
246
  end
247
+ end
405
248
 
406
- it "returns true if a measurement returns true" do
407
- wunderground = Barometer::Measurement.new(:wunderground)
408
- wunderground.stub!(:success).and_return(true)
409
- wunderground.stub!(:success?).and_return(true)
410
- @weather.measurements << wunderground
411
- @weather.measurements.each { |m| m.stub!(:day?).and_return(true) }
412
- @weather.measurements.each { |m| m.stub!(:sunny?).and_return(true) }
413
- @weather.sunny?.should be_true
414
- end
249
+ describe "#wind" do
250
+ let(:response_one) { fake_response(wind: Data::Vector.new(:metric, 20)) }
251
+ let(:response_two) { fake_response(wind: Data::Vector.new(:metric, 30)) }
415
252
 
416
- it "returns false if a measurement returns false" do
417
- wunderground = Barometer::Measurement.new(:wunderground)
418
- wunderground.stub!(:success).and_return(true)
419
- wunderground.stub!(:success?).and_return(true)
420
- @weather.measurements << wunderground
421
- @weather.measurements.each { |m| m.stub!(:day?).and_return(true) }
422
- @weather.measurements.each { |m| m.stub!(:sunny?).and_return(false) }
423
- @weather.sunny?.should be_false
424
- end
253
+ before { weather.responses = [response_one, response_two] }
425
254
 
426
- it "returns false if night time" do
427
- wunderground = Barometer::Measurement.new(:wunderground)
428
- wunderground.stub!(:success).and_return(true)
429
- wunderground.stub!(:success?).and_return(true)
430
- @weather.measurements << wunderground
431
- @weather.measurements.each { |m| m.stub!(:sunny?).and_return(true) }
432
- @weather.measurements.each { |m| m.stub!(:day?).and_return(false) }
433
- @weather.sunny?.should be_false
255
+ it "returns an average wind" do
256
+ expect( weather.wind ).to eq Data::Vector.new(:metric, 25.0)
434
257
  end
435
-
436
258
  end
437
-
438
259
  end
439
-
440
260
  end