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,239 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Data::LocalTime" do
4
-
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @time = Data::LocalTime.new
9
- end
10
-
11
- it "responds to hour" do
12
- @time.hour.should == 0
13
- end
14
-
15
- it "responds to min" do
16
- @time.min.should == 0
17
- end
18
-
19
- it "responds to sec" do
20
- @time.sec.should == 0
21
- end
22
-
23
- end
24
-
25
- describe "conversion" do
26
-
27
- before(:each) do
28
- @h = 12
29
- @m = 11
30
- @s = 10
31
- @time = Data::LocalTime.new(@h,@m,@s)
32
- end
33
-
34
- it "converts to a Time object" do
35
- @time.is_a?(Data::LocalTime)
36
- @time.to_t.is_a?(Time).should be_true
37
- @time.hour.should == @h
38
- @time.min.should == @m
39
- @time.sec.should == @s
40
- end
41
-
42
- end
43
-
44
- describe "parsing" do
45
-
46
- before(:each) do
47
- @h = 12
48
- @m = 11
49
- @s = 10
50
- @time = Data::LocalTime.new(@h,@m,@s)
51
- end
52
-
53
- it "parses a Time object" do
54
- time = Time.local(2009,1,1,@h,@m,@s)
55
- @time.parse(time)
56
- @time.hour.should == @h
57
- @time.min.should == @m
58
- @time.sec.should == @s
59
- end
60
-
61
- it "parses a DateTime object" do
62
- time = DateTime.new(2009,1,1,@h,@m,@s)
63
- @time.parse(time)
64
- @time.hour.should == @h
65
- @time.min.should == @m
66
- @time.sec.should == @s
67
- end
68
-
69
- it "parses a String" do
70
- time = "#{@h}:#{@m}:#{@s}"
71
- @time.parse(time)
72
- @time.hour.should == @h
73
- @time.min.should == @m
74
- @time.sec.should == @s
75
- end
76
-
77
- it "parses a String (using class method)" do
78
- time = "#{@h}:#{@m}:#{@s}"
79
- time = Data::LocalTime.parse(time)
80
- time.hour.should == @h
81
- time.min.should == @m
82
- time.sec.should == @s
83
- end
84
-
85
- end
86
-
87
- describe "storing" do
88
-
89
- before(:each) do
90
- @h = 12
91
- @m = 11
92
- @s = 10
93
- @time = Data::LocalTime.new(@h,@m,@s)
94
- end
95
-
96
- it "requires Fixnum (accepts nil)" do
97
- invalid_data = "s"
98
- valid_data = 1
99
- lambda { @time.hour = invalid_data }.should raise_error(ArgumentError)
100
- lambda { @time.hour = valid_data }.should_not raise_error(ArgumentError)
101
- lambda { @time.hour = nil }.should_not raise_error(ArgumentError)
102
- lambda { @time.min = invalid_data }.should raise_error(ArgumentError)
103
- lambda { @time.min = valid_data }.should_not raise_error(ArgumentError)
104
- lambda { @time.min = nil }.should_not raise_error(ArgumentError)
105
- lambda { @time.sec = invalid_data }.should raise_error(ArgumentError)
106
- lambda { @time.sec = valid_data }.should_not raise_error(ArgumentError)
107
- lambda { @time.sec = nil }.should_not raise_error(ArgumentError)
108
- end
109
-
110
- it "rolls over seconds" do
111
- time = Data::LocalTime.new(0,0,60)
112
- time.sec.should == 0
113
- time.min.should == 1
114
- end
115
-
116
- it "rolls over minutes" do
117
- time = Data::LocalTime.new(0,60,0)
118
- time.min.should == 0
119
- time.hour.should == 1
120
- end
121
-
122
- it "rolls over hours" do
123
- time = Data::LocalTime.new(24,0,0)
124
- time.sec.should == 0
125
- time.min.should == 0
126
- time.hour.should == 0
127
- end
128
-
129
- it "rolls over everything" do
130
- time = Data::LocalTime.new(50,600,601)
131
- time.sec.should == 1
132
- time.min.should == 10
133
- time.hour.should == 12
134
- end
135
-
136
- it "add seconds" do
137
- time = Data::LocalTime.new(0,0,0)
138
- time = time + 61
139
- time.sec.should == 1
140
- time.min.should == 1
141
- end
142
-
143
- end
144
-
145
- describe "retrieving" do
146
-
147
- before(:each) do
148
- @h = 6
149
- @m = 30
150
- @s = 20
151
- @time = Data::LocalTime.new(@h,@m,@s)
152
- end
153
-
154
- it "returns pretty string" do
155
- @time.to_s.should == "06:30 am"
156
- @time.to_s(true).should == "06:30:20 am"
157
- end
158
-
159
- end
160
-
161
- describe "comparators" do
162
-
163
- before(:each) do
164
- @time_low = Data::LocalTime.new(0,0,1)
165
- @time_mid = Data::LocalTime.new(12,0,0)
166
- @time_high = Data::LocalTime.new(23,59,59)
167
- end
168
-
169
- it "defines <=>" do
170
- Data::LocalTime.method_defined?("<=>").should be_true
171
- (@time_low <=> @time_high).should == -1
172
- (@time_high <=> @time_low).should == 1
173
- (@time_mid <=> @time_mid).should == 0
174
- end
175
-
176
- it "compares to a Time object" do
177
- time = Time.local(2009,1,1,12,0,0)
178
- (@time_low <=> time).should == -1
179
- (@time_high <=> time).should == 1
180
- (@time_mid <=> time).should == 0
181
- end
182
-
183
- it "compares to a DateTime object" do
184
- time = DateTime.new(2009,1,1,12,0,0)
185
- (@time_low <=> time).should == -1
186
- (@time_high <=> time).should == 1
187
- (@time_mid <=> time).should == 0
188
- end
189
-
190
- it "compares to a String object" do
191
- time = "12:00:00"
192
- (@time_low <=> time).should == -1
193
- (@time_high <=> time).should == 1
194
- (@time_mid <=> time).should == 0
195
- end
196
-
197
- end
198
-
199
- describe "math" do
200
-
201
- it "counts the total seconds" do
202
- Data::LocalTime.new(0,0,1).total_seconds.should == 1
203
- Data::LocalTime.new(0,1,0).total_seconds.should == (1*60)
204
- Data::LocalTime.new(1,0,0).total_seconds.should == (1*60*60)
205
- end
206
-
207
- it "provides a difference" do
208
- a = Data::LocalTime.new(0,0,1)
209
- b = Data::LocalTime.new(1,0,0)
210
- diff = (1*60*60) - 1
211
- a.diff(b).should == diff
212
- b.diff(a).should == diff
213
- end
214
-
215
- it "adds time" do
216
- a = Data::LocalTime.new(0,0,1)
217
- b = Data::LocalTime.new(1,0,0)
218
- c = (a + b)
219
- c.is_a?(Data::LocalTime).should be_true
220
- c.should == Data::LocalTime.new(1,0,1)
221
-
222
- b = Data::LocalTime.new(1,0,0)
223
- (b + 1).should == Data::LocalTime.new(1,0,1)
224
- end
225
-
226
- it "subtracts time" do
227
- a = Data::LocalTime.new(0,0,1)
228
- b = Data::LocalTime.new(1,0,0)
229
- c = (b - a)
230
- c.is_a?(Data::LocalTime).should be_true
231
- c.should == Data::LocalTime.new(0,59,59)
232
-
233
- b = Data::LocalTime.new(1,0,0)
234
- (b - 1).should == Data::LocalTime.new(0,59,59)
235
- end
236
-
237
- end
238
-
239
- end
@@ -1,374 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Speed" do
4
-
5
- describe "when initialized" do
6
-
7
- it "defines METRIC_UNITS" do
8
- Data::Speed.const_defined?("METRIC_UNITS").should be_true
9
- Data::Speed::METRIC_UNITS.should == "kph"
10
- end
11
-
12
- it "defines IMPERIAL_UNITS" do
13
- Data::Speed.const_defined?("IMPERIAL_UNITS").should be_true
14
- Data::Speed::IMPERIAL_UNITS.should == "mph"
15
- end
16
-
17
- before(:each) do
18
- @speed = Data::Speed.new
19
- end
20
-
21
- it "responds to kilometers" do
22
- @speed.kilometers.should be_nil
23
- end
24
-
25
- it "responds to miles" do
26
- @speed.miles.should be_nil
27
- end
28
-
29
- it "responds to degrees" do
30
- @speed.degrees.should be_nil
31
- end
32
-
33
- it "responds to direction" do
34
- @speed.direction.should be_nil
35
- end
36
-
37
- it "responds to metric_default" do
38
- lambda { @speed.metric_default = 5 }.should_not raise_error(NotImplementedError)
39
- end
40
-
41
- it "responds to imperial_default" do
42
- lambda { @speed.imperial_default = 5 }.should_not raise_error(NotImplementedError)
43
- end
44
-
45
- it "responds to nil?" do
46
- @speed.nil?.should be_true
47
- @speed.kph = 5
48
- @speed.nil?.should be_false
49
- end
50
-
51
- end
52
-
53
- describe "conversion" do
54
-
55
- # For all conversions
56
- # 16.09 km/h = 10.0 mph
57
- before(:each) do
58
- @m = 10.0
59
- @km = 16.09
60
- end
61
-
62
- it "requires a value, that is either Integer or Float" do
63
- Data::Speed.km_to_m(nil).should be_nil
64
- Data::Speed.m_to_km(nil).should be_nil
65
-
66
- not_float_or_integer = "string"
67
- Data::Speed.km_to_m(not_float_or_integer).should be_nil
68
- Data::Speed.m_to_km(not_float_or_integer).should be_nil
69
- end
70
-
71
- it "converts km/h to mph" do
72
- # to get equality, we need to tone down the precision
73
- ((Data::Speed.km_to_m(@km)*10).round/10.0).should == @m
74
- end
75
-
76
- it "converts mph to km/h" do
77
- Data::Speed.m_to_km(@m).should == @km
78
- end
79
-
80
- end
81
-
82
- describe "updating" do
83
-
84
- before(:each) do
85
- @speed = Data::Speed.new
86
- @m = 10.0
87
- @km = 16.09
88
- end
89
-
90
- it "nils M if new KM converts to a M that changes more then 1 unit" do
91
- @speed.miles = (@m + 1.1)
92
- @speed.update_miles(@km)
93
- @speed.miles.should be_nil
94
- end
95
-
96
- it "doesn't update M if new KM converts to a M that does not change more then 1 unit" do
97
- @speed.miles = (@m + 0.9)
98
- @speed.update_miles(@km)
99
- @speed.miles.should == (@m + 0.9)
100
- end
101
-
102
- it "doesn't set M if not already set" do
103
- @speed.miles.should be_nil
104
- @speed.kilometers.should be_nil
105
- @speed.update_miles(@km)
106
- @speed.miles.should be_nil
107
- @speed.kilometers.should be_nil
108
- end
109
-
110
- it "nils KM if new M converts to a KM that changes more then 1 unit" do
111
- @speed.kilometers = (@km + 1.1)
112
- @speed.update_kilometers(@m)
113
- @speed.kilometers.should be_nil
114
- end
115
-
116
- it "doesn't update KM if new M converts to a KM that does not change more then 1 unit" do
117
- @speed.kilometers = (@km + 0.9)
118
- @speed.update_kilometers(@m)
119
- @speed.kilometers.should == (@km + 0.9)
120
- end
121
-
122
- it "doesn't set KM if not already set" do
123
- @speed.miles.should be_nil
124
- @speed.kilometers.should be_nil
125
- @speed.update_kilometers(@m)
126
- @speed.miles.should be_nil
127
- @speed.kilometers.should be_nil
128
- end
129
-
130
- end
131
-
132
- describe "storing" do
133
-
134
- before(:each) do
135
- @speed = Data::Speed.new
136
- @m = 10.0
137
- @km = 16.09
138
- end
139
-
140
- it "doesn't update KM if nil value (or equivalent)" do
141
- @speed.kilometers.should be_nil
142
- @speed.kph = nil
143
- @speed.kilometers.should be_nil
144
- @speed.kph = "na"
145
- @speed.kilometers.should be_nil
146
- end
147
-
148
- it "stores KM and resets M" do
149
- @speed.kilometers.should be_nil
150
- @speed.miles = (@m + 1.1)
151
- @speed.kph = @km
152
- @speed.kilometers.should == @km
153
- @speed.miles.should be_nil
154
- end
155
-
156
- it "doesn't update M if nil value (or equivalent)" do
157
- @speed.miles.should be_nil
158
- @speed.mph = nil
159
- @speed.miles.should be_nil
160
- @speed.mph = "na"
161
- @speed.miles.should be_nil
162
- end
163
-
164
- it "stores M, resets KM" do
165
- @speed.miles.should be_nil
166
- @speed.kilometers = (@km + 1.1)
167
- @speed.mph = @m
168
- @speed.miles.should == @m
169
- @speed.kilometers.should be_nil
170
- end
171
-
172
- it "doesn't update direction if nil value (or equivalent)" do
173
- @speed.direction.should be_nil
174
- @speed.direction = nil
175
- @speed.direction.should be_nil
176
- @speed.direction = "na"
177
- @speed.direction.should_not be_nil
178
- end
179
-
180
- it "stores direction" do
181
- @speed.direction.should be_nil
182
- @speed.direction = "SSW"
183
- @speed.direction.should == "SSW"
184
- end
185
-
186
- it "doesn't update degrees if nil value (or equivalent)" do
187
- @speed.degrees.should be_nil
188
- @speed.degrees = nil
189
- @speed.degrees.should be_nil
190
- @speed.degrees = "na"
191
- @speed.degrees.should be_nil
192
- end
193
-
194
- it "stores degrees" do
195
- @speed.degrees.should be_nil
196
- @speed.degrees = 90.0
197
- @speed.degrees.should == 90.0
198
- end
199
-
200
- end
201
-
202
- describe "retrieving" do
203
-
204
- before(:each) do
205
- @speed = Data::Speed.new
206
- @m = 10.0
207
- @km = 16.09
208
- end
209
-
210
- it "returns KM if it exists" do
211
- @speed.kph = @km
212
- @speed.kilometers.should == @km
213
- @speed.kph(false).should == @km
214
- end
215
-
216
- it "auto converts from M if KM is nil and M exists" do
217
- @speed.mph = @m
218
- @speed.miles.should == @m
219
- @speed.kilometers.should be_nil
220
- @speed.kph(false).should == @km
221
- end
222
-
223
- it "allows a float to be returned for KM" do
224
- km = 16.12
225
- @speed.kph = km
226
- @speed.kilometers.should == km
227
- @speed.kph(true).should == km.to_i
228
- @speed.kph(false).should == km.to_f
229
- end
230
-
231
- it "allows only 2 decimal precision for KM" do
232
- km = 16.1234
233
- @speed.kph = km
234
- @speed.kilometers.should == km
235
- @speed.kph(false).should == 16.12
236
- end
237
-
238
- it "returns M if it exists" do
239
- @speed.mph = @m
240
- @speed.miles.should == @m
241
- @speed.mph.should == @m
242
- end
243
-
244
- it "auto converts from KM if M is nil and KM exists" do
245
- @speed.kph = @km
246
- @speed.kilometers.should == @km
247
- @speed.miles.should be_nil
248
- # to get equality, we need to tone down the precision
249
- ((@speed.mph*10).round/10.0).should == @m
250
- end
251
-
252
- it "allows a float to be returned for M" do
253
- m = 10.12
254
- @speed.mph = m
255
- @speed.miles.should == m
256
- @speed.mph(true).should == m.to_i
257
- @speed.mph(false).should == m.to_f
258
- end
259
-
260
- it "allows only 2 decimal precision for M" do
261
- m = 10.1234
262
- @speed.mph = m
263
- @speed.miles.should == m
264
- @speed.mph(false).should == 10.12
265
- end
266
-
267
- end
268
-
269
- describe "operators" do
270
-
271
- before(:each) do
272
- @m = 10.0
273
- @km = 16.09
274
- @speed_low = Data::Speed.new
275
- @speed_low.kph = (@km - 1.0)
276
- @speed_high = Data::Speed.new
277
- @speed_high.kph = (@km + 1.0)
278
- @speed = Data::Speed.new
279
- @speed.kph = @km
280
- @speed_same = Data::Speed.new
281
- @speed_same.kph = @km
282
- end
283
-
284
- it "defines <=>" do
285
- Data::Speed.method_defined?("<=>").should be_true
286
- (@speed_low <=> @speed_high).should == -1
287
- (@speed_high <=> @speed_low).should == 1
288
- (@speed <=> @speed_same).should == 0
289
- end
290
-
291
- it "defines <" do
292
- Data::Speed.method_defined?("<").should be_true
293
- @speed_low.should < @speed_high
294
- @speed_high.should_not < @speed_low
295
- @speed.should_not < @speed_same
296
- end
297
-
298
- it "defines >" do
299
- Data::Speed.method_defined?(">").should be_true
300
- @speed_low.should_not > @speed_high
301
- @speed_high.should > @speed_low
302
- @speed.should_not > @speed_same
303
- end
304
-
305
- it "defines ==" do
306
- Data::Speed.method_defined?("==").should be_true
307
- @speed_low.should_not == @speed_high
308
- @speed.should == @speed_same
309
- end
310
-
311
- it "defines <=" do
312
- Data::Speed.method_defined?("<=").should be_true
313
- @speed_low.should <= @speed_high
314
- @speed_high.should_not <= @speed_low
315
- @speed.should <= @speed_same
316
- end
317
-
318
- it "defines >=" do
319
- Data::Speed.method_defined?(">=").should be_true
320
- @speed_low.should_not >= @speed_high
321
- @speed_high.should >= @speed_low
322
- @speed.should >= @speed_same
323
- end
324
-
325
- end
326
-
327
- describe "changing units" do
328
-
329
- before(:each) do
330
- @m = 10.51
331
- @km = ((Data::Speed.m_to_km(@m)*100).round/100.0)
332
- @speed = Data::Speed.new
333
- @speed.mph = @m
334
- end
335
-
336
- it "returns just the integer value (no units)" do
337
- @speed.metric?.should be_true
338
- @speed.to_i.should == @km.to_i
339
-
340
- @speed.imperial!
341
- @speed.metric?.should be_false
342
- @speed.to_i.should == @m.to_i
343
- end
344
-
345
- it "returns just the float value (no units)" do
346
- @speed.metric?.should be_true
347
- @speed.to_f.should == @km.to_f
348
-
349
- @speed.imperial!
350
- @speed.metric?.should be_false
351
- @speed.to_f.should == @m.to_f
352
- end
353
-
354
- it "returns just the integer value with units" do
355
- @speed.metric?.should be_true
356
- @speed.to_s.should == "#{@km.to_i} #{Data::Speed::METRIC_UNITS}"
357
-
358
- @speed.imperial!
359
- @speed.metric?.should be_false
360
- @speed.to_s.should == "#{@m.to_i} #{Data::Speed::IMPERIAL_UNITS}"
361
- end
362
-
363
- it "returns just the units" do
364
- @speed.metric?.should be_true
365
- @speed.units.should == Data::Speed::METRIC_UNITS
366
-
367
- @speed.imperial!
368
- @speed.metric?.should be_false
369
- @speed.units.should == Data::Speed::IMPERIAL_UNITS
370
- end
371
-
372
- end
373
-
374
- end