barometer 0.5.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/README.rdoc +51 -9
  2. data/VERSION.yml +2 -2
  3. data/bin/barometer +57 -7
  4. data/lib/barometer.rb +11 -0
  5. data/lib/barometer/base.rb +3 -0
  6. data/lib/barometer/data.rb +11 -6
  7. data/lib/barometer/data/sun.rb +10 -0
  8. data/lib/barometer/data/zone.rb +79 -188
  9. data/lib/barometer/formats/coordinates.rb +4 -1
  10. data/lib/barometer/formats/geocode.rb +9 -7
  11. data/lib/barometer/formats/icao.rb +2 -2
  12. data/lib/barometer/formats/weather_id.rb +2 -2
  13. data/lib/barometer/measurements/common.rb +113 -0
  14. data/lib/barometer/{data → measurements}/current.rb +17 -42
  15. data/lib/barometer/measurements/forecast.rb +62 -0
  16. data/lib/barometer/measurements/forecast_array.rb +72 -0
  17. data/lib/barometer/{data → measurements}/measurement.rb +57 -45
  18. data/lib/barometer/measurements/night.rb +27 -0
  19. data/lib/barometer/query.rb +55 -5
  20. data/lib/barometer/services.rb +3 -1
  21. data/lib/barometer/translations/icao_country_codes.yml +274 -1
  22. data/lib/barometer/translations/weather_country_codes.yml +189 -6
  23. data/lib/barometer/translations/zone_codes.yml +360 -0
  24. data/lib/barometer/weather.rb +5 -4
  25. data/lib/barometer/weather_services/google.rb +19 -35
  26. data/lib/barometer/weather_services/service.rb +113 -255
  27. data/lib/barometer/weather_services/weather_bug.rb +291 -2
  28. data/lib/barometer/weather_services/weather_dot_com.rb +45 -54
  29. data/lib/barometer/weather_services/wunderground.rb +83 -89
  30. data/lib/barometer/weather_services/yahoo.rb +44 -91
  31. data/lib/barometer/web_services/geocode.rb +1 -0
  32. data/lib/barometer/web_services/timezone.rb +40 -0
  33. data/lib/barometer/web_services/weather_id.rb +17 -2
  34. data/lib/demometer/demometer.rb +28 -0
  35. data/lib/demometer/public/css/master.css +259 -1
  36. data/lib/demometer/public/css/print.css +94 -0
  37. data/lib/demometer/public/css/syntax.css +64 -0
  38. data/lib/demometer/public/images/link-out.gif +0 -0
  39. data/lib/demometer/views/about.erb +10 -0
  40. data/lib/demometer/views/index.erb +2 -0
  41. data/lib/demometer/views/layout.erb +3 -2
  42. data/lib/demometer/views/measurement.erb +4 -1
  43. data/lib/demometer/views/readme.erb +116 -88
  44. data/spec/data/sun_spec.rb +53 -0
  45. data/spec/data/zone_spec.rb +330 -100
  46. data/spec/fixtures/formats/weather_id/ksfo.xml +1 -0
  47. data/spec/fixtures/services/weather_bug/90210_current.xml +1 -0
  48. data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -0
  49. data/spec/formats/weather_id_spec.rb +10 -5
  50. data/spec/measurements/common_spec.rb +352 -0
  51. data/spec/{data → measurements}/current_spec.rb +40 -103
  52. data/spec/measurements/forecast_array_spec.rb +165 -0
  53. data/spec/measurements/forecast_spec.rb +135 -0
  54. data/spec/{data → measurements}/measurement_spec.rb +86 -107
  55. data/spec/measurements/night_measurement_spec.rb +49 -0
  56. data/spec/query_spec.rb +12 -2
  57. data/spec/spec_helper.rb +28 -1
  58. data/spec/weather_services/google_spec.rb +27 -117
  59. data/spec/weather_services/services_spec.rb +49 -1024
  60. data/spec/weather_services/weather_bug_spec.rb +274 -0
  61. data/spec/weather_services/weather_dot_com_spec.rb +45 -125
  62. data/spec/weather_services/wunderground_spec.rb +42 -136
  63. data/spec/weather_services/yahoo_spec.rb +26 -116
  64. data/spec/weather_spec.rb +45 -45
  65. metadata +27 -11
  66. data/lib/barometer/data/forecast.rb +0 -84
  67. data/lib/barometer/data/night.rb +0 -69
  68. data/lib/barometer/extensions/graticule.rb +0 -51
  69. data/spec/data/forecast_spec.rb +0 -192
  70. data/spec/data/night_measurement_spec.rb +0 -136
@@ -1,51 +0,0 @@
1
- module Graticule
2
- class Location
3
-
4
- attr_accessor :country_code, :address_line
5
-
6
- def attributes
7
- [:latitude, :longitude, :street, :locality, :region, :postal_code, :country, :precision, :cuntry_code, :address_line].inject({}) do |result,attr|
8
- result[attr] = self.send(attr) unless self.send(attr).blank?
9
- result
10
- end
11
- end
12
-
13
- end
14
-
15
- module Geocoder
16
-
17
- class Google < Rest
18
-
19
- # Locates +address+ returning a Location
20
- # add ability to bias towards a country
21
- def locate(address, country_bias=nil)
22
- get :q => (address.is_a?(String) ? address : location_from_params(address).to_s),
23
- :gl => country_bias
24
- end
25
-
26
- private
27
-
28
- # Extracts a Location from +xml+.
29
- def parse_response(xml) #:nodoc:
30
- longitude, latitude, = xml.elements['/kml/Response/Placemark/Point/coordinates'].text.split(',').map { |v| v.to_f }
31
- returning Location.new(:latitude => latitude, :longitude => longitude) do |l|
32
- address = REXML::XPath.first(xml, '//xal:AddressDetails',
33
- 'xal' => "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0")
34
-
35
- if address
36
- l.street = value(address.elements['.//ThoroughfareName/text()'])
37
- l.locality = value(address.elements['.//LocalityName/text()'])
38
- l.region = value(address.elements['.//AdministrativeAreaName/text()'])
39
- l.postal_code = value(address.elements['.//PostalCodeNumber/text()'])
40
- l.country = value(address.elements['.//CountryName/text()'])
41
- l.country_code = value(address.elements['.//CountryNameCode/text()'])
42
- l.address_line = value(address.elements['.//AddressLine/text()'])
43
- l.precision = PRECISION[address.attribute('Accuracy').value.to_i] || :unknown
44
- end
45
- end
46
- end
47
-
48
- end
49
-
50
- end
51
- end
@@ -1,192 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Forecast Measurement" do
4
-
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @forecast = Data::ForecastMeasurement.new
9
- end
10
-
11
- it "responds to date" do
12
- @forecast.date.should be_nil
13
- end
14
-
15
- it "responds to icon" do
16
- @forecast.icon.should be_nil
17
- end
18
-
19
- it "responds to condition" do
20
- @forecast.condition.should be_nil
21
- end
22
-
23
- it "responds to low" do
24
- @forecast.low.should be_nil
25
- end
26
-
27
- it "responds to high" do
28
- @forecast.high.should be_nil
29
- end
30
-
31
- it "responds to pop" do
32
- @forecast.pop.should be_nil
33
- end
34
-
35
- it "responds to humidity" do
36
- @forecast.humidity.should be_nil
37
- end
38
-
39
- it "responds to wind" do
40
- @forecast.wind.should be_nil
41
- end
42
-
43
- it "responds to sun" do
44
- @forecast.sun.should be_nil
45
- end
46
-
47
- it "responds to night" do
48
- @forecast.night.should be_nil
49
- end
50
-
51
- end
52
-
53
- describe "when writing data" do
54
-
55
- before(:each) do
56
- @forecast = Data::ForecastMeasurement.new
57
- end
58
-
59
- it "only accepts Date for date" do
60
- invalid_data = 1
61
- invalid_data.class.should_not == Date
62
- lambda { @forecast.date = invalid_data }.should raise_error(ArgumentError)
63
-
64
- valid_data = Date.new
65
- valid_data.class.should == Date
66
- lambda { @forecast.date = valid_data }.should_not raise_error(ArgumentError)
67
- end
68
-
69
- it "only accepts String for icon" do
70
- invalid_data = 1
71
- invalid_data.class.should_not == String
72
- lambda { @forecast.icon = invalid_data }.should raise_error(ArgumentError)
73
-
74
- valid_data = "valid"
75
- valid_data.class.should == String
76
- lambda { @forecast.icon = valid_data }.should_not raise_error(ArgumentError)
77
- end
78
-
79
- it "only accepts String for condition" do
80
- invalid_data = 1
81
- invalid_data.class.should_not == String
82
- lambda { @forecast.condition = invalid_data }.should raise_error(ArgumentError)
83
-
84
- valid_data = "valid"
85
- valid_data.class.should == String
86
- lambda { @forecast.condition = valid_data }.should_not raise_error(ArgumentError)
87
- end
88
-
89
- it "only accepts Data::Temperature for high" do
90
- invalid_data = 1
91
- invalid_data.class.should_not == Data::Temperature
92
- lambda { @forecast.high = invalid_data }.should raise_error(ArgumentError)
93
-
94
- valid_data = Data::Temperature.new
95
- valid_data.class.should == Data::Temperature
96
- lambda { @forecast.high = valid_data }.should_not raise_error(ArgumentError)
97
- end
98
-
99
- it "only accepts Data::Temperature for low" do
100
- invalid_data = 1
101
- invalid_data.class.should_not == Data::Temperature
102
- lambda { @forecast.low = invalid_data }.should raise_error(ArgumentError)
103
-
104
- valid_data = Data::Temperature.new
105
- valid_data.class.should == Data::Temperature
106
- lambda { @forecast.low = valid_data }.should_not raise_error(ArgumentError)
107
- end
108
-
109
- it "only accepts Fixnum for pop" do
110
- invalid_data = "test"
111
- invalid_data.class.should_not == Fixnum
112
- lambda { @forecast.pop = invalid_data }.should raise_error(ArgumentError)
113
-
114
- valid_data = 50
115
- valid_data.class.should == Fixnum
116
- lambda { @forecast.pop = valid_data }.should_not raise_error(ArgumentError)
117
- end
118
-
119
- it "only accepts Data::Speed for wind" do
120
- invalid_data = "test"
121
- invalid_data.class.should_not == Data::Speed
122
- lambda { @forecast.wind = invalid_data }.should raise_error(ArgumentError)
123
-
124
- valid_data = Data::Speed.new
125
- valid_data.class.should == Data::Speed
126
- lambda { @forecast.wind = valid_data }.should_not raise_error(ArgumentError)
127
- end
128
-
129
- it "only accepts Fixnum for humidity" do
130
- invalid_data = "test"
131
- invalid_data.class.should_not == Fixnum
132
- lambda { @forecast.humidity = invalid_data }.should raise_error(ArgumentError)
133
-
134
- valid_data = 50
135
- valid_data.class.should == Fixnum
136
- lambda { @forecast.humidity = valid_data }.should_not raise_error(ArgumentError)
137
- end
138
-
139
- it "only accepts Data::Sun for sun" do
140
- invalid_data = 1
141
- invalid_data.class.should_not == Data::Sun
142
- lambda { @forecast.sun = invalid_data }.should raise_error(ArgumentError)
143
-
144
- valid_data = Data::Sun.new
145
- valid_data.class.should == Data::Sun
146
- lambda { @forecast.sun = valid_data }.should_not raise_error(ArgumentError)
147
- end
148
-
149
- it "only accepts Data::NightMeasurement for sun" do
150
- invalid_data = 1
151
- invalid_data.class.should_not == Data::NightMeasurement
152
- lambda { @forecast.night = invalid_data }.should raise_error(ArgumentError)
153
-
154
- valid_data = Data::NightMeasurement.new
155
- valid_data.class.should == Data::NightMeasurement
156
- lambda { @forecast.night = valid_data }.should_not raise_error(ArgumentError)
157
- end
158
-
159
- end
160
-
161
- describe "method missing" do
162
-
163
- before(:each) do
164
- @forecast = Data::ForecastMeasurement.new
165
- end
166
-
167
- it "responds to method + ?" do
168
- valid_method = "pop"
169
- @forecast.respond_to?(valid_method).should be_true
170
- lambda { @forecast.send(valid_method + "?") }.should_not raise_error(NoMethodError)
171
- end
172
-
173
- it "ignores non_method + ?" do
174
- invalid_method = "humid"
175
- @forecast.respond_to?(invalid_method).should be_false
176
- lambda { @forecast.send(invalid_method + "?") }.should raise_error(NoMethodError)
177
- end
178
-
179
- it "returns true if set" do
180
- @forecast.pop = 10
181
- @forecast.pop.should_not be_nil
182
- @forecast.pop?.should be_true
183
- end
184
-
185
- it "returns false if not set" do
186
- @forecast.pop.should be_nil
187
- @forecast.pop?.should be_false
188
- end
189
-
190
- end
191
-
192
- end
@@ -1,136 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Forecasted Night Measurement" do
4
-
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @night = Data::NightMeasurement.new
9
- end
10
-
11
- it "responds to date" do
12
- @night.date.should be_nil
13
- end
14
-
15
- it "responds to icon" do
16
- @night.icon.should be_nil
17
- end
18
-
19
- it "responds to condition" do
20
- @night.condition.should be_nil
21
- end
22
-
23
- it "responds to pop" do
24
- @night.pop.should be_nil
25
- end
26
-
27
- it "responds to humidity" do
28
- @night.humidity.should be_nil
29
- end
30
-
31
- it "responds to wind" do
32
- @night.wind.should be_nil
33
- end
34
-
35
- end
36
-
37
- describe "when writing data" do
38
-
39
- before(:each) do
40
- @night = Data::NightMeasurement.new
41
- end
42
-
43
- it "only accepts Date for date" do
44
- invalid_data = 1
45
- invalid_data.class.should_not == Date
46
- lambda { @night.date = invalid_data }.should raise_error(ArgumentError)
47
-
48
- valid_data = Date.new
49
- valid_data.class.should == Date
50
- lambda { @night.date = valid_data }.should_not raise_error(ArgumentError)
51
- end
52
-
53
- it "only accepts String for icon" do
54
- invalid_data = 1
55
- invalid_data.class.should_not == String
56
- lambda { @night.icon = invalid_data }.should raise_error(ArgumentError)
57
-
58
- valid_data = "valid"
59
- valid_data.class.should == String
60
- lambda { @night.icon = valid_data }.should_not raise_error(ArgumentError)
61
- end
62
-
63
- it "only accepts String for condition" do
64
- invalid_data = 1
65
- invalid_data.class.should_not == String
66
- lambda { @night.condition = invalid_data }.should raise_error(ArgumentError)
67
-
68
- valid_data = "valid"
69
- valid_data.class.should == String
70
- lambda { @night.condition = valid_data }.should_not raise_error(ArgumentError)
71
- end
72
-
73
- it "only accepts Fixnum for pop" do
74
- invalid_data = "test"
75
- invalid_data.class.should_not == Fixnum
76
- lambda { @night.pop = invalid_data }.should raise_error(ArgumentError)
77
-
78
- valid_data = 50
79
- valid_data.class.should == Fixnum
80
- lambda { @night.pop = valid_data }.should_not raise_error(ArgumentError)
81
- end
82
-
83
- it "only accepts Data::Speed for wind" do
84
- invalid_data = "test"
85
- invalid_data.class.should_not == Data::Speed
86
- lambda { @night.wind = invalid_data }.should raise_error(ArgumentError)
87
-
88
- valid_data = Data::Speed.new
89
- valid_data.class.should == Data::Speed
90
- lambda { @night.wind = valid_data }.should_not raise_error(ArgumentError)
91
- end
92
-
93
- it "only accepts Fixnum for humidity" do
94
- invalid_data = "test"
95
- invalid_data.class.should_not == Fixnum
96
- lambda { @night.humidity = invalid_data }.should raise_error(ArgumentError)
97
-
98
- valid_data = 50
99
- valid_data.class.should == Fixnum
100
- lambda { @night.humidity = valid_data }.should_not raise_error(ArgumentError)
101
- end
102
-
103
- end
104
-
105
- describe "method missing" do
106
-
107
- before(:each) do
108
- @night = Data::NightMeasurement.new
109
- end
110
-
111
- it "responds to method + ?" do
112
- valid_method = "pop"
113
- @night.respond_to?(valid_method).should be_true
114
- lambda { @night.send(valid_method + "?") }.should_not raise_error(NoMethodError)
115
- end
116
-
117
- it "ignores non_method + ?" do
118
- invalid_method = "humid"
119
- @night.respond_to?(invalid_method).should be_false
120
- lambda { @night.send(invalid_method + "?") }.should raise_error(NoMethodError)
121
- end
122
-
123
- it "returns true if set" do
124
- @night.pop = 10
125
- @night.pop.should_not be_nil
126
- @night.pop?.should be_true
127
- end
128
-
129
- it "returns false if not set" do
130
- @night.pop.should be_nil
131
- @night.pop?.should be_false
132
- end
133
-
134
- end
135
-
136
- end