barometer 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +7 -0
  3. data/LICENSE +1 -1
  4. data/{README.rdoc → README.md} +124 -110
  5. data/Rakefile +1 -21
  6. data/TODO +8 -9
  7. data/barometer.gemspec +20 -19
  8. data/bin/barometer +36 -83
  9. data/lib/barometer.rb +13 -11
  10. data/lib/barometer/base.rb +10 -10
  11. data/lib/barometer/data.rb +1 -1
  12. data/lib/barometer/data/distance.rb +25 -25
  13. data/lib/barometer/data/geo.rb +9 -9
  14. data/lib/barometer/data/local_datetime.rb +24 -20
  15. data/lib/barometer/data/local_time.rb +13 -13
  16. data/lib/barometer/data/location.rb +6 -6
  17. data/lib/barometer/data/pressure.rb +24 -24
  18. data/lib/barometer/data/speed.rb +28 -28
  19. data/lib/barometer/data/sun.rb +7 -7
  20. data/lib/barometer/data/temperature.rb +29 -29
  21. data/lib/barometer/data/units.rb +9 -9
  22. data/lib/barometer/data/zone.rb +19 -19
  23. data/lib/barometer/formats.rb +1 -1
  24. data/lib/barometer/formats/coordinates.rb +7 -7
  25. data/lib/barometer/formats/format.rb +6 -6
  26. data/lib/barometer/formats/geocode.rb +5 -5
  27. data/lib/barometer/formats/icao.rb +6 -6
  28. data/lib/barometer/formats/postalcode.rb +3 -3
  29. data/lib/barometer/formats/short_zipcode.rb +2 -2
  30. data/lib/barometer/formats/weather_id.rb +10 -10
  31. data/lib/barometer/formats/woe_id.rb +20 -20
  32. data/lib/barometer/formats/zipcode.rb +3 -3
  33. data/lib/barometer/key_file_parser.rb +20 -0
  34. data/lib/barometer/measurements/measurement.rb +32 -32
  35. data/lib/barometer/measurements/result.rb +39 -39
  36. data/lib/barometer/measurements/result_array.rb +12 -12
  37. data/lib/barometer/query.rb +15 -15
  38. data/lib/barometer/services.rb +3 -3
  39. data/lib/barometer/translations/icao_country_codes.yml +20 -20
  40. data/lib/barometer/translations/weather_country_codes.yml +1 -1
  41. data/lib/barometer/translations/zone_codes.yml +2 -2
  42. data/lib/barometer/version.rb +3 -0
  43. data/lib/barometer/weather.rb +27 -27
  44. data/lib/barometer/weather_services/noaa.rb +314 -3
  45. data/lib/barometer/weather_services/service.rb +32 -30
  46. data/lib/barometer/weather_services/weather_bug.rb +35 -33
  47. data/lib/barometer/weather_services/wunderground.rb +31 -29
  48. data/lib/barometer/weather_services/yahoo.rb +36 -35
  49. data/lib/barometer/web_services/geocode.rb +5 -7
  50. data/lib/barometer/web_services/noaa_station_id.rb +53 -0
  51. data/lib/barometer/web_services/placemaker.rb +11 -13
  52. data/lib/barometer/web_services/timezone.rb +5 -7
  53. data/lib/barometer/web_services/weather_id.rb +4 -6
  54. data/lib/barometer/web_services/web_service.rb +4 -4
  55. data/spec/barometer_spec.rb +25 -27
  56. data/spec/cassettes/Barometer.json +1 -0
  57. data/spec/cassettes/Query.json +1 -0
  58. data/spec/cassettes/Query_Format_Coordinates.json +1 -0
  59. data/spec/cassettes/Query_Format_Geocode.json +1 -0
  60. data/spec/cassettes/Query_Format_WeatherID.json +1 -0
  61. data/spec/cassettes/Query_Format_WoeID.json +1 -0
  62. data/spec/cassettes/WeatherService.json +1 -0
  63. data/spec/cassettes/WeatherService_Noaa.json +1 -0
  64. data/spec/cassettes/WeatherService_WeatherBug.json +1 -0
  65. data/spec/cassettes/WeatherService_Wunderground.json +1 -0
  66. data/spec/cassettes/WeatherService_Yahoo.json +1 -0
  67. data/spec/cassettes/WebService_Geocode.json +1 -0
  68. data/spec/cassettes/WebService_NoaaStation.json +1 -0
  69. data/spec/data/distance_spec.rb +60 -60
  70. data/spec/data/geo_spec.rb +23 -23
  71. data/spec/data/local_datetime_spec.rb +44 -44
  72. data/spec/data/local_time_spec.rb +47 -47
  73. data/spec/data/location_spec.rb +16 -16
  74. data/spec/data/pressure_spec.rb +61 -61
  75. data/spec/data/speed_spec.rb +69 -69
  76. data/spec/data/sun_spec.rb +25 -25
  77. data/spec/data/temperature_spec.rb +68 -68
  78. data/spec/data/units_spec.rb +21 -21
  79. data/spec/data/zone_spec.rb +35 -35
  80. data/spec/formats/coordinates_spec.rb +27 -27
  81. data/spec/formats/format_spec.rb +17 -25
  82. data/spec/formats/geocode_spec.rb +23 -31
  83. data/spec/formats/icao_spec.rb +26 -32
  84. data/spec/formats/postalcode_spec.rb +22 -28
  85. data/spec/formats/short_zipcode_spec.rb +20 -26
  86. data/spec/formats/weather_id_spec.rb +57 -67
  87. data/spec/formats/woe_id_spec.rb +59 -59
  88. data/spec/formats/zipcode_spec.rb +39 -47
  89. data/spec/key_file_parser_spec.rb +28 -0
  90. data/spec/measurements/measurement_spec.rb +79 -133
  91. data/spec/measurements/result_array_spec.rb +23 -38
  92. data/spec/measurements/result_spec.rb +100 -128
  93. data/spec/query_spec.rb +83 -100
  94. data/spec/spec_helper.rb +24 -6
  95. data/spec/weather_services/noaa_spec.rb +179 -0
  96. data/spec/weather_services/services_spec.rb +28 -36
  97. data/spec/weather_services/weather_bug_spec.rb +57 -77
  98. data/spec/weather_services/wunderground_spec.rb +36 -65
  99. data/spec/weather_services/yahoo_spec.rb +38 -60
  100. data/spec/weather_spec.rb +79 -79
  101. data/spec/web_services/geocode_spec.rb +7 -11
  102. data/spec/web_services/noaa_station_id_spec.rb +33 -0
  103. data/spec/web_services/placemaker_spec.rb +7 -12
  104. data/spec/web_services/web_services_spec.rb +3 -9
  105. metadata +214 -163
  106. data/VERSION.yml +0 -5
  107. data/lib/barometer/weather_services/google.rb +0 -142
  108. data/lib/barometer/weather_services/weather_dot_com.rb +0 -279
  109. data/spec/fakeweb_helper.rb +0 -179
  110. data/spec/fixtures/formats/weather_id/90210.xml +0 -7
  111. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +0 -3
  112. data/spec/fixtures/formats/weather_id/ksfo.xml +0 -1
  113. data/spec/fixtures/formats/weather_id/manhattan.xml +0 -7
  114. data/spec/fixtures/formats/weather_id/new_york.xml +0 -1
  115. data/spec/fixtures/formats/weather_id/the_hills.xml +0 -1
  116. data/spec/fixtures/geocode/40_73_v3.json +0 -497
  117. data/spec/fixtures/geocode/90210_v3.json +0 -63
  118. data/spec/fixtures/geocode/T5B4M9_v3.json +0 -68
  119. data/spec/fixtures/geocode/atlanta_v3.json +0 -58
  120. data/spec/fixtures/geocode/calgary_ab_v3.json +0 -58
  121. data/spec/fixtures/geocode/ksfo_v3.json +0 -73
  122. data/spec/fixtures/geocode/newyork_ny_v3.json +0 -58
  123. data/spec/fixtures/services/google/calgary_ab.xml +0 -1
  124. data/spec/fixtures/services/placemaker/T5B4M9.xml +0 -65
  125. data/spec/fixtures/services/placemaker/atlanta.xml +0 -65
  126. data/spec/fixtures/services/placemaker/coords.xml +0 -65
  127. data/spec/fixtures/services/placemaker/ksfo.xml +0 -65
  128. data/spec/fixtures/services/placemaker/new_york.xml +0 -65
  129. data/spec/fixtures/services/placemaker/the_hills.xml +0 -65
  130. data/spec/fixtures/services/placemaker/w615702.xml +0 -47
  131. data/spec/fixtures/services/weather_bug/90210_current.xml +0 -93
  132. data/spec/fixtures/services/weather_bug/90210_forecast.xml +0 -76
  133. data/spec/fixtures/services/weather_dot_com/90210.xml +0 -1
  134. data/spec/fixtures/services/wunderground/current_calgary_ab.xml +0 -9
  135. data/spec/fixtures/services/wunderground/forecast_calgary_ab.xml +0 -13
  136. data/spec/fixtures/services/yahoo/90210.xml +0 -3
  137. data/spec/weather_services/google_spec.rb +0 -181
  138. data/spec/weather_services/weather_dot_com_spec.rb +0 -224
@@ -1,155 +1,140 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  include Barometer
3
3
 
4
- describe "Wunderground" do
5
-
4
+ describe Barometer::WeatherService::Wunderground, :vcr => {
5
+ :cassette_name => "WeatherService::Wunderground"
6
+ } do
6
7
  before(:each) do
7
8
  @accepted_formats = [:zipcode, :postalcode, :icao, :coordinates, :geocode]
8
9
  @base_uri = "http://api.wunderground.com/auto/wui/geo"
9
10
  end
10
-
11
+
11
12
  describe "the class methods" do
12
-
13
13
  it "defines accepted_formats" do
14
14
  WeatherService::Wunderground._accepted_formats.should == @accepted_formats
15
15
  end
16
-
16
+
17
17
  it "defines source_name" do
18
18
  WeatherService::Wunderground._source_name.should == :wunderground
19
19
  end
20
-
20
+
21
21
  it "defines fetch_current" do
22
22
  WeatherService::Wunderground.respond_to?("_fetch_current").should be_true
23
23
  end
24
-
24
+
25
25
  it "defines fetch_forecast" do
26
26
  WeatherService::Wunderground.respond_to?("_fetch_forecast").should be_true
27
27
  end
28
-
29
28
  end
30
-
29
+
31
30
  describe "building the current data" do
32
-
33
31
  it "defines the build method" do
34
32
  WeatherService::Wunderground.respond_to?("_build_current").should be_true
35
33
  end
36
-
34
+
37
35
  it "requires Hash input" do
38
36
  lambda { WeatherService::Wunderground._build_current }.should raise_error(ArgumentError)
39
37
  WeatherService::Wunderground._build_current({})
40
38
  lambda { WeatherService::Wunderground._build_current({}) }.should_not raise_error(ArgumentError)
41
39
  end
42
-
40
+
43
41
  it "returns Barometer::CurrentMeasurement object" do
44
42
  current = WeatherService::Wunderground._build_current({})
45
43
  current.is_a?(Measurement::Result).should be_true
46
44
  end
47
-
48
45
  end
49
-
46
+
50
47
  describe "building the forecast data" do
51
-
52
48
  it "defines the build method" do
53
49
  WeatherService::Wunderground.respond_to?("_build_forecast").should be_true
54
50
  end
55
-
51
+
56
52
  it "requires Hash input" do
57
53
  lambda { WeatherService::Wunderground._build_forecast }.should raise_error(ArgumentError)
58
54
  lambda { WeatherService::Wunderground._build_forecast({}) }.should_not raise_error(ArgumentError)
59
55
  end
60
-
56
+
61
57
  it "returns Array object" do
62
58
  current = WeatherService::Wunderground._build_forecast({})
63
59
  current.is_a?(Array).should be_true
64
60
  end
65
-
66
61
  end
67
-
62
+
68
63
  describe "building the station data" do
69
-
70
64
  it "defines the build method" do
71
65
  WeatherService::Wunderground.respond_to?("_build_station").should be_true
72
66
  end
73
-
67
+
74
68
  it "requires Hash input" do
75
69
  lambda { WeatherService::Wunderground._build_station }.should raise_error(ArgumentError)
76
70
  lambda { WeatherService::Wunderground._build_station({}) }.should_not raise_error(ArgumentError)
77
71
  end
78
-
72
+
79
73
  it "returns Barometer::Location object" do
80
74
  station = WeatherService::Wunderground._build_station({})
81
75
  station.is_a?(Data::Location).should be_true
82
76
  end
83
-
84
77
  end
85
-
78
+
86
79
  describe "building the location data" do
87
-
88
80
  it "defines the build method" do
89
81
  WeatherService::Wunderground.respond_to?("_build_location").should be_true
90
82
  end
91
-
83
+
92
84
  it "requires Hash input" do
93
85
  lambda { WeatherService::Wunderground._build_location }.should raise_error(ArgumentError)
94
86
  lambda { WeatherService::Wunderground._build_location({}) }.should_not raise_error(ArgumentError)
95
87
  end
96
-
88
+
97
89
  it "returns Barometer::Location object" do
98
90
  location = WeatherService::Wunderground._build_location({})
99
91
  location.is_a?(Data::Location).should be_true
100
92
  end
101
-
102
93
  end
103
-
94
+
104
95
  describe "building the timezone" do
105
-
106
96
  it "defines the build method" do
107
97
  WeatherService::Wunderground.respond_to?("_parse_full_timezone").should be_true
108
98
  end
109
-
99
+
110
100
  it "requires Hash input" do
111
101
  lambda { WeatherService::Wunderground._parse_full_timezone }.should raise_error(ArgumentError)
112
102
  lambda { WeatherService::Wunderground._parse_full_timezone({}) }.should_not raise_error(ArgumentError)
113
103
  end
114
-
115
104
  end
116
-
105
+
117
106
  describe "building the sun data" do
118
-
119
107
  it "defines the build method" do
120
108
  WeatherService::Wunderground.respond_to?("_build_sun").should be_true
121
109
  end
122
-
110
+
123
111
  it "requires Hash input" do
124
112
  lambda { WeatherService::Wunderground._build_sun }.should raise_error(ArgumentError)
125
113
  lambda { WeatherService::Wunderground._build_sun({}) }.should_not raise_error(ArgumentError)
126
114
  end
127
-
115
+
128
116
  it "requires Barometer::Zone input" do
129
117
  lambda { WeatherService::Wunderground._build_sun({}, "invalid") }.should raise_error(ArgumentError)
130
118
  lambda { WeatherService::Wunderground._build_sun({}) }.should_not raise_error(ArgumentError)
131
119
  end
132
-
120
+
133
121
  it "returns Barometer::Sun object" do
134
122
  sun = WeatherService::Wunderground._build_sun({})
135
123
  sun.is_a?(Data::Sun).should be_true
136
124
  end
137
-
138
125
  end
139
-
140
- describe "when measuring" do
141
126
 
127
+ describe "when measuring" do
142
128
  before(:each) do
143
129
  @query = Barometer::Query.new("Calgary,AB")
144
130
  @measurement = Barometer::Measurement.new
145
131
  end
146
-
132
+
147
133
  describe "all" do
148
-
149
134
  it "responds to _measure" do
150
135
  WeatherService::Wunderground.respond_to?("_measure").should be_true
151
136
  end
152
-
137
+
153
138
  it "requires a Barometer::Measurement object" do
154
139
  lambda { WeatherService::Wunderground._measure(nil, @query) }.should raise_error(ArgumentError)
155
140
  lambda { WeatherService::Wunderground._measure("invlaid", @query) }.should raise_error(ArgumentError)
@@ -160,49 +145,35 @@ describe "Wunderground" do
160
145
  it "requires a Barometer::Query query" do
161
146
  lambda { WeatherService::Wunderground._measure }.should raise_error(ArgumentError)
162
147
  lambda { WeatherService::Wunderground._measure(@measurement, 1) }.should raise_error(ArgumentError)
163
-
148
+
164
149
  lambda { WeatherService::Wunderground._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
165
150
  end
166
-
151
+
167
152
  it "returns a Barometer::Measurement object" do
168
153
  result = WeatherService::Wunderground._measure(@measurement, @query)
169
154
  result.is_a?(Barometer::Measurement).should be_true
170
155
  result.current.is_a?(Measurement::Result).should be_true
171
156
  result.forecast.is_a?(Array).should be_true
172
157
  end
173
-
174
158
  end
175
-
176
159
  end
177
-
160
+
178
161
  describe "overall data correctness" do
179
-
180
162
  before(:each) do
181
163
  @query = Barometer::Query.new("Calgary,AB")
182
164
  @measurement = Barometer::Measurement.new
183
165
  end
184
166
 
185
- # TODO: complete this
186
167
  it "should correctly build the data" do
187
168
  result = WeatherService::Wunderground._measure(@measurement, @query)
188
-
169
+
189
170
  # build timezone
190
171
  @measurement.timezone.zone_full.should == "America/Edmonton"
191
172
  @measurement.timezone.current.should == "America/Edmonton"
192
-
193
- # time = Time.local(2009, 4, 23, 18, 00, 0)
194
- # rise = Time.local(time.year, time.month, time.day, 6, 23)
195
- # set = Time.local(time.year, time.month, time.day, 20, 45)
196
- # sun_rise = @measurement.timezone.tz.local_to_utc(rise)
197
- # sun_set = @measurement.timezone.tz.local_to_utc(set)
198
-
173
+
199
174
  # build current
200
- #@measurement.current.sun.rise.should == sun_rise
201
- #@measurement.current.sun.set.should == sun_set
202
- @measurement.current.sun.rise.to_s.should == "05:26 am"
203
- @measurement.current.sun.set.to_s.should == "09:41 pm"
175
+ @measurement.current.sun.rise.to_s.should match(/^\d{1,2}:\d{1,2}[ ]?[apmAPM]{0,2}$/i)
176
+ @measurement.current.sun.set.to_s.should match(/^\d{1,2}:\d{1,2}[ ]?[apmAPM]{0,2}$/i)
204
177
  end
205
-
206
178
  end
207
-
208
- end
179
+ end
@@ -1,165 +1,143 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  include Barometer
3
3
 
4
- describe "Yahoo" do
5
-
4
+ describe Barometer::WeatherService::Yahoo, :vcr => {
5
+ :cassette_name => "WeatherService::Yahoo"
6
+ } do
6
7
  before(:each) do
7
8
  @accepted_formats = [:zipcode, :weather_id, :woe_id]
8
- #@base_uri = "http://google.com"
9
9
  end
10
-
10
+
11
11
  describe "the class methods" do
12
-
13
12
  it "defines accepted_formats" do
14
13
  WeatherService::Yahoo._accepted_formats.should == @accepted_formats
15
14
  end
16
-
15
+
17
16
  it "defines source_name" do
18
17
  WeatherService::Yahoo._source_name.should == :yahoo
19
18
  end
20
-
19
+
21
20
  it "defines get_all" do
22
21
  WeatherService::Yahoo.respond_to?("_fetch").should be_true
23
22
  end
24
-
25
23
  end
26
-
24
+
27
25
  describe "building the current data" do
28
-
29
26
  it "defines the build method" do
30
27
  WeatherService::Yahoo.respond_to?("_build_current").should be_true
31
28
  end
32
-
29
+
33
30
  it "requires Hash input" do
34
31
  lambda { WeatherService::Yahoo._build_current }.should raise_error(ArgumentError)
35
32
  lambda { WeatherService::Yahoo._build_current({}) }.should_not raise_error(ArgumentError)
36
33
  end
37
-
34
+
38
35
  it "returns Barometer::CurrentMeasurement object" do
39
36
  current = WeatherService::Yahoo._build_current({})
40
37
  current.is_a?(Measurement::Result).should be_true
41
38
  end
42
-
43
39
  end
44
-
40
+
45
41
  describe "building the forecast data" do
46
-
47
42
  it "defines the build method" do
48
43
  WeatherService::Yahoo.respond_to?("_build_forecast").should be_true
49
44
  end
50
-
45
+
51
46
  it "requires Hash input" do
52
47
  lambda { WeatherService::Yahoo._build_forecast }.should raise_error(ArgumentError)
53
48
  lambda { WeatherService::Yahoo._build_forecast({}) }.should_not raise_error(ArgumentError)
54
49
  end
55
-
50
+
56
51
  it "returns Array object" do
57
52
  current = WeatherService::Yahoo._build_forecast({})
58
53
  current.is_a?(Array).should be_true
59
54
  end
60
-
61
55
  end
62
-
56
+
63
57
  describe "building the location data" do
64
-
65
58
  it "defines the build method" do
66
59
  WeatherService::Yahoo.respond_to?("_build_location").should be_true
67
60
  end
68
-
61
+
69
62
  it "requires Hash input" do
70
63
  lambda { WeatherService::Yahoo._build_location }.should raise_error(ArgumentError)
71
64
  lambda { WeatherService::Yahoo._build_location({}) }.should_not raise_error(ArgumentError)
72
65
  end
73
-
66
+
74
67
  it "requires Barometer::Geo input" do
75
68
  geo = Data::Geo.new({})
76
69
  lambda { WeatherService::Yahoo._build_location({}, {}) }.should raise_error(ArgumentError)
77
70
  lambda { WeatherService::Yahoo._build_location({}, geo) }.should_not raise_error(ArgumentError)
78
71
  end
79
-
72
+
80
73
  it "returns Barometer::Location object" do
81
74
  location = WeatherService::Yahoo._build_location({})
82
75
  location.is_a?(Data::Location).should be_true
83
76
  end
84
-
85
77
  end
86
78
 
87
79
  describe "when measuring" do
88
-
89
80
  before(:each) do
90
81
  @query = Barometer::Query.new("90210")
91
82
  @measurement = Barometer::Measurement.new
92
83
  end
93
-
84
+
94
85
  describe "all" do
95
-
96
86
  it "responds to _measure" do
97
87
  WeatherService::Yahoo.respond_to?("_measure").should be_true
98
88
  end
99
-
89
+
100
90
  it "requires a Barometer::Measurement object" do
101
91
  lambda { WeatherService::Yahoo._measure(nil, @query) }.should raise_error(ArgumentError)
102
92
  lambda { WeatherService::Yahoo._measure("invlaid", @query) }.should raise_error(ArgumentError)
103
93
 
104
94
  lambda { WeatherService::Yahoo._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
105
95
  end
106
-
96
+
107
97
  it "requires a Barometer::Query query" do
108
98
  lambda { WeatherService::Yahoo._measure }.should raise_error(ArgumentError)
109
99
  lambda { WeatherService::Yahoo._measure(@measurement, 1) }.should raise_error(ArgumentError)
110
100
 
111
101
  lambda { WeatherService::Yahoo._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
112
102
  end
113
-
103
+
114
104
  it "returns a Barometer::Measurement object" do
115
105
  result = WeatherService::Yahoo._measure(@measurement, @query)
116
106
  result.is_a?(Barometer::Measurement).should be_true
117
107
  result.current.is_a?(Measurement::Result).should be_true
118
108
  result.forecast.is_a?(Array).should be_true
119
109
  end
120
-
121
110
  end
122
-
123
111
  end
124
-
112
+
125
113
  describe "overall data correctness" do
126
-
127
114
  before(:each) do
128
115
  @query = Barometer::Query.new("90210")
129
116
  @measurement = Barometer::Measurement.new
130
117
  end
131
118
 
132
- # TODO: complete this
133
119
  it "should correctly build the data" do
134
120
  result = WeatherService::Yahoo._measure(@measurement, @query)
135
-
136
- #sun_rise = Barometer::Zone.merge("6:09 am", "Sun, 26 Apr 2009 10:51 am PDT", "PDT")
137
- #sun_set = Barometer::Zone.merge("7:34 pm", "Sun, 26 Apr 2009 10:51 am PDT", "PDT")
138
-
121
+
139
122
  # build current
140
- #@measurement.current.sun.rise.should == sun_rise
141
- #@measurement.current.sun.set.should == sun_set
142
- @measurement.current.sun.rise.to_s.should == "05:42 am"
143
- @measurement.current.sun.set.to_s.should == "07:57 pm"
144
-
123
+ @measurement.current.sun.rise.to_s.should match(/^\d{1,2}:\d{1,2}[ ]?[apmAPM]{0,2}$/i)
124
+ @measurement.current.sun.set.to_s.should match(/^\d{1,2}:\d{1,2}[ ]?[apmAPM]{0,2}$/i)
125
+
145
126
  # builds location
146
127
  @measurement.location.city.should == "Beverly Hills"
147
-
128
+
148
129
  # builds forecasts
149
130
  @measurement.forecast.size.should == 2
150
-
151
- @measurement.forecast[0].condition.should == "Clear"
152
- @measurement.forecast[0].icon.should == "31"
153
- @measurement.forecast[0].sun.rise.should == "05:42 am"
154
- @measurement.forecast[0].sun.set.should == "07:57 pm"
155
-
156
- @measurement.forecast[1].condition.should == "Mostly Sunny"
157
- @measurement.forecast[1].icon.should == "34"
158
- @measurement.forecast[1].sun.rise.should == "05:42 am"
159
- @measurement.forecast[1].sun.set.should == "07:57 pm"
160
-
161
- end
162
-
131
+
132
+ @measurement.forecast[0].condition.should match(/^[\w ]+$/i)
133
+ @measurement.forecast[0].icon.to_s.should match(/^\d{1,3}$/i)
134
+ @measurement.forecast[0].sun.rise.to_s.should match(/^\d{1,2}:\d{1,2}[ ]?[apmAPM]{0,2}$/i)
135
+ @measurement.forecast[0].sun.set.to_s.should match(/^\d{1,2}:\d{1,2}[ ]?[apmAPM]{0,2}$/i)
136
+
137
+ @measurement.forecast[1].condition.should match(/^[\w ]+$/i)
138
+ @measurement.forecast[1].icon.to_s.should match(/^\d{1,3}$/i)
139
+ @measurement.forecast[1].sun.rise.to_s.should match(/^\d{1,2}:\d{1,2}[ ]?[apmAPM]{0,2}$/i)
140
+ @measurement.forecast[1].sun.set.to_s.should match(/^\d{1,2}:\d{1,2}[ ]?[apmAPM]{0,2}$/i)
141
+ end
163
142
  end
164
-
165
- end
143
+ end
data/spec/weather_spec.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "Weather" do
4
-
3
+ describe Barometer::Weather do
4
+
5
5
  describe "when initialized" do
6
-
6
+
7
7
  before(:each) do
8
8
  @weather = Barometer::Weather.new
9
9
  end
@@ -33,9 +33,9 @@ describe "Weather" do
33
33
  end
34
34
 
35
35
  end
36
-
36
+
37
37
  describe "with measurements" do
38
-
38
+
39
39
  before(:each) do
40
40
  @weather = Barometer::Weather.new
41
41
  @wunderground = Barometer::Measurement.new(:wunderground)
@@ -49,7 +49,7 @@ describe "Weather" do
49
49
  @weather.measurements << @yahoo
50
50
  @weather.measurements << @google
51
51
  end
52
-
52
+
53
53
  it "retrieves a source measurement" do
54
54
  lambda { @weather.source(1) }.should raise_error(ArgumentError)
55
55
  lambda { @weather.source("valid") }.should_not raise_error(ArgumentError)
@@ -57,7 +57,7 @@ describe "Weather" do
57
57
  @weather.source(:does_not_exist).should be_nil
58
58
  @weather.source(:wunderground).should == @wunderground
59
59
  end
60
-
60
+
61
61
  it "lists the sources of measurements (that were successful)" do
62
62
  sources = @weather.sources
63
63
  sources.should_not be_nil
@@ -68,15 +68,15 @@ describe "Weather" do
68
68
  @google.success?.should be_false
69
69
  sources.include?(:google).should be_false
70
70
  end
71
-
71
+
72
72
  it "returns the default source" do
73
73
  @weather.default.should == @wunderground
74
74
  end
75
-
75
+
76
76
  end
77
-
77
+
78
78
  describe "when calculating averages" do
79
-
79
+
80
80
  before(:each) do
81
81
  @weather = Barometer::Weather.new
82
82
  @wunderground = Barometer::Measurement.new(:wunderground)
@@ -92,32 +92,32 @@ describe "Weather" do
92
92
  @weather.measurements << @yahoo
93
93
  @weather.measurements << @google
94
94
  end
95
-
95
+
96
96
  it "doesn't include nil values" do
97
97
  @weather.source(:wunderground).current.temperature = Data::Temperature.new
98
98
  @weather.source(:wunderground).current.temperature.c = 10
99
-
99
+
100
100
  @weather.temperature.c.should == 10
101
-
101
+
102
102
  @weather.source(:yahoo).current.temperature = Data::Temperature.new
103
103
  @weather.source(:yahoo).current.temperature.c = nil
104
-
104
+
105
105
  @weather.temperature.c.should == 10
106
106
  end
107
-
107
+
108
108
  it "respects the measurement weight" do
109
109
  @weather.source(:wunderground).current.temperature = Data::Temperature.new
110
110
  @weather.source(:wunderground).current.temperature.c = 10
111
111
  @weather.source(:yahoo).current.temperature = Data::Temperature.new
112
112
  @weather.source(:yahoo).current.temperature.c = 4
113
-
113
+
114
114
  @weather.measurements.first.weight = 2
115
-
115
+
116
116
  @weather.temperature.c.should == 8
117
117
  end
118
-
118
+
119
119
  describe "for temperature" do
120
-
120
+
121
121
  before(:each) do
122
122
  @weather.source(:wunderground).current.temperature = Data::Temperature.new
123
123
  @weather.source(:wunderground).current.temperature.c = 10
@@ -128,15 +128,15 @@ describe "Weather" do
128
128
  it "returns averages" do
129
129
  @weather.temperature.c.should == 8
130
130
  end
131
-
131
+
132
132
  it "returns default when disabled" do
133
133
  @weather.temperature(false).c.should == 10
134
134
  end
135
-
135
+
136
136
  end
137
-
137
+
138
138
  describe "for wind" do
139
-
139
+
140
140
  before(:each) do
141
141
  @weather.source(:wunderground).current.wind = Data::Speed.new
142
142
  @weather.source(:wunderground).current.wind.kph = 10
@@ -147,15 +147,15 @@ describe "Weather" do
147
147
  it "returns averages" do
148
148
  @weather.wind.kph.should == 8
149
149
  end
150
-
150
+
151
151
  it "returns default when disabled" do
152
152
  @weather.wind(false).kph.should == 10
153
153
  end
154
-
154
+
155
155
  end
156
-
156
+
157
157
  describe "for humidity" do
158
-
158
+
159
159
  before(:each) do
160
160
  @weather.source(:wunderground).current.humidity = 10
161
161
  @weather.source(:yahoo).current.humidity = 6
@@ -164,15 +164,15 @@ describe "Weather" do
164
164
  it "returns averages" do
165
165
  @weather.humidity.should == 8
166
166
  end
167
-
167
+
168
168
  it "returns default when disabled" do
169
169
  @weather.humidity(false).should == 10
170
170
  end
171
-
171
+
172
172
  end
173
-
173
+
174
174
  describe "for pressure" do
175
-
175
+
176
176
  before(:each) do
177
177
  @weather.source(:wunderground).current.pressure = Data::Pressure.new
178
178
  @weather.source(:wunderground).current.pressure.mb = 10
@@ -183,15 +183,15 @@ describe "Weather" do
183
183
  it "returns averages" do
184
184
  @weather.pressure.mb.should == 8
185
185
  end
186
-
186
+
187
187
  it "returns default when disabled" do
188
188
  @weather.pressure(false).mb.should == 10
189
189
  end
190
-
190
+
191
191
  end
192
-
192
+
193
193
  describe "for dew_point" do
194
-
194
+
195
195
  before(:each) do
196
196
  @weather.source(:wunderground).current.dew_point = Data::Temperature.new
197
197
  @weather.source(:wunderground).current.dew_point.c = 10
@@ -202,15 +202,15 @@ describe "Weather" do
202
202
  it "returns averages" do
203
203
  @weather.dew_point.c.should == 8
204
204
  end
205
-
205
+
206
206
  it "returns default when disabled" do
207
207
  @weather.dew_point(false).c.should == 10
208
208
  end
209
-
209
+
210
210
  end
211
-
211
+
212
212
  describe "for heat_index" do
213
-
213
+
214
214
  before(:each) do
215
215
  @weather.source(:wunderground).current.heat_index = Data::Temperature.new
216
216
  @weather.source(:wunderground).current.heat_index.c = 10
@@ -221,15 +221,15 @@ describe "Weather" do
221
221
  it "returns averages" do
222
222
  @weather.heat_index.c.should == 8
223
223
  end
224
-
224
+
225
225
  it "returns default when disabled" do
226
226
  @weather.heat_index(false).c.should == 10
227
227
  end
228
-
228
+
229
229
  end
230
-
230
+
231
231
  describe "for wind_chill" do
232
-
232
+
233
233
  before(:each) do
234
234
  @weather.source(:wunderground).current.wind_chill = Data::Temperature.new
235
235
  @weather.source(:wunderground).current.wind_chill.c = 10
@@ -240,15 +240,15 @@ describe "Weather" do
240
240
  it "returns averages" do
241
241
  @weather.wind_chill.c.should == 8
242
242
  end
243
-
243
+
244
244
  it "returns default when disabled" do
245
245
  @weather.wind_chill(false).c.should == 10
246
246
  end
247
-
247
+
248
248
  end
249
-
249
+
250
250
  describe "for visibility" do
251
-
251
+
252
252
  before(:each) do
253
253
  @weather.source(:wunderground).current.visibility = Data::Distance.new
254
254
  @weather.source(:wunderground).current.visibility.km = 10
@@ -259,40 +259,40 @@ describe "Weather" do
259
259
  it "returns averages" do
260
260
  @weather.visibility.km.should == 8
261
261
  end
262
-
262
+
263
263
  it "returns default when disabled" do
264
264
  @weather.visibility(false).km.should == 10
265
265
  end
266
-
266
+
267
267
  end
268
-
268
+
269
269
  end
270
-
270
+
271
271
  describe "when answering the simple questions," do
272
-
272
+
273
273
  before(:each) do
274
274
  @weather = Barometer::Weather.new
275
275
  @now = Data::LocalDateTime.parse("2:05 pm")
276
276
  end
277
-
277
+
278
278
  describe "windy?" do
279
-
279
+
280
280
  # it "requires time as a Data::LocalTime object" do
281
281
  # #lambda { @weather.windy?(1,"a") }.should raise_error(ArgumentError)
282
282
  # lambda { @weather.windy?(1,@now) }.should_not raise_error(ArgumentError)
283
283
  # end
284
-
284
+
285
285
  it "requires threshold as a number" do
286
286
  lambda { @weather.windy?(@now,"a") }.should raise_error(ArgumentError)
287
287
  lambda { @weather.windy?(@now,1) }.should_not raise_error(ArgumentError)
288
288
  lambda { @weather.windy?(@now,1.1) }.should_not raise_error(ArgumentError)
289
289
  end
290
-
290
+
291
291
  it "returns nil when no measurements" do
292
292
  @weather.measurements.should be_empty
293
293
  @weather.windy?.should be_nil
294
294
  end
295
-
295
+
296
296
  it "returns true if a measurement returns true" do
297
297
  wunderground = Barometer::Measurement.new(:wunderground)
298
298
  wunderground.stub!(:success).and_return(true)
@@ -310,27 +310,27 @@ describe "Weather" do
310
310
  @weather.measurements.each { |m| m.stub!(:windy?).and_return(false) }
311
311
  @weather.windy?.should be_false
312
312
  end
313
-
313
+
314
314
  end
315
-
315
+
316
316
  describe "wet?" do
317
-
317
+
318
318
  it "requires threshold as a number" do
319
319
  lambda { @weather.wet?(@now,"a") }.should raise_error(ArgumentError)
320
320
  lambda { @weather.wet?(@now,1) }.should_not raise_error(ArgumentError)
321
321
  lambda { @weather.wet?(@now,1.1) }.should_not raise_error(ArgumentError)
322
322
  end
323
-
323
+
324
324
  # it "requires time as a Data::LocalTime object" do
325
325
  # #lambda { @weather.wet?(1,"a") }.should raise_error(ArgumentError)
326
326
  # lambda { @weather.wet?(1,@now) }.should_not raise_error(ArgumentError)
327
327
  # end
328
-
328
+
329
329
  it "returns nil when no measurements" do
330
330
  @weather.measurements.should be_empty
331
331
  @weather.wet?.should be_nil
332
332
  end
333
-
333
+
334
334
  it "returns true if a measurement returns true" do
335
335
  wunderground = Barometer::Measurement.new(:wunderground)
336
336
  wunderground.stub!(:success).and_return(true)
@@ -348,27 +348,27 @@ describe "Weather" do
348
348
  @weather.measurements.each { |m| m.stub!(:wet?).and_return(false) }
349
349
  @weather.wet?.should be_false
350
350
  end
351
-
351
+
352
352
  end
353
-
353
+
354
354
  describe "day? and night?" do
355
-
355
+
356
356
  it "requires time as a Data::LocalTime object" do
357
357
  #lambda { @weather.day?("a") }.should raise_error(ArgumentError)
358
358
  lambda { @weather.day?(@now) }.should_not raise_error(ArgumentError)
359
359
  end
360
-
360
+
361
361
  it "requires time as a Data::LocalTime object" do
362
362
  #lambda { @weather.night?("a") }.should raise_error(ArgumentError)
363
363
  lambda { @weather.night?(@now) }.should_not raise_error(ArgumentError)
364
364
  end
365
-
365
+
366
366
  it "returns nil when no measurements" do
367
367
  @weather.measurements.should be_empty
368
368
  @weather.day?.should be_nil
369
369
  @weather.night?.should be_nil
370
370
  end
371
-
371
+
372
372
  it "returns true if a measurement returns true (night is opposite)" do
373
373
  wunderground = Barometer::Measurement.new(:wunderground)
374
374
  wunderground.stub!(:success).and_return(true)
@@ -388,21 +388,21 @@ describe "Weather" do
388
388
  @weather.day?.should be_false
389
389
  @weather.night?.should be_true
390
390
  end
391
-
391
+
392
392
  end
393
-
393
+
394
394
  describe "sunny?" do
395
-
395
+
396
396
  it "requires time as a Data::LocalTime object" do
397
397
  #lambda { @weather.sunny?("a") }.should raise_error(ArgumentError)
398
398
  lambda { @weather.sunny?(@now) }.should_not raise_error(ArgumentError)
399
399
  end
400
-
400
+
401
401
  it "returns nil when no measurements" do
402
402
  @weather.measurements.should be_empty
403
403
  @weather.sunny?.should be_nil
404
404
  end
405
-
405
+
406
406
  it "returns true if a measurement returns true" do
407
407
  wunderground = Barometer::Measurement.new(:wunderground)
408
408
  wunderground.stub!(:success).and_return(true)
@@ -422,7 +422,7 @@ describe "Weather" do
422
422
  @weather.measurements.each { |m| m.stub!(:sunny?).and_return(false) }
423
423
  @weather.sunny?.should be_false
424
424
  end
425
-
425
+
426
426
  it "returns false if night time" do
427
427
  wunderground = Barometer::Measurement.new(:wunderground)
428
428
  wunderground.stub!(:success).and_return(true)
@@ -434,7 +434,7 @@ describe "Weather" do
434
434
  end
435
435
 
436
436
  end
437
-
437
+
438
438
  end
439
-
440
- end
439
+
440
+ end