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,36 +1,36 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::Zone" do
4
-
4
+
5
5
  # describe "and class methods" do
6
- #
6
+ #
7
7
  # it "responds to now and returns Time object" do
8
8
  # Data::Zone.respond_to?("now").should be_true
9
9
  # Data::Zone.now.is_a?(Time).should be_true
10
10
  # end
11
- #
11
+ #
12
12
  # it "responds to today and returns Date object" do
13
13
  # Data::Zone.respond_to?("today").should be_true
14
14
  # Data::Zone.today.is_a?(Date).should be_true
15
15
  # end
16
- #
16
+ #
17
17
  # end
18
-
18
+
19
19
  describe "when initialized" do
20
-
20
+
21
21
  describe "with a full zone" do
22
-
22
+
23
23
  before(:each) do
24
24
  @utc = Time.now.utc
25
25
  @timezone = "Europe/Paris"
26
26
  @zone = Data::Zone.new(@timezone)
27
27
  end
28
-
28
+
29
29
  it "responds to zone_full" do
30
30
  @zone.zone_full.should_not be_nil
31
31
  @zone.zone_full.should == @timezone
32
32
  end
33
-
33
+
34
34
  it "responds to zone_code" do
35
35
  @zone.zone_code.should be_nil
36
36
  end
@@ -41,22 +41,22 @@ describe "Data::Zone" do
41
41
 
42
42
  it "responds to tz" do
43
43
  lambda { Data::Zone.new("invalid timezone") }.should raise_error(ArgumentError)
44
-
44
+
45
45
  zone = Data::Zone.new(@timezone)
46
46
  zone.tz.should_not be_nil
47
47
  end
48
-
48
+
49
49
  it "responds to full" do
50
50
  @zone.respond_to?("full").should be_true
51
51
  zone = Data::Zone.new(@timezone)
52
52
  zone.tz = nil
53
53
  zone.tz.should be_nil
54
54
  zone.full.should == @timezone
55
-
55
+
56
56
  zone = Data::Zone.new(@timezone)
57
57
  zone.full.should == @timezone
58
58
  end
59
-
59
+
60
60
  it "responds to code" do
61
61
  @zone.respond_to?("code").should be_true
62
62
  zone = Data::Zone.new(@timezone)
@@ -78,14 +78,14 @@ describe "Data::Zone" do
78
78
  zone.tz.should be_nil
79
79
  zone.dst?.should be_nil
80
80
  end
81
-
81
+
82
82
  it "responds to now" do
83
83
  @zone.respond_to?("now").should be_true
84
84
  @zone.now.is_a?(Time).should be_true
85
-
85
+
86
86
  period = @zone.tz.period_for_utc(Time.now)
87
87
  actual_now = Time.now.utc + period.utc_total_offset
88
-
88
+
89
89
  now = @zone.now
90
90
  now.hour.should == actual_now.hour
91
91
  now.min.should == actual_now.min
@@ -94,40 +94,40 @@ describe "Data::Zone" do
94
94
  now.month.should == actual_now.month
95
95
  now.day.should == actual_now.day
96
96
  end
97
-
97
+
98
98
  it "responds to today" do
99
99
  @zone.respond_to?("today").should be_true
100
100
  @zone.today.is_a?(Date).should be_true
101
-
101
+
102
102
  period = @zone.tz.period_for_utc(Time.now)
103
103
  actual_now = Time.now.utc + period.utc_total_offset
104
-
104
+
105
105
  now = @zone.today
106
106
  now.year.should == actual_now.year
107
107
  now.month.should == actual_now.month
108
108
  now.day.should == actual_now.day
109
109
  end
110
-
110
+
111
111
  it "converts local_time to utc" do
112
112
  local_time = Time.now.utc
113
113
  utc_time = @zone.local_to_utc(local_time)
114
-
114
+
115
115
  offset = @zone.tz.period_for_utc(local_time).utc_total_offset
116
116
  utc_time.should == (local_time - offset)
117
117
  end
118
-
118
+
119
119
  it "converts utc to local_time" do
120
120
  utc_time = Time.now.utc
121
121
  local_time = @zone.utc_to_local(utc_time)
122
-
122
+
123
123
  offset = @zone.tz.period_for_utc(local_time).utc_total_offset
124
124
  utc_time.should == (local_time - offset)
125
125
  end
126
-
126
+
127
127
  end
128
-
128
+
129
129
  describe "with a zone code" do
130
-
130
+
131
131
  before(:each) do
132
132
  @utc = Time.now.utc
133
133
  @timezone = "EAST"
@@ -226,9 +226,9 @@ describe "Data::Zone" do
226
226
  end
227
227
 
228
228
  end
229
-
229
+
230
230
  describe "with a zone offset" do
231
-
231
+
232
232
  before(:each) do
233
233
  @utc = Time.now.utc
234
234
  @timezone = 8.5
@@ -338,29 +338,29 @@ describe "Data::Zone" do
338
338
  end
339
339
 
340
340
  end
341
-
341
+
342
342
  end
343
-
343
+
344
344
  describe "when detecting zones" do
345
-
345
+
346
346
  it "recognozes a full time zone format" do
347
347
  Data::Zone.is_zone_full?("invalid").should be_false
348
348
  Data::Zone.is_zone_full?("America/New York").should be_true
349
349
  end
350
-
350
+
351
351
  it "matches a zone offset" do
352
352
  Data::Zone.is_zone_offset?("invalid").should be_false
353
353
  Data::Zone.is_zone_offset?("MST").should be_false
354
354
  Data::Zone.is_zone_offset?("10").should be_false
355
355
  Data::Zone.is_zone_offset?(-10).should be_true
356
356
  end
357
-
357
+
358
358
  it "matches a zone code" do
359
359
  Data::Zone.is_zone_code?("invalid").should be_false
360
360
  Data::Zone.is_zone_code?("MST").should be_true
361
361
  Data::Zone.is_zone_code?("EAST").should be_true
362
362
  end
363
-
363
+
364
364
  end
365
-
365
+
366
366
  end
@@ -1,7 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Query::Coordinates" do
4
-
3
+ describe Barometer::Query::Format::Coordinates, :vcr => {
4
+ :cassette_name => "Query::Format::Coordinates"
5
+ } do
5
6
  before(:each) do
6
7
  @short_zipcode = "90210"
7
8
  @zipcode = @short_zipcode
@@ -12,22 +13,21 @@ describe "Query::Coordinates" do
12
13
  @geocode = "New York, NY"
13
14
  @icao = "KSFO"
14
15
  end
15
-
16
+
16
17
  describe "and class methods" do
17
-
18
18
  it "returns a format" do
19
19
  Barometer::Query::Format::Coordinates.format.should == :coordinates
20
20
  end
21
-
21
+
22
22
  it "returns a country" do
23
23
  Barometer::Query::Format::Coordinates.country_code.should be_nil
24
24
  end
25
-
25
+
26
26
  it "returns a regex" do
27
27
  Barometer::Query::Format::Coordinates.regex.should_not be_nil
28
28
  Barometer::Query::Format::Coordinates.regex.is_a?(Regexp).should be_true
29
29
  end
30
-
30
+
31
31
  it "returns the convertable_formats" do
32
32
  Barometer::Query::Format::Coordinates.convertable_formats.should_not be_nil
33
33
  Barometer::Query::Format::Coordinates.convertable_formats.is_a?(Array).should be_true
@@ -39,26 +39,23 @@ describe "Query::Coordinates" do
39
39
  Barometer::Query::Format::Coordinates.convertable_formats.include?(:icao).should be_true
40
40
  Barometer::Query::Format::Coordinates.convertable_formats.include?(:geocode).should be_true
41
41
  end
42
-
42
+
43
43
  describe "is?," do
44
-
45
44
  before(:each) do
46
45
  @valid = "40.756054,-73.986951"
47
46
  @invalid = "invalid"
48
47
  end
49
-
48
+
50
49
  it "recognizes a valid format" do
51
50
  Barometer::Query::Format::Coordinates.is?(@valid).should be_true
52
51
  end
53
-
52
+
54
53
  it "recognizes non-valid format" do
55
54
  Barometer::Query::Format::Coordinates.is?(@invalid).should be_false
56
55
  end
57
-
58
56
  end
59
-
57
+
60
58
  describe "when converting using 'to'," do
61
-
62
59
  it "requires a Query::Format object" do
63
60
  lambda { Barometer::Query::Format::Coordinates.to }.should raise_error(ArgumentError)
64
61
  lambda { Barometer::Query::Format::Coordinates.to("invalid") }.should raise_error(ArgumentError)
@@ -66,7 +63,7 @@ describe "Query::Coordinates" do
66
63
  query.is_a?(Barometer::Query).should be_true
67
64
  lambda { Barometer::Query::Format::Coordinates.to(original_query) }.should_not raise_error(ArgumentError)
68
65
  end
69
-
66
+
70
67
  it "returns a Barometer::Query" do
71
68
  query = Barometer::Query.new(@short_zipcode)
72
69
  Barometer::Query::Format::Coordinates.to(query).is_a?(Barometer::Query).should be_true
@@ -107,7 +104,11 @@ describe "Query::Coordinates" do
107
104
  query = Barometer::Query.new(@geocode)
108
105
  query.format.should == :geocode
109
106
  new_query = Barometer::Query::Format::Coordinates.to(query)
110
- new_query.q.should == "40.7143528,-74.00597309999999"
107
+
108
+ new_query_coords = new_query.q.split(',').map{|c| c.to_f}
109
+ new_query_coords[0].should be_within(0.00001).of(40.7143528)
110
+ new_query_coords[1].should be_within(0.00001).of(-74.0059731)
111
+
111
112
  new_query.country_code.should == "US"
112
113
  new_query.format.should == :coordinates
113
114
  new_query.geo.should_not be_nil
@@ -117,7 +118,7 @@ describe "Query::Coordinates" do
117
118
  query = Barometer::Query.new(@postal_code)
118
119
  query.format.should == :postalcode
119
120
  new_query = Barometer::Query::Format::Coordinates.to(query)
120
- new_query.q.should == "53.570516,-113.45784"
121
+ new_query.q.should == "53.5721719,-113.4551835"
121
122
  new_query.country_code.should == "CA"
122
123
  new_query.format.should == :coordinates
123
124
  new_query.geo.should_not be_nil
@@ -137,30 +138,29 @@ describe "Query::Coordinates" do
137
138
  query = Barometer::Query.new(@coordinates)
138
139
  query.format.should == :coordinates
139
140
  new_query = Barometer::Query::Format::Coordinates.to(query)
140
- new_query.q.should == "40.7560395,-73.9869147"
141
+
142
+ new_query_coords = new_query.q.split(',').map{|c| c.to_f}
143
+ new_query_coords[0].should be_within(0.00001).of(40.7560413)
144
+ new_query_coords[1].should be_within(0.00001).of(-73.9869192)
145
+
141
146
  new_query.country_code.should == "US"
142
147
  new_query.format.should == :coordinates
143
148
  new_query.geo.should_not be_nil
144
149
  end
145
-
146
150
  end
147
-
151
+
148
152
  describe "parsing" do
149
-
150
153
  it "returns the latitude" do
151
154
  Barometer::Query::Format::Coordinates.parse_latitude(@coordinates).should == "40.756054"
152
155
  end
153
-
156
+
154
157
  it "returns the longitude" do
155
158
  Barometer::Query::Format::Coordinates.parse_longitude(@coordinates).should == "-73.986951"
156
159
  end
157
-
160
+
158
161
  it "returns nil when unknown" do
159
162
  Barometer::Query::Format::Coordinates.parse_longitude(@short_zipcode).should be_nil
160
163
  end
161
-
162
164
  end
163
-
164
165
  end
165
-
166
- end
166
+ end
@@ -1,44 +1,38 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Query::Format" do
4
-
3
+ describe Barometer::Query::Format do
5
4
  describe "and class methods" do
6
-
7
5
  describe "is?," do
8
-
9
6
  it "requires a String" do
10
7
  invalid = 1
11
8
  lambda { Barometer::Query::Format.is?(invalid) }.should raise_error(ArgumentError)
12
-
9
+
13
10
  valid = "string"
14
11
  valid.is_a?(String).should be_true
15
12
  lambda { Barometer::Query::Format.is?(valid) }.should_not raise_error(ArgumentError)
16
13
  end
17
-
14
+
18
15
  it "calls a stubbed undefined method" do
19
16
  lambda { Barometer::Query::Format.is?("valid") }.should raise_error(NotImplementedError)
20
- end
21
-
17
+ end
22
18
  end
23
-
19
+
24
20
  describe "converts?," do
25
-
26
21
  it "requires a Query object" do
27
22
  invalid = 1
28
23
  Barometer::Query::Format.converts?(invalid).should be_false
29
-
24
+
30
25
  valid = Barometer::Query.new
31
26
  valid.is_a?(Barometer::Query).should be_true
32
27
  lambda { Barometer::Query::Format.converts?(valid) }.should_not raise_error(ArgumentError)
33
28
  end
34
-
29
+
35
30
  it "returns false" do
36
31
  valid = Barometer::Query.new
37
32
  Barometer::Query::Format.converts?(valid).should be_false
38
- end
39
-
33
+ end
40
34
  end
41
-
35
+
42
36
  it "detects a Query object" do
43
37
  invalid = 1
44
38
  Barometer::Query::Format.is_a_query?.should be_false
@@ -47,36 +41,34 @@ describe "Query::Format" do
47
41
  valid.is_a?(Barometer::Query).should be_true
48
42
  Barometer::Query::Format.is_a_query?(valid).should be_true
49
43
  end
50
-
44
+
51
45
  it "stubs regex" do
52
46
  lambda { Barometer::Query::Format.regex }.should raise_error(NotImplementedError)
53
47
  end
54
-
48
+
55
49
  it "stubs format" do
56
50
  lambda { Barometer::Query::Format.format }.should raise_error(NotImplementedError)
57
51
  end
58
-
52
+
59
53
  it "stubs to" do
60
54
  Barometer::Query::Format.to.should be_nil
61
55
  end
62
-
56
+
63
57
  it "stubs country_code" do
64
58
  Barometer::Query::Format.country_code.should be_nil
65
59
  end
66
-
60
+
67
61
  it "stubs convertable_formats" do
68
62
  Barometer::Query::Format.convertable_formats.should == []
69
63
  end
70
-
64
+
71
65
  it "stubs convert_query" do
72
66
  Barometer::Query::Format.respond_to?(:convert_query).should be_true
73
67
  end
74
-
68
+
75
69
  it "normally does nothing when converting a query" do
76
70
  text = "this is a query"
77
71
  Barometer::Query::Format.convert_query(text).should == text
78
72
  end
79
-
80
73
  end
81
-
82
- end
74
+ end
@@ -1,7 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Query::Geocode" do
4
-
3
+ describe Barometer::Query::Format::Geocode, :vcr => {
4
+ :cassette_name => "Query::Format::Geocode"
5
+ } do
5
6
  before(:each) do
6
7
  @short_zipcode = "90210"
7
8
  @zipcode = @short_zipcode
@@ -12,17 +13,16 @@ describe "Query::Geocode" do
12
13
  @geocode = "New York, NY"
13
14
  @icao = "KSFO"
14
15
  end
15
-
16
+
16
17
  describe "and class methods" do
17
-
18
18
  it "returns a format" do
19
19
  Barometer::Query::Format::Geocode.format.should == :geocode
20
20
  end
21
-
21
+
22
22
  it "returns a country" do
23
23
  Barometer::Query::Format::Geocode.country_code.should be_nil
24
24
  end
25
-
25
+
26
26
  it "returns the convertable_formats" do
27
27
  Barometer::Query::Format::Geocode.convertable_formats.should_not be_nil
28
28
  Barometer::Query::Format::Geocode.convertable_formats.is_a?(Array).should be_true
@@ -32,26 +32,23 @@ describe "Query::Geocode" do
32
32
  Barometer::Query::Format::Geocode.convertable_formats.include?(:weather_id).should be_true
33
33
  Barometer::Query::Format::Geocode.convertable_formats.include?(:icao).should be_true
34
34
  end
35
-
35
+
36
36
  describe "is?," do
37
-
38
37
  before(:each) do
39
38
  @valid = "New York, NY"
40
39
  end
41
-
40
+
42
41
  it "recognizes a valid format" do
43
42
  Barometer::Query::Format::Geocode.is?(@valid).should be_true
44
43
  Barometer::Query::Format::Geocode.is?.should be_false
45
44
  end
46
-
47
45
  end
48
-
46
+
49
47
  describe "when converting using 'to'," do
50
-
51
48
  before(:each) do
52
49
  Barometer.force_geocode = false
53
50
  end
54
-
51
+
55
52
  it "requires a Barometer::Query object" do
56
53
  lambda { Barometer::Query::Format::Geocode.to }.should raise_error(ArgumentError)
57
54
  lambda { Barometer::Query::Format::Geocode.to("invalid") }.should raise_error(ArgumentError)
@@ -59,12 +56,12 @@ describe "Query::Geocode" do
59
56
  query.is_a?(Barometer::Query).should be_true
60
57
  lambda { Barometer::Query::Format::Geocode.to(query) }.should_not raise_error(ArgumentError)
61
58
  end
62
-
59
+
63
60
  it "returns a Barometer::Query" do
64
61
  query = Barometer::Query.new(@short_zipcode)
65
62
  Barometer::Query::Format::Geocode.to(query).is_a?(Barometer::Query).should be_true
66
63
  end
67
-
64
+
68
65
  it "converts from short_zipcode" do
69
66
  query = Barometer::Query.new(@short_zipcode)
70
67
  query.format.should == :short_zipcode
@@ -74,7 +71,7 @@ describe "Query::Geocode" do
74
71
  new_query.format.should == :geocode
75
72
  new_query.geo.should_not be_nil
76
73
  end
77
-
74
+
78
75
  it "converts from zipcode" do
79
76
  query = Barometer::Query.new(@zipcode)
80
77
  query.format = :zipcode
@@ -85,7 +82,7 @@ describe "Query::Geocode" do
85
82
  new_query.format.should == :geocode
86
83
  new_query.geo.should_not be_nil
87
84
  end
88
-
85
+
89
86
  it "converts from weather_id" do
90
87
  query = Barometer::Query.new(@weather_id)
91
88
  query.format.should == :weather_id
@@ -95,7 +92,7 @@ describe "Query::Geocode" do
95
92
  new_query.format.should == :geocode
96
93
  new_query.geo.should be_nil
97
94
  end
98
-
95
+
99
96
  it "converts from coordinates" do
100
97
  query = Barometer::Query.new(@coordinates)
101
98
  query.format.should == :coordinates
@@ -105,7 +102,7 @@ describe "Query::Geocode" do
105
102
  new_query.format.should == :geocode
106
103
  new_query.geo.should_not be_nil
107
104
  end
108
-
105
+
109
106
  it "converts from icao" do
110
107
  query = Barometer::Query.new(@icao)
111
108
  query.format.should == :icao
@@ -115,14 +112,14 @@ describe "Query::Geocode" do
115
112
  new_query.format.should == :geocode
116
113
  new_query.geo.should_not be_nil
117
114
  end
118
-
115
+
119
116
  it "does not convert postalcode" do
120
117
  query = Barometer::Query.new(@postal_code)
121
118
  query.format.should == :postalcode
122
119
  new_query = Barometer::Query::Format::Geocode.to(query)
123
120
  new_query.should be_nil
124
121
  end
125
-
122
+
126
123
  it "leaves geocode untouched" do
127
124
  query = Barometer::Query.new(@geocode)
128
125
  query.format.should == :geocode
@@ -132,11 +129,9 @@ describe "Query::Geocode" do
132
129
  new_query.format.should == :geocode
133
130
  new_query.geo.should be_nil
134
131
  end
135
-
136
132
  end
137
-
133
+
138
134
  describe "when geocoding" do
139
-
140
135
  it "requires a Barometer::Query object" do
141
136
  lambda { Barometer::Query::Format::Geocode.geocode }.should raise_error(ArgumentError)
142
137
  lambda { Barometer::Query::Format::Geocode.geocode("invalid") }.should raise_error(ArgumentError)
@@ -144,12 +139,12 @@ describe "Query::Geocode" do
144
139
  query.is_a?(Barometer::Query).should be_true
145
140
  lambda { Barometer::Query::Format::Geocode.geocode(original_query) }.should_not raise_error(ArgumentError)
146
141
  end
147
-
142
+
148
143
  it "returns a Barometer::Query" do
149
144
  query = Barometer::Query.new(@short_zipcode)
150
145
  Barometer::Query::Format::Geocode.geocode(query).is_a?(Barometer::Query).should be_true
151
146
  end
152
-
147
+
153
148
  it "converts from short_zipcode" do
154
149
  query = Barometer::Query.new(@short_zipcode)
155
150
  query.format.should == :short_zipcode
@@ -159,13 +154,10 @@ describe "Query::Geocode" do
159
154
  new_query.format.should == :geocode
160
155
  new_query.geo.should_not be_nil
161
156
  end
162
-
163
157
  end
164
-
158
+
165
159
  it "doesn't define a regex" do
166
160
  lambda { Barometer::Query::Format::Geocode.regex }.should raise_error(NotImplementedError)
167
161
  end
168
-
169
162
  end
170
-
171
- end
163
+ end