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,102 +1,78 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require_relative '../spec_helper'
2
2
 
3
- describe "Data::Sun" do
3
+ module Barometer::Data
4
+ describe Sun do
5
+ let(:local_time_set) { Time.now + (60*60*8) }
6
+ let(:local_time_rise) { Time.now }
4
7
 
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @sun = Data::Sun.new
9
- @local_time_rise = Data::LocalTime.new.parse(Time.now)
10
- @local_time_set = Data::LocalTime.new.parse(Time.now + (60*60*8))
11
- end
12
-
13
- it "responds to rise" do
14
- @sun.respond_to?("rise").should be_true
15
- end
16
-
17
- it "responds to set" do
18
- @sun.respond_to?("set").should be_true
19
- end
20
-
21
- it "sets sunrise" do
22
- sun = Data::Sun.new(@local_time_rise,@local_time_set)
23
- sun.rise.should == @local_time_rise
24
- end
25
-
26
- it "sets sunset" do
27
- sun = Data::Sun.new(@local_time_rise,@local_time_set)
28
- sun.set.should == @local_time_set
29
- end
30
-
31
- it "requires Data::LocalTime for sunrise" do
32
- lambda { Data::Sun.new("",@local_time_set) }.should raise_error(ArgumentError)
33
- lambda { Data::Sun.new(@local_time_rise,@local_time_set) }.should_not raise_error(ArgumentError)
34
- end
35
-
36
- it "requires Data::LocalTime for sunset" do
37
- lambda { Data::Sun.new(@local_time_rise,"") }.should raise_error(ArgumentError)
38
- lambda { Data::Sun.new(@local_time_rise,@local_time_set) }.should_not raise_error(ArgumentError)
39
- end
40
-
41
- it "responds to nil?" do
42
- @sun.nil?.should be_true
43
- sun = Data::Sun.new(@local_time_rise, @local_time_set)
44
- sun.nil?.should be_false
45
- end
46
-
47
- end
8
+ describe '#nil?' do
9
+ it 'returns true if nothing is set' do
10
+ sun = Sun.new(rise: nil, set: nil)
11
+ expect( sun ).to be_nil
12
+ end
48
13
 
49
- describe "comparisons" do
14
+ it 'returns false if sunrise is set' do
15
+ sun = Sun.new(rise: local_time_rise, set: nil)
16
+ expect( sun ).not_to be_nil
17
+ end
50
18
 
51
- before(:each) do
52
- now = Time.local(2009,5,5,11,40,00)
53
- @mid_time = Data::LocalTime.new.parse(now)
54
- @early_time = Data::LocalTime.new.parse(now - (60*60*8))
55
- @late_time = Data::LocalTime.new.parse(now + (60*60*8))
19
+ it 'returns false if sunset is set' do
20
+ sun = Sun.new(rise: nil, set: local_time_set)
21
+ expect( sun ).not_to be_nil
22
+ end
56
23
  end
57
24
 
58
- describe "after_rise?" do
59
-
60
- it "requires a LocalTime object" do
61
- sun = Data::Sun.new(@early_time,@late_time)
62
- lambda { sun.after_rise? }.should raise_error(ArgumentError)
63
- lambda { sun.after_rise?("invalid") }.should raise_error(ArgumentError)
64
- lambda { sun.after_rise?(@mid_time) }.should_not raise_error(ArgumentError)
25
+ describe 'comparisons' do
26
+ let(:now) { Time.local(2009,5,5,11,40,00) }
27
+ let(:early_time) { now - (60*60*8) }
28
+ let(:mid_time) { now }
29
+ let(:late_time) { now + (60*60*8) }
30
+
31
+ describe '#after_rise?' do
32
+ it 'returns true when after sun rise' do
33
+ sun = Sun.new(rise: early_time, set: late_time)
34
+ expect( sun.after_rise?(mid_time) ).to be_true
35
+ end
36
+
37
+ it 'returns false when before sun rise' do
38
+ sun = Sun.new(rise: mid_time, set: late_time)
39
+ expect( sun.after_rise?(early_time) ).to be_false
40
+ end
65
41
  end
66
42
 
67
- it "returns true when after sun rise" do
68
- sun = Data::Sun.new(@early_time,@late_time)
69
- sun.after_rise?(@mid_time).should be_true
70
- end
43
+ describe '#before_set?' do
44
+ it 'returns true when before sun set' do
45
+ sun = Sun.new(rise: early_time, set: late_time)
46
+ expect( sun.before_set?(mid_time) ).to be_true
47
+ end
71
48
 
72
- it "returns false when before sun rise" do
73
- sun = Data::Sun.new(@mid_time,@late_time)
74
- sun.after_rise?(@early_time).should be_false
49
+ it 'returns false when before sun set' do
50
+ sun = Sun.new(rise: early_time, set: mid_time)
51
+ expect( sun.before_set?(late_time) ).to be_false
52
+ end
75
53
  end
76
-
77
54
  end
78
55
 
79
- describe "before_set?" do
80
-
81
- it "requires a LocalTime object" do
82
- sun = Data::Sun.new(@early_time,@late_time)
83
- lambda { sun.before_set? }.should raise_error(ArgumentError)
84
- lambda { sun.before_set?("invalid") }.should raise_error(ArgumentError)
85
- lambda { sun.before_set?(@mid_time) }.should_not raise_error(ArgumentError)
56
+ describe '#to_s' do
57
+ it 'defaults as blank' do
58
+ sun = Sun.new()
59
+ expect( sun.to_s ).to be_blank
86
60
  end
87
61
 
88
- it "returns true when before sun set" do
89
- sun = Data::Sun.new(@early_time,@late_time)
90
- sun.before_set?(@mid_time).should be_true
62
+ it 'returns the sunrise time' do
63
+ sun = Sun.new(rise: local_time_rise)
64
+ expect( sun.to_s ).to eq "rise: #{local_time_rise.strftime('%H:%M')}"
91
65
  end
92
66
 
93
- it "returns false when before sun set" do
94
- sun = Data::Sun.new(@early_time,@mid_time)
95
- sun.before_set?(@late_time).should be_false
67
+ it 'returns the sunset time' do
68
+ sun = Sun.new(rise: nil, set: local_time_set)
69
+ expect( sun.to_s ).to eq "set: #{local_time_set.strftime('%H:%M')}"
96
70
  end
97
71
 
72
+ it 'returns both times' do
73
+ sun = Sun.new(rise: local_time_rise, set: local_time_set)
74
+ expect( sun.to_s ).to eq "rise: #{local_time_rise.strftime('%H:%M')}, set: #{local_time_set.strftime('%H:%M')}"
75
+ end
98
76
  end
99
-
100
77
  end
101
-
102
78
  end
@@ -1,396 +1,52 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Data::Temperature" do
4
-
5
- describe "when initialized" do
6
-
7
- it "defines METRIC_UNITS" do
8
- Data::Temperature.const_defined?("METRIC_UNITS").should be_true
9
- Data::Temperature::METRIC_UNITS.should == "C"
10
- end
11
-
12
- it "defines IMPERIAL_UNITS" do
13
- Data::Temperature.const_defined?("IMPERIAL_UNITS").should be_true
14
- Data::Temperature::IMPERIAL_UNITS.should == "F"
15
- end
16
-
17
- before(:each) do
18
- @temp = Data::Temperature.new
19
- end
20
-
21
- it "responds to celcius" do
22
- @temp.celsius.should be_nil
23
- end
24
-
25
- it "responds to fahrenheit" do
26
- @temp.fahrenheit.should be_nil
27
- end
28
-
29
- it "responds to kelvin" do
30
- @temp.kelvin.should be_nil
31
- end
32
-
33
- it "responds to metric_default" do
34
- lambda { @temp.metric_default = 5 }.should_not raise_error(NotImplementedError)
35
- end
36
-
37
- it "responds to imperial_default" do
38
- lambda { @temp.imperial_default = 5 }.should_not raise_error(NotImplementedError)
39
- end
40
-
41
- it "responds to nil?" do
42
- @temp.nil?.should be_true
43
- @temp.c = 5
44
- @temp.nil?.should be_false
45
- end
46
-
47
- end
48
-
49
- describe "conversion" do
50
-
51
- # For all conversions
52
- # 20.0 C = 293.15 K = 68.0 F
53
- before(:each) do
54
- @f = 68.0
55
- @c = 20.0
56
- @k = 293.15
57
- end
58
-
59
- it "requires a value, that is either Integer or Float" do
60
- Data::Temperature.c_to_k(nil).should be_nil
61
- Data::Temperature.c_to_f(nil).should be_nil
62
- Data::Temperature.f_to_k(nil).should be_nil
63
- Data::Temperature.f_to_c(nil).should be_nil
64
- Data::Temperature.k_to_c(nil).should be_nil
65
- Data::Temperature.k_to_f(nil).should be_nil
66
-
67
- not_float_or_integer = "string"
68
- Data::Temperature.c_to_k(not_float_or_integer).should be_nil
69
- Data::Temperature.c_to_f(not_float_or_integer).should be_nil
70
- Data::Temperature.f_to_k(not_float_or_integer).should be_nil
71
- Data::Temperature.f_to_c(not_float_or_integer).should be_nil
72
- Data::Temperature.k_to_c(not_float_or_integer).should be_nil
73
- Data::Temperature.k_to_f(not_float_or_integer).should be_nil
74
- end
75
-
76
- it "converts C to K" do
77
- # 0 C = 273.15 K
78
- Data::Temperature.c_to_k(@c).should == @k
79
- end
80
-
81
- it "converts C to F" do
82
- # Tf = (9/5)*Tc+32
83
- Data::Temperature.c_to_f(@c).should == @f
84
- end
85
-
86
- it "converts F to C" do
87
- # Tc = (5/9)*(Tf-32)
88
- Data::Temperature.f_to_c(@f).should == @c
89
- end
90
-
91
- it "converts F to K" do
92
- Data::Temperature.f_to_k(@f).should == @k
93
- end
94
-
95
- it "converts K to C" do
96
- Data::Temperature.k_to_c(@k).should == @c
97
- end
98
-
99
- it "converts K to F" do
100
- Data::Temperature.k_to_f(@k).should == @f
101
- end
102
-
103
- end
104
-
105
- describe "updating" do
106
-
107
- before(:each) do
108
- @temp = Data::Temperature.new
109
- @f = 68.0
110
- @c = 20.0
111
- end
112
-
113
- it "nils F if new C converts to a F that changes more then 1 degree" do
114
- @temp.fahrenheit = (@f + 1.1)
115
- @temp.update_fahrenheit(@c)
116
- @temp.fahrenheit.should be_nil
117
- end
118
-
119
- it "doesn't update F if new C converts to a F that does not change more then 1 degree" do
120
- @temp.fahrenheit = (@f + 0.9)
121
- @temp.update_fahrenheit(@c)
122
- @temp.fahrenheit.should == (@f + 0.9)
123
- end
124
-
125
- it "doesn't set F if not already set" do
126
- @temp.fahrenheit.should be_nil
127
- @temp.celsius.should be_nil
128
- @temp.update_fahrenheit(@c)
129
- @temp.fahrenheit.should be_nil
130
- @temp.celsius.should be_nil
131
- end
132
-
133
- it "nils C if new F converts to a C that changes more then 1 degree" do
134
- @temp.celsius = (@c + 1.1)
135
- @temp.update_celsius(@f)
136
- @temp.celsius.should be_nil
137
- end
138
-
139
- it "doesn't update C if new F converts to a C that does not change more then 1 degree" do
140
- @temp.celsius = (@c + 0.9)
141
- @temp.update_celsius(@f)
142
- @temp.celsius.should == (@c + 0.9)
143
- end
144
-
145
- it "doesn't set C if not already set" do
146
- @temp.fahrenheit.should be_nil
147
- @temp.celsius.should be_nil
148
- @temp.update_celsius(@f)
149
- @temp.fahrenheit.should be_nil
150
- @temp.celsius.should be_nil
151
- end
152
-
153
- end
154
-
155
- describe "storing" do
156
-
157
- before(:each) do
158
- @temp = Data::Temperature.new
159
- @f = 68.0
160
- @c = 20.0
161
- @k = 293.15
162
- end
163
-
164
- it "doesn't update C if nil value (or equivalent)" do
165
- @temp.celsius.should be_nil
166
- @temp.c = nil
167
- @temp.celsius.should be_nil
168
- @temp.c = "na"
169
- @temp.celsius.should be_nil
170
- end
171
-
172
- it "stores C, convert to K and reset F" do
173
- @temp.celsius.should be_nil
174
- @temp.fahrenheit = (@f + 1.1)
175
- @temp.kelvin.should be_nil
176
- @temp.c = @c
177
- @temp.celsius.should == @c
178
- @temp.kelvin.should == @k
179
- @temp.fahrenheit.should be_nil
1
+ require_relative '../spec_helper'
2
+
3
+ module Barometer::Data
4
+ describe Temperature do
5
+ describe '.initialize' do
6
+ it 'sets C' do
7
+ temperature = Temperature.new(20.0, nil)
8
+ expect( temperature.c ).to eq 20.0
9
+ end
10
+
11
+ it 'sets F' do
12
+ temperature = Temperature.new(nil, 68.0)
13
+ expect( temperature.f ).to eq 68.0
14
+ end
15
+
16
+ it 'defaults to metric' do
17
+ temperature = Temperature.new(20)
18
+ expect( temperature ).to be_metric
19
+ end
20
+ end
21
+
22
+ describe '#f' do
23
+ it 'returns known value as F' do
24
+ temperature = Temperature.new(:imperial, 68)
25
+ expect( temperature.f ).to eq 68
26
+ end
27
+ end
28
+
29
+ describe '#c' do
30
+ it 'returns known value as C' do
31
+ temperature = Temperature.new(:metric, 20)
32
+ expect( temperature.c ).to eq 20
33
+ end
34
+ end
35
+
36
+ describe '#units' do
37
+ context 'when temperature is metric' do
38
+ it 'returns C' do
39
+ temperature = Temperature.new(:metric, 20.0)
40
+ expect( temperature.units ).to eq 'C'
41
+ end
42
+ end
43
+
44
+ context 'when temperature is imperial' do
45
+ it 'returns F' do
46
+ temperature = Temperature.new(:imperial, 68.0)
47
+ expect( temperature.units ).to eq 'F'
48
+ end
49
+ end
180
50
  end
181
-
182
- it "doesn't update F if nil value (or equivalent)" do
183
- @temp.fahrenheit.should be_nil
184
- @temp.f = nil
185
- @temp.fahrenheit.should be_nil
186
- @temp.f = "na"
187
- @temp.fahrenheit.should be_nil
188
- end
189
-
190
- it "stores F, convert to K and reset C" do
191
- @temp.fahrenheit.should be_nil
192
- @temp.celsius = (@c + 1.1)
193
- @temp.kelvin.should be_nil
194
- @temp.f = @f
195
- @temp.fahrenheit.should == @f
196
- @temp.kelvin.should == @k
197
- @temp.celsius.should be_nil
198
- end
199
-
200
- it "doesn't update K if nil value (or equivalent)" do
201
- @temp.kelvin.should be_nil
202
- @temp.k = nil
203
- @temp.kelvin.should be_nil
204
- @temp.k = "na"
205
- @temp.kelvin.should be_nil
206
- end
207
-
208
- it "stores K, convert to F and C" do
209
- @temp.celsius.should be_nil
210
- @temp.fahrenheit.should be_nil
211
- @temp.kelvin.should be_nil
212
- @temp.k = @k
213
- @temp.celsius.should == @c
214
- @temp.fahrenheit.should == @f
215
- @temp.kelvin.should == @k
216
- end
217
-
218
51
  end
219
-
220
- describe "retrieving" do
221
-
222
- before(:each) do
223
- @temp = Data::Temperature.new
224
- @f = 68.0
225
- @c = 20.0
226
- @k = 293.15
227
- end
228
-
229
- it "returns C if it exists" do
230
- @temp.c = @c
231
- @temp.celsius.should == @c
232
- @temp.c.should == @c
233
- end
234
-
235
- it "auto converts from K if C is nil and K exists" do
236
- @temp.f = @f
237
- @temp.fahrenheit.should == @f
238
- @temp.kelvin.should == @k
239
- @temp.celsius.should be_nil
240
- @temp.c.should == @c
241
- end
242
-
243
- it "allows a float to be returned for C" do
244
- c = 20.12
245
- @temp.c = c
246
- @temp.celsius.should == c
247
- @temp.c(true).should == c.to_i
248
- @temp.c(false).should == c.to_f
249
- end
250
-
251
- it "allows only 2 decimal precision for C" do
252
- c = 20.1234
253
- @temp.c = c
254
- @temp.celsius.should == c
255
- @temp.c(false).should == 20.12
256
- end
257
-
258
- it "returns F if it exists" do
259
- @temp.f = @f
260
- @temp.fahrenheit.should == @f
261
- @temp.f.should == @f
262
- end
263
-
264
- it "auto converts from K if F is nil and K exists" do
265
- @temp.c = @c
266
- @temp.celsius.should == @c
267
- @temp.kelvin.should == @k
268
- @temp.fahrenheit.should be_nil
269
- @temp.f.should == @f
270
- end
271
-
272
- it "allows a float to be returned for F" do
273
- f = 68.12
274
- @temp.f = f
275
- @temp.fahrenheit.should == f
276
- @temp.f(true).should == f.to_i
277
- @temp.f(false).should == f.to_f
278
- end
279
-
280
- it "allows only 2 decimal precision for F" do
281
- f = 68.1234
282
- @temp.f = f
283
- @temp.fahrenheit.should == f
284
- @temp.f(false).should == 68.12
285
- end
286
-
287
- end
288
-
289
- describe "operators" do
290
-
291
- before(:each) do
292
- @f = 68.0
293
- @c = 20.0
294
- @k = 293.15
295
- @temp_low = Data::Temperature.new
296
- @temp_low.k = (@k - 1.0)
297
- @temp_high = Data::Temperature.new
298
- @temp_high.k = (@k + 1.0)
299
- @temp = Data::Temperature.new
300
- @temp.k = @k
301
- @temp_same = Data::Temperature.new
302
- @temp_same.k = @k
303
- end
304
-
305
- it "defines <=>" do
306
- Data::Temperature.method_defined?("<=>").should be_true
307
- (@temp_low <=> @temp_high).should == -1
308
- (@temp_high <=> @temp_low).should == 1
309
- (@temp <=> @temp_same).should == 0
310
- end
311
-
312
- it "defines <" do
313
- Data::Temperature.method_defined?("<").should be_true
314
- @temp_low.should < @temp_high
315
- @temp_high.should_not < @temp_low
316
- @temp.should_not < @temp_same
317
- end
318
-
319
- it "defines >" do
320
- Data::Temperature.method_defined?(">").should be_true
321
- @temp_low.should_not > @temp_high
322
- @temp_high.should > @temp_low
323
- @temp.should_not > @temp_same
324
- end
325
-
326
- it "defines ==" do
327
- Data::Temperature.method_defined?("==").should be_true
328
- @temp_low.should_not == @temp_high
329
- @temp.should == @temp_same
330
- end
331
-
332
- it "defines <=" do
333
- Data::Temperature.method_defined?("<=").should be_true
334
- @temp_low.should <= @temp_high
335
- @temp_high.should_not <= @temp_low
336
- @temp.should <= @temp_same
337
- end
338
-
339
- it "defines >=" do
340
- Data::Temperature.method_defined?(">=").should be_true
341
- @temp_low.should_not >= @temp_high
342
- @temp_high.should >= @temp_low
343
- @temp.should >= @temp_same
344
- end
345
-
346
- end
347
-
348
- describe "changing units" do
349
-
350
- before(:each) do
351
- @c = 20.5
352
- @f = Data::Temperature.c_to_f(@c)
353
- @k = Data::Temperature.c_to_k(@c)
354
- @temp = Data::Temperature.new
355
- @temp.k = @k
356
- end
357
-
358
- it "returns just the integer value (no units)" do
359
- @temp.metric?.should be_true
360
- @temp.to_i.should == @c.to_i
361
-
362
- @temp.imperial!
363
- @temp.metric?.should be_false
364
- @temp.to_i.should == @f.to_i
365
- end
366
-
367
- it "returns just the float value (no units)" do
368
- @temp.metric?.should be_true
369
- @temp.to_f.should == @c.to_f
370
-
371
- @temp.imperial!
372
- @temp.metric?.should be_false
373
- @temp.to_f.should == @f.to_f
374
- end
375
-
376
- it "returns just the integer value with units" do
377
- @temp.metric?.should be_true
378
- @temp.to_s.should == "#{@c.to_i} #{Data::Temperature::METRIC_UNITS}"
379
-
380
- @temp.imperial!
381
- @temp.metric?.should be_false
382
- @temp.to_s.should == "#{@f.to_i} #{Data::Temperature::IMPERIAL_UNITS}"
383
- end
384
-
385
- it "returns just the units" do
386
- @temp.metric?.should be_true
387
- @temp.units.should == Data::Temperature::METRIC_UNITS
388
-
389
- @temp.imperial!
390
- @temp.metric?.should be_false
391
- @temp.units.should == Data::Temperature::IMPERIAL_UNITS
392
- end
393
-
394
- end
395
-
396
52
  end