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,150 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Barometer::Measurement::ResultArray do
4
- describe "instance methods" do
5
- before(:each) do
6
- @array = Barometer::Measurement::ResultArray.new
7
- end
8
-
9
- describe "'<<'" do
10
- it "requires Barometer::Measurement::Result" do
11
- lambda { @array << "invalid" }.should raise_error(ArgumentError)
12
- end
13
-
14
- it "adds ForecastMeasurement" do
15
- @array.size.should == 0
16
- forecast = Barometer::Measurement::Result.new
17
- @array << forecast
18
- @array.size.should == 1
19
- end
20
- end
21
-
22
- describe "when searching forecasts using 'for'" do
23
- before(:each) do
24
- 1.upto(4) do |i|
25
- forecast_measurement = Barometer::Measurement::Result.new
26
- forecast_measurement.date = Date.parse((Time.now + (i * 60 * 60 * 24)).to_s)
27
- @array << forecast_measurement
28
- end
29
- @array.size.should == 4
30
-
31
- @tommorrow = (Time.now + (60 * 60 * 24))
32
- end
33
-
34
- it "returns nil when there are no forecasts" do
35
- @array = Barometer::Measurement::ResultArray.new
36
- @array.size.should == 0
37
- @array.for(@tommorrow).should be_nil
38
- end
39
-
40
- it "finds the date using a String" do
41
- tommorrow = @tommorrow.to_s
42
- tommorrow.class.should == String
43
- @array.for(tommorrow).should == @array.first
44
- end
45
-
46
- it "finds the date using a Date" do
47
- tommorrow = Date.parse(@tommorrow.to_s)
48
- tommorrow.class.should == Date
49
- @array.for(tommorrow).should == @array.first
50
- end
51
-
52
- it "finds the date using a DateTime" do
53
- tommorrow = DateTime.parse(@tommorrow.to_s)
54
- tommorrow.class.should == DateTime
55
- @array.for(tommorrow).should == @array.first
56
- end
57
-
58
- it "finds the date using a Time" do
59
- @tommorrow.class.should == Time
60
- @array.for(@tommorrow).should == @array.first
61
- end
62
-
63
- it "finds the date using Data::LocalDateTime" do
64
- tommorrow = Data::LocalDateTime.parse(@tommorrow.to_s)
65
- tommorrow.class.should == Data::LocalDateTime
66
- @array.for(tommorrow).should == @array.first
67
- end
68
-
69
- it "finds nothing when there is not a match" do
70
- yesterday = (Time.now - (60 * 60 * 24))
71
- yesterday.class.should == Time
72
- @array.for(yesterday).should be_nil
73
- end
74
-
75
- it "finds using '[]'" do
76
- tommorrow = @tommorrow.to_s
77
- tommorrow.class.should == String
78
- @array[tommorrow].should == @array.first
79
- end
80
- end
81
- end
82
-
83
- describe "simple questions" do
84
- before(:each) do
85
- @array = Barometer::Measurement::ResultArray.new
86
- @now = Time.utc(2009,5,5,10,30,25)
87
-
88
- @sun_icons = %w(sunny)
89
-
90
- 0.upto(1) do |i|
91
- forecast_measurement = Barometer::Measurement::Result.new
92
- forecast_measurement.date = Date.parse((@now + (i * 60 * 60 * 24)).to_s)
93
- wind = Data::Speed.new
94
- wind << (i * 5)
95
- forecast_measurement.wind = wind
96
- forecast_measurement.sun = Data::Sun.new(
97
- Data::LocalTime.parse("9:00 am"), Data::LocalTime.parse("3:00 pm"))
98
- forecast_measurement.icon = "sunny"
99
- forecast_measurement.pop = 40
100
- forecast_measurement.humidity = 95
101
- @array << forecast_measurement
102
- end
103
- @array.size.should == 2
104
- @tommorrow = (@now + (60 * 60 * 24))
105
- @yesterday = (@now - (60 * 60 * 24))
106
- @earlier = (@now - (60 * 60 * 3))
107
- @later = (@now + (60 * 60 * 6))
108
- end
109
-
110
- it "answers windy?" do
111
- @array.windy?(@tommorrow).should be_false
112
- @array.windy?(@tommorrow,1).should be_true
113
- @array.windy?(@yesterday).should be_nil
114
- end
115
-
116
- it "answers day?" do
117
- @array.day?(@yesterday).should be_nil
118
- @array.day?(@earlier).should be_false
119
- @array.day?(@later).should be_false
120
- @array.day?(@tommorrow).should be_true
121
- @array.day?(@now).should be_true
122
- end
123
-
124
- it "answers sunny?" do
125
- @array.sunny?(@tommorrow,%w(rain)).should be_false
126
- @array.sunny?(@tommorrow,@sun_icons).should be_true
127
- @array.sunny?(@yesterday).should be_nil
128
- end
129
-
130
- describe "wet?" do
131
- it "answers via pop" do
132
- @array.wet?(@tommorrow).should be_false
133
- @array.wet?(@tommorrow,nil,50).should be_false
134
- @array.wet?(@tommorrow,nil,30).should be_true
135
- end
136
-
137
- it "answers via humidity" do
138
- @array.wet?(@tommorrow).should be_false
139
- @array.wet?(@tommorrow,nil,50,99).should be_false
140
- @array.wet?(@tommorrow,nil,50,90).should be_true
141
- end
142
-
143
- it "answers via icon" do
144
- @array.wet?(@tommorrow,%w(rain)).should be_false
145
- # pretend that "sun" means wet
146
- @array.wet?(@tommorrow,@sun_icons).should be_true
147
- end
148
- end
149
- end
150
- end
@@ -1,632 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Barometer::Measurement::Result do
4
- describe "when initialized" do
5
- before(:each) do
6
- @result = Barometer::Measurement::Result.new
7
- end
8
-
9
- it "responds to temperature" do
10
- @result.temperature.should be_nil
11
- end
12
-
13
- it "responds to dew_point" do
14
- @result.dew_point.should be_nil
15
- end
16
-
17
- it "responds to heat_index" do
18
- @result.heat_index.should be_nil
19
- end
20
-
21
- it "responds to wind_chill" do
22
- @result.wind_chill.should be_nil
23
- end
24
-
25
- it "responds to pressure" do
26
- @result.pressure.should be_nil
27
- end
28
-
29
- it "responds to visibility" do
30
- @result.pressure.should be_nil
31
- end
32
-
33
- it "responds to current_at" do
34
- @result.current_at.should be_nil
35
- end
36
-
37
- it "responds to updated_at" do
38
- @result.updated_at.should be_nil
39
- end
40
-
41
- it "responds to date" do
42
- @result.date.should be_nil
43
- end
44
-
45
- it "responds to low" do
46
- @result.low.should be_nil
47
- end
48
-
49
- it "responds to high" do
50
- @result.high.should be_nil
51
- end
52
-
53
- it "responds to pop" do
54
- @result.pop.should be_nil
55
- end
56
-
57
- it "responds to valid_start_date" do
58
- @result.valid_start_date.should be_nil
59
- end
60
-
61
- it "responds to valid_end_date" do
62
- @result.valid_end_date.should be_nil
63
- end
64
-
65
- it "responds to description" do
66
- @result.description.should be_nil
67
- end
68
-
69
- it "responds to humidity" do
70
- @result.humidity.should be_nil
71
- end
72
-
73
- it "responds to icon" do
74
- @result.icon.should be_nil
75
- end
76
-
77
- it "responds to condition" do
78
- @result.condition.should be_nil
79
- end
80
-
81
- it "responds to wind" do
82
- @result.wind.should be_nil
83
- end
84
-
85
- it "responds to sun" do
86
- @result.sun.should be_nil
87
- end
88
-
89
- it "responds to metric" do
90
- @result.metric.should be_true
91
- end
92
-
93
- it "responds to metric?" do
94
- @result.metric?.should be_true
95
- @result.metric = false
96
- @result.metric?.should be_false
97
- end
98
- end
99
-
100
- describe "when writing data" do
101
- before(:each) do
102
- @result = Barometer::Measurement::Result.new
103
- end
104
-
105
- it "only accepts Data::Temperature for temperature" do
106
- invalid_data = 1
107
- invalid_data.class.should_not == Data::Temperature
108
- lambda { @result.temperature = invalid_data }.should raise_error(ArgumentError)
109
-
110
- valid_data = Data::Temperature.new
111
- valid_data.class.should == Data::Temperature
112
- lambda { @result.temperature = valid_data }.should_not raise_error(ArgumentError)
113
- end
114
-
115
- it "only accepts Data::Temperature for dew_point" do
116
- invalid_data = 1
117
- invalid_data.class.should_not == Data::Temperature
118
- lambda { @result.dew_point = invalid_data }.should raise_error(ArgumentError)
119
-
120
- valid_data = Data::Temperature.new
121
- valid_data.class.should == Data::Temperature
122
- lambda { @result.dew_point = valid_data }.should_not raise_error(ArgumentError)
123
- end
124
-
125
- it "only accepts Data::Temperature for heat_index" do
126
- invalid_data = 1
127
- invalid_data.class.should_not == Data::Temperature
128
- lambda { @result.heat_index = invalid_data }.should raise_error(ArgumentError)
129
-
130
- valid_data = Data::Temperature.new
131
- valid_data.class.should == Data::Temperature
132
- lambda { @result.heat_index = valid_data }.should_not raise_error(ArgumentError)
133
- end
134
-
135
- it "only accepts Data::Temperature for wind_chill" do
136
- invalid_data = 1
137
- invalid_data.class.should_not == Data::Temperature
138
- lambda { @result.wind_chill = invalid_data }.should raise_error(ArgumentError)
139
-
140
- valid_data = Data::Temperature.new
141
- valid_data.class.should == Data::Temperature
142
- lambda { @result.wind_chill = valid_data }.should_not raise_error(ArgumentError)
143
- end
144
-
145
- it "only accepts Data::Pressure for pressure" do
146
- invalid_data = 1
147
- invalid_data.class.should_not == Data::Pressure
148
- lambda { @result.pressure = invalid_data }.should raise_error(ArgumentError)
149
-
150
- valid_data = Data::Pressure.new
151
- valid_data.class.should == Data::Pressure
152
- lambda { @result.pressure = valid_data }.should_not raise_error(ArgumentError)
153
- end
154
-
155
- it "only accepts Data::Distance for visibility" do
156
- invalid_data = 1
157
- invalid_data.class.should_not == Data::Distance
158
- lambda { @result.visibility = invalid_data }.should raise_error(ArgumentError)
159
-
160
- valid_data = Data::Distance.new
161
- valid_data.class.should == Data::Distance
162
- lambda { @result.visibility = valid_data }.should_not raise_error(ArgumentError)
163
- end
164
-
165
- it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
166
- invalid_data = 1
167
- invalid_data.class.should_not == Data::LocalTime
168
- invalid_data.class.should_not == Data::LocalDateTime
169
- lambda { @result.current_at = invalid_data }.should raise_error(ArgumentError)
170
-
171
- valid_data = Data::LocalTime.new
172
- valid_data.class.should == Data::LocalTime
173
- lambda { @result.current_at = valid_data }.should_not raise_error(ArgumentError)
174
-
175
- valid_data = Data::LocalDateTime.new(2009,1,1)
176
- valid_data.class.should == Data::LocalDateTime
177
- lambda { @result.current_at = valid_data }.should_not raise_error(ArgumentError)
178
- end
179
-
180
- it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
181
- invalid_data = 1
182
- invalid_data.class.should_not == Data::LocalTime
183
- invalid_data.class.should_not == Data::LocalDateTime
184
- lambda { @result.updated_at = invalid_data }.should raise_error(ArgumentError)
185
-
186
- valid_data = Data::LocalTime.new
187
- valid_data.class.should == Data::LocalTime
188
- lambda { @result.updated_at = valid_data }.should_not raise_error(ArgumentError)
189
-
190
- valid_data = Data::LocalDateTime.new(2009,1,1)
191
- valid_data.class.should == Data::LocalDateTime
192
- lambda { @result.updated_at = valid_data }.should_not raise_error(ArgumentError)
193
- end
194
-
195
- it "only accepts Date for date" do
196
- invalid_data = 1
197
- invalid_data.class.should_not == Date
198
- lambda { @result.date = invalid_data }.should raise_error(ArgumentError)
199
-
200
- valid_data = Date.new
201
- valid_data.class.should == Date
202
- lambda { @result.date = valid_data }.should_not raise_error(ArgumentError)
203
- end
204
-
205
- it "only accepts Data::Temperature for high" do
206
- invalid_data = 1
207
- invalid_data.class.should_not == Data::Temperature
208
- lambda { @result.high = invalid_data }.should raise_error(ArgumentError)
209
-
210
- valid_data = Data::Temperature.new
211
- valid_data.class.should == Data::Temperature
212
- lambda { @result.high = valid_data }.should_not raise_error(ArgumentError)
213
- end
214
-
215
- it "only accepts Data::Temperature for low" do
216
- invalid_data = 1
217
- invalid_data.class.should_not == Data::Temperature
218
- lambda { @result.low = invalid_data }.should raise_error(ArgumentError)
219
-
220
- valid_data = Data::Temperature.new
221
- valid_data.class.should == Data::Temperature
222
- lambda { @result.low = valid_data }.should_not raise_error(ArgumentError)
223
- end
224
-
225
- it "only accepts Fixnum for pop" do
226
- invalid_data = "test"
227
- invalid_data.class.should_not == Fixnum
228
- lambda { @result.pop = invalid_data }.should raise_error(ArgumentError)
229
-
230
- valid_data = 50
231
- valid_data.class.should == Fixnum
232
- lambda { @result.pop = valid_data }.should_not raise_error(ArgumentError)
233
- end
234
-
235
- it "only accepts Data::LocalDateTime for valid_start_date" do
236
- invalid_data = 1
237
- invalid_data.class.should_not == Data::LocalDateTime
238
- lambda { @result.valid_start_date = invalid_data }.should raise_error(ArgumentError)
239
-
240
- valid_data = Data::LocalDateTime.new(2009,1,1)
241
- valid_data.class.should == Data::LocalDateTime
242
- lambda { @result.valid_start_date = valid_data }.should_not raise_error(ArgumentError)
243
- end
244
-
245
- it "only accepts Data::LocalDateTime for valid_end_date" do
246
- invalid_data = 1
247
- invalid_data.class.should_not == Data::LocalDateTime
248
- lambda { @result.valid_end_date = invalid_data }.should raise_error(ArgumentError)
249
-
250
- valid_data = Data::LocalDateTime.new(2009,1,1)
251
- valid_data.class.should == Data::LocalDateTime
252
- lambda { @result.valid_end_date = valid_data }.should_not raise_error(ArgumentError)
253
- end
254
-
255
- it "sets valid_start_date and valid_end_date if given date" do
256
- forecast = Barometer::Measurement::Result.new
257
- forecast.valid_start_date.should be_nil
258
- forecast.valid_end_date.should be_nil
259
- date = Date.new(2009,05,05)
260
- forecast.date = date
261
- forecast.valid_start_date.should_not be_nil
262
- forecast.valid_start_date.year.should == date.year
263
- forecast.valid_start_date.month.should == date.month
264
- forecast.valid_start_date.day.should == date.day
265
- forecast.valid_start_date.hour.should == 0
266
- forecast.valid_start_date.min.should == 0
267
- forecast.valid_start_date.sec.should == 0
268
-
269
- forecast.valid_end_date.should_not be_nil
270
- forecast.valid_end_date.year.should == date.year
271
- forecast.valid_end_date.month.should == date.month
272
- forecast.valid_end_date.day.should == date.day
273
- forecast.valid_end_date.hour.should == 23
274
- forecast.valid_end_date.min.should == 59
275
- forecast.valid_end_date.sec.should == 59
276
- end
277
-
278
- it "returns true if the valid_date range includes the given date" do
279
- forecast = Barometer::Measurement::Result.new
280
- forecast.date = Date.new(2009,05,05)
281
- forecast.for_datetime?(Data::LocalDateTime.new(2009,5,5,12,0,0)).should be_true
282
- end
283
-
284
- it "returns false if the valid_date range excludes the given date" do
285
- forecast = Barometer::Measurement::Result.new
286
- forecast.date = Date.new(2009,05,05)
287
- forecast.for_datetime?(Data::LocalDateTime.new(2009,5,4,12,0,0)).should be_false
288
- end
289
-
290
- it "only accepts Fixnum or Float for humidity" do
291
- invalid_data = "invalid"
292
- invalid_data.class.should_not == Fixnum
293
- invalid_data.class.should_not == Float
294
- lambda { @result.humidity = invalid_data }.should raise_error(ArgumentError)
295
-
296
- valid_data = 1.to_i
297
- valid_data.class.should == Fixnum
298
- lambda { @result.humidity = valid_data }.should_not raise_error(ArgumentError)
299
-
300
- valid_data = 1.0.to_f
301
- valid_data.class.should == Float
302
- lambda { @result.humidity = valid_data }.should_not raise_error(ArgumentError)
303
- end
304
-
305
- it "only accepts String for icon" do
306
- invalid_data = 1
307
- invalid_data.class.should_not == String
308
- lambda { @result.icon = invalid_data }.should raise_error(ArgumentError)
309
-
310
- valid_data = "valid"
311
- valid_data.class.should == String
312
- lambda { @result.icon = valid_data }.should_not raise_error(ArgumentError)
313
- end
314
-
315
- it "only accepts String for condition" do
316
- invalid_data = 1
317
- invalid_data.class.should_not == String
318
- lambda { @result.condition = invalid_data }.should raise_error(ArgumentError)
319
-
320
- valid_data = "valid"
321
- valid_data.class.should == String
322
- lambda { @result.condition = valid_data }.should_not raise_error(ArgumentError)
323
- end
324
-
325
- it "only accepts Data::Speed for wind" do
326
- invalid_data = 1
327
- invalid_data.class.should_not == Data::Speed
328
- lambda { @result.wind = invalid_data }.should raise_error(ArgumentError)
329
-
330
- valid_data = Data::Speed.new
331
- valid_data.class.should == Data::Speed
332
- lambda { @result.wind = valid_data }.should_not raise_error(ArgumentError)
333
- end
334
-
335
- it "only accepts Data::Sun for sun" do
336
- invalid_data = 1
337
- invalid_data.class.should_not == Data::Sun
338
- lambda { @result.sun = invalid_data }.should raise_error(ArgumentError)
339
-
340
- valid_data = Data::Sun.new
341
- valid_data.class.should == Data::Sun
342
- lambda { @result.sun = valid_data }.should_not raise_error(ArgumentError)
343
- end
344
- end
345
-
346
- describe "method missing" do
347
- before(:each) do
348
- @result = Barometer::Measurement::Result.new
349
- end
350
-
351
- it "responds to method + ?" do
352
- valid_method = "humidity"
353
- @result.respond_to?(valid_method).should be_true
354
- lambda { @result.send(valid_method + "?") }.should_not raise_error(NoMethodError)
355
- end
356
-
357
- it "ignores non_method + ?" do
358
- invalid_method = "humid"
359
- @result.respond_to?(invalid_method).should be_false
360
- lambda { @result.send(invalid_method + "?") }.should raise_error(NoMethodError)
361
- end
362
-
363
- it "returns true if set" do
364
- @result.humidity = 10
365
- @result.humidity.should_not be_nil
366
- @result.humidity?.should be_true
367
- end
368
-
369
- it "returns false if not set" do
370
- @result.humidity.should be_nil
371
- @result.humidity?.should be_false
372
- end
373
- end
374
-
375
- describe "answer simple questions, like" do
376
- before(:each) do
377
- @result = Barometer::Measurement::Result.new
378
- @result.temperature = Data::Temperature.new
379
- @result.temperature << 5
380
- @dew_point = Data::Temperature.new
381
- @dew_point << 10
382
- end
383
-
384
- describe "windy?" do
385
- before(:each) do
386
- @wind = Data::Speed.new
387
- @wind << 11
388
- end
389
-
390
- it "requires real threshold number (or nil)" do
391
- lambda { @result.windy?("invalid") }.should raise_error(ArgumentError)
392
- lambda { @result.windy? }.should_not raise_error(ArgumentError)
393
- lambda { @result.windy?(10) }.should_not raise_error(ArgumentError)
394
- end
395
-
396
- it "returns nil when no wind" do
397
- @result.wind?.should be_false
398
- @result.windy?.should be_nil
399
- @result.wind = @wind
400
- @result.wind?.should be_true
401
- @result.windy?.should_not be_nil
402
- end
403
-
404
- it "return true when current wind over threshold" do
405
- @result.wind = @wind
406
- @result.windy?.should be_true
407
- @result.windy?(10).should be_true
408
- end
409
-
410
- it "return false when current wind under threshold" do
411
- @result.wind = @wind
412
- @result.windy?(15).should be_false
413
- end
414
- end
415
-
416
- describe "day?" do
417
- before(:each) do
418
- @early_time = Data::LocalTime.parse("6:00 am")
419
- @mid_time = Data::LocalTime.parse("11:00 am")
420
- @late_time = Data::LocalTime.parse("8:00 pm")
421
- @sun = Data::Sun.new(@early_time, @late_time)
422
-
423
- end
424
-
425
- it "requires Data::LocalTime object" do
426
- @result.sun = @sun
427
- lambda { @result.day?("invalid") }.should raise_error(ArgumentError)
428
- lambda { @result.day? }.should raise_error(ArgumentError)
429
- lambda { @result.day?(@mid_time) }.should_not raise_error(ArgumentError)
430
- end
431
-
432
- it "returns nil when no sun" do
433
- @result.sun?.should be_false
434
- @result.day?(@mid_time).should be_nil
435
- @result.sun = @sun
436
- @result.sun?.should be_true
437
- @result.day?(@mid_time).should_not be_nil
438
- end
439
-
440
- it "return true when time between rise and set" do
441
- @result.sun = @sun
442
- @result.day?(@mid_time).should be_true
443
- end
444
-
445
- it "return false when time before rise or after set" do
446
- sun = Data::Sun.new(@mid_time, @late_time)
447
- @result.sun = sun
448
- @result.day?(@early_time).should be_false
449
-
450
- sun = Data::Sun.new(@early_time, @mid_time)
451
- @result.sun = sun
452
- @result.day?(@late_time).should be_false
453
- end
454
- end
455
-
456
- describe "wet?" do
457
- describe "wet_by_humidity?" do
458
- it "requires real threshold number (or nil)" do
459
- lambda { @result.send("_wet_by_humidity?","invalid") }.should raise_error(ArgumentError)
460
- lambda { @result.send("_wet_by_humidity?") }.should_not raise_error(ArgumentError)
461
- lambda { @result.send("_wet_by_humidity?",99) }.should_not raise_error(ArgumentError)
462
- end
463
-
464
- it "returns nil when no humidity" do
465
- @result.humidity?.should be_false
466
- @result.send("_wet_by_humidity?").should be_nil
467
- @result.wet?(nil,99).should be_nil
468
- @result.humidity = 100
469
- @result.humidity?.should be_true
470
- @result.send("_wet_by_humidity?").should_not be_nil
471
- @result.wet?(nil,99).should_not be_nil
472
- end
473
-
474
- it "return true when current humidity over threshold" do
475
- @result.humidity = 100
476
- @result.send("_wet_by_humidity?").should be_true
477
- @result.send("_wet_by_humidity?",99).should be_true
478
- @result.wet?(nil,99).should be_true
479
- end
480
-
481
- it "return false when current humidity under threshold" do
482
- @result.humidity = 98
483
- @result.send("_wet_by_humidity?",99).should be_false
484
- @result.wet?(nil,99).should be_false
485
- end
486
- end
487
-
488
- describe "wet_by_icon?" do
489
- before(:each) do
490
- @wet_icons = %w(rain thunderstorm)
491
- end
492
-
493
- it "requires Array (or nil)" do
494
- lambda { @result.send("_wet_by_icon?","invalid") }.should raise_error(ArgumentError)
495
- lambda { @result.send("_wet_by_icon?") }.should_not raise_error(ArgumentError)
496
- lambda { @result.send("_wet_by_icon?",@wet_icons) }.should_not raise_error(ArgumentError)
497
- end
498
-
499
- it "returns nil when no icon or Array" do
500
- @result.icon?.should be_false
501
- @result.send("_wet_by_icon?",@wet_icons).should be_nil
502
- @result.wet?(@wet_icons).should be_nil
503
- @result.icon = "rain"
504
- @result.icon?.should be_true
505
- @result.send("_wet_by_icon?").should be_nil
506
- @result.send("_wet_by_icon?",@wet_icons).should_not be_nil
507
- @result.wet?(@wet_icons).should_not be_nil
508
- end
509
-
510
- it "return true when current icon indicates wet" do
511
- @result.icon = "rain"
512
- @result.send("_wet_by_icon?",@wet_icons).should be_true
513
- @result.wet?(@wet_icons).should be_true
514
- end
515
-
516
- it "return false when current icon does NOT indicate wet" do
517
- @result.icon = "sun"
518
- @result.send("_wet_by_icon?",@wet_icons).should be_false
519
- @result.wet?(@wet_icons).should be_false
520
- end
521
- end
522
-
523
- describe "wet_by_dewpoint?" do
524
- it "returns nil when no dewpoint" do
525
- @result.dew_point?.should be_false
526
- @result.send("_wet_by_dewpoint?").should be_nil
527
- @result.wet?.should be_nil
528
- @result.dew_point = @dew_point
529
- @result.dew_point?.should be_true
530
- @result.send("_wet_by_dewpoint?").should_not be_nil
531
- @result.wet?.should_not be_nil
532
- end
533
-
534
- it "return true when current dewpoint over temperature" do
535
- @result.dew_point = @dew_point
536
- @result.send("_wet_by_dewpoint?").should be_true
537
- @result.wet?.should be_true
538
- end
539
-
540
- it "return false when current dewpoint under temperature" do
541
- @result.temperature << 15
542
- @result.dew_point = @dew_point
543
- @result.send("_wet_by_dewpoint?").should be_false
544
- @result.wet?.should be_false
545
- end
546
- end
547
-
548
- describe "wet_by_pop?" do
549
- it "requires real threshold number (or nil)" do
550
- lambda { @result.send("_wet_by_pop?","invalid") }.should raise_error(ArgumentError)
551
- lambda { @result.send("_wet_by_pop?") }.should_not raise_error(ArgumentError)
552
- lambda { @result.send("_wet_by_pop?",50) }.should_not raise_error(ArgumentError)
553
- end
554
-
555
- it "returns nil when no pop" do
556
- @result.pop?.should be_false
557
- @result.send("_wet_by_pop?",50).should be_nil
558
- @result.wet?.should be_nil
559
- @result.pop = 60
560
- @result.pop?.should be_true
561
- @result.send("_wet_by_pop?",50).should_not be_nil
562
- @result.wet?.should_not be_nil
563
- end
564
-
565
- it "return true when current pop over threshold" do
566
- @result.pop = 60
567
- @result.send("_wet_by_pop?",50).should be_true
568
- @result.wet?.should be_true
569
- end
570
-
571
- it "return false when current pop under threshold" do
572
- @result.pop = 40
573
- @result.send("_wet_by_pop?",50).should be_false
574
- @result.wet?.should be_false
575
- end
576
- end
577
- end
578
-
579
- describe "sunny?" do
580
- describe "sunny_by_icon?" do
581
- before(:each) do
582
- @sunny_icons = %w(sunny clear)
583
- @early_time = Data::LocalTime.parse("6:00 am")
584
- @mid_time = Data::LocalTime.parse("11:00 am")
585
- @late_time = Data::LocalTime.parse("8:00 pm")
586
- @sun = Data::Sun.new(@early_time, @late_time)
587
-
588
- @result.sun = @sun
589
- end
590
-
591
- it "requires Array (or nil)" do
592
- lambda { @result.send("_sunny_by_icon?","invalid") }.should raise_error(ArgumentError)
593
- lambda { @result.send("_sunny_by_icon?") }.should_not raise_error(ArgumentError)
594
- lambda { @result.send("_sunny_by_icon?",@sunny_icons) }.should_not raise_error(ArgumentError)
595
- end
596
-
597
- it "returns nil when no icon or Array" do
598
- @result.icon?.should be_false
599
- @result.send("_sunny_by_icon?",@sunny_icons).should be_nil
600
- @result.sunny?(@mid_time,@sunny_icons).should be_nil
601
- @result.icon = "sunny"
602
- @result.icon?.should be_true
603
- @result.send("_sunny_by_icon?").should be_nil
604
- @result.send("_sunny_by_icon?",@sunny_icons).should_not be_nil
605
- @result.sun?(@mid_time,@sunny_icons).should_not be_nil
606
- end
607
-
608
- it "returns true when current icon indicates sunny" do
609
- @result.icon = "sunny"
610
- @result.send("_sunny_by_icon?",@sunny_icons).should be_true
611
- @result.sunny?(@mid_time,@sunny_icons).should be_true
612
- end
613
-
614
- it "returns false when current icon does NOT indicate sunny" do
615
- @result.icon = "rain"
616
- @result.send("_sunny_by_icon?",@sunny_icons).should be_false
617
- @result.sunny?(@mid_time,@sunny_icons).should be_false
618
- end
619
-
620
- it "returns false when night" do
621
- @result.icon = "sunny"
622
- @result.send("_sunny_by_icon?",@sunny_icons).should be_true
623
- @result.sunny?(@mid_time,@sunny_icons).should be_true
624
-
625
- @sun = Data::Sun.new(@mid_time, @late_time)
626
- @result.sun = @sun
627
- @result.sunny?(@early_time,@sunny_icons).should be_false
628
- end
629
- end
630
- end
631
- end
632
- end